If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
I want to align two buttons one at the left and the other to the right. I'm using horizontal sizer to align buttons left and right with StretchSpacer which works properly on expansion but overlaps on shrinking.
The overlapping happens because there is not enough room for the controls. The only way to avoid this is to set a proper minimum size for the outer window.
wxSizer::SetSizeHints() does that. Alternatively you can call wxWindow::SetSizerAndFit instead of wxWindow::SetSizer to set the sizer.
doublemax wrote:There is no way to control what a sizer does when there is not enough room to show all controls.
Shrinking frame doesn't have to shrink the controls as shown in the above image <shrink without overlap>. it can cut the view which is the behaviour if we don't set min size.
Update: Sorry for being not clear. What I meant is, without StretchSpacer(in the code I've posted above) buttons wont move on expand but at the same time wont overlap on shrinking the frame but view will be cut which I believe is the default behaviour.
Last edited by rajan_m on Tue Feb 09, 2016 2:23 pm, edited 1 time in total.
What is supposed to happen when a window is resized smaller than a minimum value is a design decision,
Personally I don't like to hide any control, nor behind another control neither outside the window. So I agree with using SetMinSize().
Anyhow, you can handle size-event and if it comes to a special size, change sizers: detach, re-attach controls with other flags.
Manolo wrote:What is supposed to happen when a window is resized smaller than a minimum value is a design decision
I believe the default behaviour(not my opinion) is, when we shrink the frame with controls beyond the min size it'll cut the view. In my case when frame expands it should align the controls to left and right and when we shrink the frame beyond min size it can cut the view.
Sizers in your example are working as you decided: the left button is letf-aligned with the window and the right botton with the right border of the window (spacers apart). It happens that the only way of fulfilling those settings is overlapping buttons.