Center objects within a vertical box sizer

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dohpam1ne
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu May 14, 2020 11:27 pm

Center objects within a vertical box sizer

Post by dohpam1ne » Wed May 20, 2020 12:57 pm

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);

User avatar
doublemax
Moderator
Moderator
Posts: 14786
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Center objects within a vertical box sizer

Post by doublemax » Wed May 20, 2020 1:02 pm

Add a stretch spacer before and after the controls.
https://docs.wxwidgets.org/trunk/classw ... 747af5c976
Use the source, Luke!

dohpam1ne
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu May 14, 2020 11:27 pm

Re: Center objects within a vertical box sizer

Post by dohpam1ne » Wed May 20, 2020 3:36 pm

Ah, somehow I missed that. Thanks!

Post Reply