Page 1 of 1

Center objects within a vertical box sizer

Posted: Wed May 20, 2020 12:57 pm
by dohpam1ne
Say I have a large square panel, and I've assigned a vertical box sizer to it. The sizer has two children- a text field and a button. The children are much smaller than the panel, and although I'm able to center the children horizontally, wxWidgets complains if I try to center them vertically. Here's what I'm talking about:

Image

How do I get the child fields to align to the center of the blue panel?

Here's my current relevant code:

Code: Select all

	configSizer = new wxBoxSizer(wxVERTICAL);
	configSizer->Add(
		renderButton,
		wxSizerFlags().CenterHorizontal().Border(wxRIGHT | wxLEFT, 40));
	configSizer->Add(
		infoBox,
		wxSizerFlags().CenterHorizontal().Border(wxRIGHT | wxLEFT, 40));

	SetSizer(configSizer);

Re: Center objects within a vertical box sizer

Posted: Wed May 20, 2020 1:02 pm
by doublemax
Add a stretch spacer before and after the controls.
https://docs.wxwidgets.org/trunk/classw ... 747af5c976

Re: Center objects within a vertical box sizer

Posted: Wed May 20, 2020 3:36 pm
by dohpam1ne
Ah, somehow I missed that. Thanks!