Code: Select all
wxBoxSizer * pSizer_0_0 = new wxBoxSizer(wxHORIZONTAL);
pSizer_0_0->AddStretchSpacer();
pSizer_0_0->Add(new wxButton(this, wxID_OK, L"AAA"));
pSizer_0_0->Add(new wxButton(this, wxID_CANCEL, L"BBB"));
Code: Select all
wxBoxSizer * pSizer_0_0 = new wxBoxSizer(wxHORIZONTAL);
pSizer_0_0->AddStretchSpacer();
pSizer_0_0->Add(new wxButton(this, wxID_OK, L"AAA"));
pSizer_0_0->Add(new wxButton(this, wxID_CANCEL, L"BBB"));
Code: Select all
pSizer_0_0->Add(new wxButton(this, wxID_OK, L"AAA"), 0, wxALIGN_RIGHT);
pSizer_0_0->Add(new wxButton(this, wxID_CANCEL, L"BBB"),1, wxALIGN_RIGHT);
ASSERTS: "Horizontal alignment flags are ignored in horizontal sizers"Manolo wrote: ↑Mon Sep 16, 2019 12:52 pm Tell the sizer how to align the buttons using some flag of https://docs.wxwidgets.org/trunk/classw ... izer_flags
Notice the "0" I added to the first button means "don't change size of this button". The "1" in the second button, together with the default "1" in the AddStretchSpacer(), means "the remaining space will be evenly distributed (because of the 1/1 relation) between this second button and the spacer".Code: Select all
pSizer_0_0->Add(new wxButton(this, wxID_OK, L"AAA"), 0, wxALIGN_RIGHT); pSizer_0_0->Add(new wxButton(this, wxID_CANCEL, L"BBB"),1, wxALIGN_RIGHT);
I think the default proportions in wxBoxSizer::AddStretchSpacer and wxBoxSizer::Add in the case are OK.
Buttons should not expand their sizes, just right aligned in horizontal sizer.doublemax wrote: ↑Mon Sep 16, 2019 3:42 pm Using wxALIGN_RIGHT like Manolo wrote will not work in this case. This is only allowed in a vertical boxsizer and serves a (slightly) different purpose.
Your code looks ok, the problem is mostly how you insert pSizer_0_0 into another sizer. E.g. if you put it into a vertical sizer, set the wxEXPAND flag so that it takes the whole width. And if you put it into a horizontal sizer, use a "proportion" value > 0 so that it can take extra space.
If you can't get it to work, please show the whole sizer related code.
Code: Select all
void MyDlg::Init()
{
wxBoxSizer * pSizer_0 = new wxBoxSizer(wxVERTICAL);
// add some children to pSizer_0
{
wxBoxSizer * pSizer_0_0 = new wxBoxSizer(wxHORIZONTAL);
pSizer_0_0->AddStretchSpacer();
pSizer_0_0->Add(new wxButton(this, wxID_OK, L"OK"));
pSizer_0_0->Add(new wxButton(this, wxID_CANCEL, L"Cancel"));
pSizer_0->Add(pSizer_0_0);
}
SetSizer(pSizer_0);
Fit();
}
Your code looks ok, the problem is mostly how you insert pSizer_0_0 into another sizer. E.g. if you put it into a vertical sizer, set the wxEXPAND flag so that it takes the whole width.
Code: Select all
pSizer_0->Add(pSizer_0_0, 0, wxEXPAND);
Works, the design by wx is fine, I just haven't realized it.doublemax wrote: ↑Tue Sep 17, 2019 5:05 amYour code looks ok, the problem is mostly how you insert pSizer_0_0 into another sizer. E.g. if you put it into a vertical sizer, set the wxEXPAND flag so that it takes the whole width.Code: Select all
pSizer_0->Add(pSizer_0_0, 0, wxEXPAND);