Do not limit label width in wxToolBar by control width

This removes irregular behaviour in setting the label of a control. Creating
a control with label now behaves the same as setting or changing the label
later on. And behaves the same as for other tools in the wxToolBar.

Closes https://github.com/wxWidgets/wxWidgets/pull/1289
This commit is contained in:
Maarten Bent
2019-04-10 23:26:43 +02:00
committed by Vadim Zeitlin
parent 20c7421a67
commit 94907d3893
2 changed files with 18 additions and 29 deletions

View File

@@ -333,10 +333,6 @@ public:
@param label
Text to be displayed near the control.
@remarks
wxMSW: the label is only displayed if there is enough space
available below the embedded control.
@remarks
wxMac: labels are only displayed if wxWidgets is built with @c
wxMAC_USE_NATIVE_TOOLBAR set to 1

View File

@@ -194,39 +194,32 @@ public:
{
if ( m_staticText )
{
if ( !label.empty() )
{
if ( !label.empty() )
{
m_staticText->SetLabel(label);
}
else
{
}
else
{
delete m_staticText;
m_staticText = NULL;
}
}
}
else
{
if ( !label.empty() )
{
// Create a control to render the control's label.
// It has the same witdh as the control.
wxSize size(m_control->GetSize().GetWidth(), wxDefaultCoord);
m_staticText = new wxStaticText(m_tbar, wxID_ANY, label,
wxDefaultPosition, size,
wxALIGN_CENTRE | wxST_NO_AUTORESIZE);
}
if ( !label.empty() )
{
m_staticText = new wxStaticText(m_tbar, wxID_ANY, label);
}
}
}
else if ( IsButton() )
{
// Because new label can have different length than the old one
// so updating button's label with TB_SETBUTTONINFO would require
// also manual re-positionining items in the control tools located
// to the right in the toolbar and recalculation of stretchable
// spacers so it is easier just to recreate the toolbar with
// Realize(). Performance penalty should be negligible.
m_tbar->Realize();
}
// Because new label can have different length than the old one
// so updating button's label with TB_SETBUTTONINFO would require
// also manual re-positionining items in the control tools located
// to the right in the toolbar and recalculation of stretchable
// spacers so it is easier just to recreate the toolbar with
// Realize(). Performance penalty should be negligible.
m_tbar->Realize();
}
wxStaticText* GetStaticText()