I'm basically adding panels to a wxNotebook, and each panel uses a wxGridBagSizer to layout its elements - which are mostly static boxes. Being a notebook, all panels will be resized to be as wide as the widest of them all, while their content doesn't necessarily occupy the entire width. So I would like the content of narrower panels to be spread out evenly (horizontally) in the panel.
Here's what I'm getting now (forgive the red, that's to show that the panel does indeed get resized):
But here's what I'd like to get instead (more or less, this has been hacked in Paint):
In other words, I'd like the grid bag sizer to expand (horizontally) to occupy the entire space - together with its cells - and each of its cells to center its content horizontally.
This is the current code that I'm using to populate that panel above:
Code: Select all
void SettingsDialog::PopulateTODOTEST(wxPanel * panel)
{
wxGridBagSizer * gridSizer = new wxGridBagSizer(0, 0);
{
wxStaticBoxSizer * mechanicsBoxSizer = new wxStaticBoxSizer(wxVERTICAL, panel, _("Mechanics1"));
{
wxButton * todo = new wxButton(mechanicsBoxSizer->GetStaticBox(), wxID_ANY, "FOO1");
mechanicsBoxSizer->Add(todo, 0, wxALL, StaticBoxInsetMargin);
}
gridSizer->Add(
mechanicsBoxSizer,
wxGBPosition(0, 0),
wxGBSpan(1, 1),
wxALL,
CellBorderOuter);
}
{
wxStaticBoxSizer * mechanicsBoxSizer = new wxStaticBoxSizer(wxVERTICAL, panel, _("Mechanics2"));
{
wxButton * todo = new wxButton(mechanicsBoxSizer->GetStaticBox(), wxID_ANY, "FOO2");
mechanicsBoxSizer->Add(todo, 0, wxALL, StaticBoxInsetMargin);
}
gridSizer->Add(
mechanicsBoxSizer,
wxGBPosition(0, 1),
wxGBSpan(1, 1),
wxALL,
CellBorderOuter);
}
{
wxStaticBoxSizer * mechanicsBoxSizer = new wxStaticBoxSizer(wxHORIZONTAL, panel, _("Mechanics3"));
{
wxButton * todo = new wxButton(mechanicsBoxSizer->GetStaticBox(), wxID_ANY, "FOO3a");
mechanicsBoxSizer->Add(todo, 0, wxALL, StaticBoxInsetMargin);
}
{
wxButton * todo = new wxButton(mechanicsBoxSizer->GetStaticBox(), wxID_ANY, "FOO3b");
mechanicsBoxSizer->Add(todo, 0, wxALL, StaticBoxInsetMargin);
}
gridSizer->Add(
mechanicsBoxSizer,
wxGBPosition(1, 0),
wxGBSpan(1, 2),
wxALL,
CellBorderOuter);
}
// Finalize panel
panel->SetBackgroundColour(*wxRED);
panel->SetSizer(gridSizer);
}