Michael Hipp wrote:
More sizer fun, trying to understand "the why".
I've a horrid panel with 40-something controls on it. It's packed
tight.So I have a StaticText control, that I stuff a new (longish) value
into. If I call panel.Layout() a bunch of things spill off the right
of the screen, but yet there's obviously plenty of room for things to
resize without that. If I call sizer.Layout() everything looks great.I thought panel.Layout() was supposed to call Layout() on all it's
children and it's official sizer and everything would propagate down
to all the controls and sizers. Is this not true?
panel.Layout checks if the panel has a sizer and if so it calls the sizer's SetDimension method passing it the current size of the panel. The SetDimension method stores the size and position given to it and then calls the sizer's Layout method which calculates the minimum needed by the items in the sizer and then does the layout of those items within the space given to the sizer.
Is calling Layout() on the sizers and not the panel the "correct"
answer? Or always call it on both?
Most of the time they should be equivalent, but not always. For example, if there is some sub-panels between the top level panel and the item that changed size, and if the sub-panel's sizer is such that changing that item will not change the overall size needs of the sub-panel, then calling Layout on the top level panel will not actually cause a layout of the sub-panel. This is because when the top level sizer asks the sub-panel what its minimum size is, and it reports the same size as it already has, then its SetSize will not be called, and so it gets no EVT_SIZE event that would call its Layout method. I expect that a similar situation is possible with just sub-sizers. In either case calling Layout on the panel or sizer that directly controls the item that changed will usually take care of the problem.
I love my children. They're the best kids around. But sometimes
they're a pain. Same with sizers.
ยทยทยท
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!