Let wxAuiToolBars with stretchable elements stretch

Previously, all fixed panes without a minimum size were forced to have a
proportion of 0 in wxAUI layout code, which meant that a wxAuiToolBar
with stretchable elements (typically spaces, but labels and controls
could be stretchable too) couldn't stretch unless its pane was given
some non-default minimum size, even if it was just wxSize(-1,1).

This was completely undiscoverable and not intuitive at all, so let
wxAuiToolBar stretch if it has any stretchable elements, regardless of
its pane min size instead.

This required adding wxAuiToolBar::CanStretch() and using an ugly
dynamic cast. We could probably avoid this by using some kind of
heuristic based on e.g. comparing min and best size, but this is simple
and guaranteed not to break anything else, so do it like this for now.

See #26252.

Closes #26249.
This commit is contained in:
Vadim Zeitlin
2026-02-28 13:24:07 +01:00
parent 475182cd9c
commit 97050e18e2
3 changed files with 21 additions and 1 deletions
+3
View File
@@ -636,6 +636,9 @@ public:
// Override to call DoIdleUpdate().
virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE) override;
// This function is for internal use only, don't call it from your code.
bool CanStretch() const;
protected:
void Init();
+11
View File
@@ -2207,6 +2207,17 @@ bool wxAuiToolBar::RealizeHelper(wxClientDC& dc, bool horizontal)
return true;
}
bool wxAuiToolBar::CanStretch() const
{
for (auto const& item : m_items)
{
if (item.m_proportion)
return true;
}
return false;
}
int wxAuiToolBar::GetOverflowState() const
{
return m_overflowState;
+7 -1
View File
@@ -2447,7 +2447,13 @@ void wxAuiManager::LayoutAddPane(wxSizer* cont,
if (min_size == wxDefaultSize)
{
min_size = pane.best_size;
pane_proportion = 0;
// Toolbars may be fixed, i.e. non-resizable, but still need to
// stretch if they contain stretchable spacers, so we should avoid
// setting their proportion to 0 in this case.
auto* const toolbar = wxDynamicCast(pane.window, wxAuiToolBar);
if (!toolbar || !toolbar->CanStretch())
pane_proportion = 0;
}
}