Reputation: 920
I have a static text control that changes it contents based on user actions. It is in a horizontal sizer with several other control. When the text changes, the control dynamically updates its size, but it doesn't dynamically adjust it's position in the sizer, ie, it overlaps a sibling control until I resize the main window manually, after which it all looks good again.
How do I cause the sizer to automatically re-adjust so everythings fits?
Upvotes: 2
Views: 344
Reputation: 22688
The simplest way is to call Layout()
on the top level window parent returned by wxGetTopLevelParent()
. This is not the most efficient way as it can result in re-laying out too much and you can always restrict the layout to just the deepest sizer or window containing the window that changed size whose size needs to update, but, again, doing it at TLW level is the simplest way.
Upvotes: 2
Reputation: 920
OK, Stackoverflow pointed me at some other questions that contained my answer. I need to call Layout() on the sizer. But it wasn't quite that simple. I was using an xrc file for the GUI, and didn't know how to get a handle for the sizer. Until I learned I could call GetContainingSizer() on the control.
But it wasn't quite that simple.
Being new to wxWidgets, and trying many different ways to fix this problem, I had the static text control in its own sizer, and its neighboring buttons in a sizer, and all these sizers in a horizontal box sizer.
Getting rid of these extra sizers and having the controls all siblings of one horiz. box sizer worked...almost! But it wasn't quite that simple.
The sibling controls were flowing ok, but the containing sizer wasn't remaining centered in its area, ie, the controls were off center to the right. So I had to go up to the next containing sizer. But I couldn't call GetContainingSizer() on the sizer I did have, so I had to get the control that was a sibling of the sizer, and call GetContainingSizer() on that. And as long as I did a layout on that sizer, it all worked! Quite simple, really.
Upvotes: 1