How does a Grid know when to re-layout? - xaml

I want to subclass Grid to use the yogalayout library to calculate its children's positions and locations. I'm following instructions to create a custom panel. I see that when a child changes size, Grid knows to do a layout, but my control does not (ie, neither MeasureOverride nor ArrangeOverride() is called).
How can I know when a child (or, worse, a child of a child) size changes?
I have created a sample project https://github.com/arolson101/PanelTest that reproduces the issue I'm talking about.
(Note: I'm changing the question which previously mentioned StackPanel to instead mention Grid; I'm not convinced that it's unique to the Grid, but that was the way I was able to make a simple repro case.)

I see that when a child changes size, StackPanel knows to do a layout, but my control does not (ie, neither MeasureOverride nor ArrangeOverride() is called).
If you have not specific width and height property for the children element, when you get it's property, it will return NaN, And you could not set value with Width = newWidth, it can't also invoke the size change event, please call SetValue method to change the element size like the following. Then it will make MeasureOverride invoked.
MyTextBlock.SetValue(WidthProperty, 15);

Related

Vuetify – Expand v-navigation-drawer on click like it works on hover

The v-navigation-drawer has a very nice expand-on-hover functionality; here the expanded layer is displayed atop of the content; i.e. the content is not resized. Now I would like to have the same behaviour on click; but if I just manipulate the mini-variant property then the content gets resized (the layer moves the start of the content).
Now I found out – by complete accident – that I (kind of) get the behaviour I want by setting the width property (of v-navigation-drawer) not to a number (like 224 or "224") but to a string containing the number plus a unit (like "224px").
To me this actually seems to be a bug. Is it? If so: is there a proper way to achieve the same result?

wxWidget: How do change the size of the parent Sizer according to the size of the children sizers?

this is a question about wxBoxSizer. I am implementing a custom wxWidget like collapsible pane.
The problem is: I have a wxBoxSizer (Sizer1), and I add another wxBoxSizer (Sizer2) as its child. If I change the size of Sizer2, How do I make Sizer1 update it's size, automatically or manually?
I have tried to call Fit() and Layout() on Sizer1 after I call SetSize() on Sizer2, but it doesn't change the size for Sizer1.
Please help, thank you!
Layout in wxWidgets always works from top to bottom and changing the size of a sub-window or sub-sizer will never change the size of the containing window on its own. If you do want this to happen, call Fit() on the parent window to tell it that should become as big as required by its children. Notice that calling it on the panel will still not be enough, you need to do it on the top level wxFrame or wxDialog itself, unless you have some free space in it which can be used to accommodate the increasing panel size.
wxBoxSizer1 already occupies the whole panel. So unless you change the size of the panel itself, the wxBoxSizer1 wont be resized. You might want to try another size as your main sizer such as wxFlexGridSizer. Here you have more choices for precise control.

IOS 7 Approach for create container with two elements?

So, i am new to xcode and iOS7 and i'm trying to create simple container with two elements inside.
I prefer to make it 100% programmatically. (no IB)
I want to create container with two elements Image and Label.
I want to achieve variable width depends on the text element inside.
Here is example:
Based on user action i want to change text on the fly. Let's assume longer text, and main container have to change width too.
And now the question is: What is best approach to to that?
UIView with subviews or something else i'm just expecting direction.
Code examples with be gratefully appreciated.
Thank you in advance.
What you have described is exactly what a UIButton does automatically: it is a container containing an image and a title (text) and it resizes itself automatically when the text changes.
Let us assume, however, that you want to do this yourself. That is, let's say you want a UIView ("container") containing two other UIViews (subviews). Then we need to discuss this requirement:
Based on user action i want to change text on the fly. Let's assume longer text, and main container have to change width too.
This is not going to happen automatically. You can use constraints (auto layout) to describe the size / position of the subviews in relation to the superview, but it works the other way: the superview changes, and the subviews obey. So you will have to change the superview size manually after you change the text.
You can still use auto layout to help you. Let's say the text is in a UILabel. Well, a UILabel wants to change width automatically when the text changes. So far so good. But you must still change the container view width yourself. You can call systemLayoutSizeFittingSize: to learn what the size of the container should be, using constraints, working from the inside out; but then you will have to change its size yourself to that size.
(You can easily create the view, the subviews, and the auto layout constraints in code.)
If you don't want to use autolayout, then you will just calculate the sizes and positions of everything when the text changes and adjust it all yourself (in code). You can learn the size the label needs to be, to fit its text, by calling sizeThatFits: (or sizeToFit which will actually resize it correctly).

How do you replace HBox/VBox with Box/Grid

The documentation for HBox and VBox includes the statement:
Deprecated: Use Box instead, which is a very quick and easy change.
But we recommend switching to Grid, since Box will go away eventually.
However, it isn't obvious what the "quick and easy change" should be.
How do you use Box and/or Grid to achieve the functionality of VBox or HBox?
One of the big changes in gtkmm3:
Gtk::Box, Gtk::ButtonBox, Gtk::IconView, Gtk::Paned, Gtk::ProgressBar,
Gtk::ScaleButton, Gtk::ScrollBar and Gtk::Separator now derive from
Gtk::Orientable, allowing their orientation (vertical or horizontal)
to be specified without requiring the use of a derived class such as
Gtk::HBox.
Although Grid isn't mentioned above, both containers now have a method set_orientation; Box can also take it in the constructor. So for Box, set the orientation and use your usual pack_start, pack_end.
With Grid, if you scrutinize the documentation, you'll see this line:
Grid can be used like a Box by just using Gtk::Container::add(), which
will place children next to each other in the direction determined by
the orientation property.
So, it should be as simple as setting the orientation and then add your child widgets.

Draw Lines on gtk.TextView

I'm trying to show the "selection" of a certain sub-string in a
gtk.TextView by drawing a border around the word. The only way to mark
text in a TextView that I've found so far is by placing TextTags with
modified properties. This does not seem to offer a way to draw a border,
though, DOES GTK SUPPORT THIS OR IS THIS A PROBLEM WITH ONLT PYGTK
I figured out how to draw on a text view !!!
To begin with lets assume the reference to your gtk.TextView is in a variable called viewer, Inside one of ur classes
Also the draw function has to be called with an event called expose-event else the drawings will be refreshed and will not stay on the screen
The next part is the gtk.TextView consists of 7 types of gtk.gdk.windows on which u can draw
gtk.TEXT_WINDOW_WIDGET
gtk.TEXT_WINDOW_TEXT
gtk.TEXT_WINDOW_LEFT - not displayed by default
gtk.TEXT_WINDOW_RIGHT - not displayed by default
gtk.TEXT_WINDOW_TOP - not displayed by default
gtk.TEXT_WINDOW_BOTTOM
gtk.TEXT_WINDOW_PRIVATE
For the drawing to appear on gtk.TextView We have to draw on gtk.TEXT_WINDOW_TEXT
An Example Code is as shown Below
if(viewer!=None):
viewer.connect("expose-event", expose_view)
self.drawable=viewer.get_window(gtk.TEXT_WINDOW_TEXT)
def expose_view(self,window,event):
if(self.drawable!=None):
self.drawable.draw_line(self.drawable.new_gc(),1,1,30,30)
# (1,1) and (30,30) are the coordinates and u can give the values accordingly
In a gtk.TextBuffer tags are used to set one or more pre-defined text attributes. Without subclassing, this is limited to the properties of a gtk.TextTag, and doesn't include anything akin to a border or outline property. There is no difference between PyGTK and plain GTK+ in this regard.
While somewhat hacky, the easiest way to do what you want to do is to connect to the expose-event of your gtk.TextView, get the coordinates of your string and draw on event.window, which is the gdk.Window of the event provided in the expose callback.
(Note that you don't have to get and store the gtk.TEXT_WINDOW_TEXT window, you just need to check what window the expose event is for in the callback, probably ignoring the expose if it's not for the text window.)
Instead, you could presumably subclass one or more of TextBuffer/TextView/TextTag to add a border tag, but whether it's reasonable to do so is another question.