Opened 5 years ago

Closed 2 years ago

Last modified 2 years ago

#11497 closed defect (fixed)

SetMaxSize not limiting the size of controls in sizer

Reported by: Boksha Owned by:
Priority: normal Milestone:
Component: GUI-all Version: 2.9.0
Keywords: wxSizer wxBoxSizer wxButton regression Cc: joshtp
Blocked By: Blocking: #14498
Patch: no

Description

It appears the SetMaxSize function might have been broken in 2.9.0. If the function is called for a control in a sizer, the sizer will still resize the control above the set size, regardless of whether it's the only control in the sizer and regardless of whether the sizer is applied to a top level window or a child like wxPanel.

Included should be a patch to samples/minimal that shows the problem (apply from within folder with -p1). If compiled with any 2.8 version (checked for wxGTK and wxMac), the button stops becoming larger when the window is resized to above the max size, which is what I'd expect to happen. If compiled with 2.9.0 (checked for wxGTK and wxMSW), the button will always take up the entire window.

Attachments (5)

maxsizeprob.patch download (1.1 KB) - added by Boksha 5 years ago.
boxsizer_max_size_fix_trac11497.patch download (3.8 KB) - added by joshtp 5 years ago.
fix for sizer.cpp
maxsize-getbestsize.patch download (1.4 KB) - added by HighCommander4 2 years ago.
Patch to get wxWindowBase::GetBestSize to respect the window's max size
maxsize-boxsizer.patch download (5.7 KB) - added by HighCommander4 2 years ago.
Patch to get wxBoxSizer::RecalcSizes() to respect the max size of a window
maxsize-tests.patch download (3.1 KB) - added by HighCommander4 2 years ago.
Tests for the previous two patches

Download all attachments as: .zip

Change History (14)

Changed 5 years ago by Boksha

comment:1 Changed 5 years ago by vadz

  • Keywords regression added
  • Milestone set to 2.9.1

To be honest I had no idea that anybody used SetMaxSize() like this but if you did and it stopped working we should restore this functionality...

comment:2 Changed 5 years ago by joshtp

  • Cc joshtp added
  • Patch set

I have been having trouble with this myself so I set about fixing it, though it is my first foray into editing wxWidgets code so please bear with me and let me know if I do anything wrong.

I've modified wxBoxSizer::RecalcSizes() so that after distributing available space to satisfy the minimum sizes of child items, it then distributes the remaining space based on the items' proportion. I first place all shown items with proportion>0 into a wxSizerItemList, named stretchableChildren. Looping through the list and distributing extra space (delta), if one of the items reaches it's max size I remove that item from stretchableChildren and iterate through the list again.

In the worst case scenario the inner loop will be called (N/2)*(N+1), where N is the total number of visible, stretchable children. I've tried this with 50 wxSizeReportCtrl each with a different max size, such that this worst case occurs, and don't notice any performance difference from the current implementation.

Changed 5 years ago by joshtp

fix for sizer.cpp

comment:3 Changed 5 years ago by vadz

  • Milestone 2.9.1 deleted
  • Patch unset

Unfortunately the patch doesn't apply to the latest version in svn which was changed a lot (to fix many bugs, although not this one). Could you please try to merge your changes with the svn version and produce an updated patch?

Sorry for not looking at this one before changing svn code but it shouldn't happen again (i.e. this code is unlikely to change much in the near future).

comment:4 Changed 2 years ago by vadz

  • Blocking 14498 added

(In #14498) I think the best way to solve this inconsistency would indeed be to set the max vertical size for these controls by default. Unfortunately, currently this wouldn't work because of #11497. But once it's fixed, this should be simple enough to do.

comment:5 Changed 2 years ago by HighCommander4

Changed 2 years ago by HighCommander4

Patch to get wxWindowBase::GetBestSize to respect the window's max size

Changed 2 years ago by HighCommander4

Patch to get wxBoxSizer::RecalcSizes() to respect the max size of a window

Changed 2 years ago by HighCommander4

Tests for the previous two patches

comment:6 Changed 2 years ago by VZ

(In [72343]) Honour window min and max sizes in wxWindow::GetBestSize().

The best size of the window should be at least as large as its min size and
less than its max size. This allows to override the windows own best size
determination with an explicit SetMinSize() or SetMaxSize() call.

See #11497.

comment:7 Changed 2 years ago by VZ

(In [72344]) No real changes, just add wxSizerItem::AddBorderToSize() helper.

Factor out this function from GetMinSizeWithBorder() as it will be used for
max size too in a next commit.

See #11497.

comment:8 Changed 2 years ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [72345]) Respect item max sizes in wxBoxSizer.

Don't give more space than the max size, if set, to wxBoxSizer elements.

Closes #11497.

comment:9 Changed 2 years ago by VZ

(In [72586]) Fix handling of not fully specified min/max size in wxBoxSizer.

wxSizerItem::AddBorderToSize() added in r72344 (see #11497) didn't work
correctly as it replaced unspecified (i.e. set to -1) components of wxSize
with the small positive values that did take effect, contrary to the
intention.

Fix it to only adjust the actually set component(s) of wxSize.

Closes #14696.

Note: See TracTickets for help on using tickets.