|
Prev: grabbing frame char events
Next: Detailed Guide to set up MSYS, MinGW, Eclipse CDT and wxWidgets onWindows
From: Harvey Chapman on 7 May 2008 10:15 Hello, I'm trying to create a header of sorts at the top of a window using a horizontal box sizer. I want something like this: Left Label <expandable space> Center Label <expandable space> Right Label I can create that, but when a user resizes the window small enough the labels all start to overlap each other than just disappear off-screen as I would desire (and would happen if I used fixed sizes for the spaces with no proportionality). So: How can I have both proportionality and minimum sizes? Do I have to always set the minimum sizes myself? Below, I've included code (generated by wxDesigner) that illustrates the problem (parent is an empty wxFrame). Worth noting is the fact that the text control does n fact limit the minimum size of the window(frame). Thank you, Harvey wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL ); wxStaticText *item2 = new wxStaticText( parent, ID_TEXT, _("Some Longer Text Indeed"), wxDefaultPosition, wxSize(160,10), 0 ); item1->Add( item2, 0, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 5 ); item1->Add( 25, 20, 1, wxALIGN_CENTER|wxALL, 5 ); wxStaticText *item3 = new wxStaticText( parent, ID_TEXT, _("Some Longer Text Indeed"), wxDefaultPosition, wxDefaultSize, 0 ); item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 ); item1->Add( 20, 20, 1, wxALIGN_CENTER|wxALL, 5 ); wxStaticText *item4 = new wxStaticText( parent, ID_TEXT, _("Some Longer Text Indeed"), wxDefaultPosition, wxDefaultSize, 0 ); item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 ); item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxTextCtrl *item5 = new wxTextCtrl( parent, ID_TEXTCTRL, wxT(""), wxDefaultPosition, wxSize(400,200), wxTE_MULTILINE ); item0->Add( item5, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); if (set_sizer) { parent->SetSizer( item0 ); if (call_fit) item0->SetSizeHints( parent ); }
From: Vadim Zeitlin on 7 May 2008 10:59 On Wed, 7 May 2008 10:15:29 -0400 Harvey Chapman <hchapman-wx-users(a)3gfp.com> wrote: HC> How can I have both proportionality and minimum sizes? Do I have to HC> always set the minimum sizes myself? Usually I'd advise you to set the minimal size for the window containing this sizer. The sizer elements do set their minimal sizes automatically but if you resize the window containing them below their sum, they have no choice but to behave as you described. However if you really want the labels to be cut off when the window is too small (rather than preventing it from becoming so small), then you do indeed need to set the minimal size (say 5 or 10 pixels) for the spacers as they don't have any minimal size by default. Regards, VZ -- TT-Solutions: wxWidgets consultancy and technical support http://www.tt-solutions.com/
From: Harvey Chapman on 7 May 2008 12:31
On May 7, 2008, at 10:59 AM, Vadim Zeitlin wrote: > However if you really want the labels to be cut off when the window > is too > small (rather than preventing it from becoming so small), then you do > indeed need to set the minimal size (say 5 or 10 pixels) for the > spacers as > they don't have any minimal size by default. Thanks for the hint on setting a minimum size on the entire window. I used the code below to do that. I'm not sure if I can do it to the immediately parent sizer since I'm using XML. I'm not sure if I'd want to either since it kind of defeats the purpose of the XML. I tried: win->SetMinSize(win->GetEffectiveMinSize()); on all three labels right at startup, but after the frame had been shown. It had not effect. I don't know how to do the same to the spaces. The problem lies with the proportional flag. Is it possible to get wxWidgets to respect a minimum size if a proportional flag is set? Thanks for the help, R. |