How to resize parent on wxCollapsiblePane expansion Topic is solved

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
mmead
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Jun 08, 2021 7:30 pm

How to resize parent on wxCollapsiblePane expansion

Post by mmead »

Hi,

I am new to using wxWidgets. I am having some difficulty wrapping my head around how to properly handle wxCollapsiblePane expand/collapse events.

The main issue I am having is that, after collapsing the pane, the pane remains the same size as it did when it was fully expanded.

Expanded
Screenshot from 2021-06-08 13-19-29.png
Screenshot from 2021-06-08 13-19-29.png (6.21 KiB) Viewed 2233 times
Collapsed
Screenshot from 2021-06-08 13-22-21.png
Screenshot from 2021-06-08 13-22-21.png (4.05 KiB) Viewed 2233 times
I've pasted my code below. I am laying out the pane children in a wxFlexGridSizer and binding a custom event handler to wxEVT_COLLAPSIBLEPANE_CHANGED.

Code: Select all

	auto pane = this->GetPane();
	auto pane_sizer = new wxFlexGridSizer(2, 5, 5);

	pane_sizer->AddSpacer(3);
	pane_sizer->AddSpacer(3);

	m_row_0 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, wxT("Row 0:")), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_0, 1, wxALIGN_LEFT, 2);

	m_row_1 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, wxT("Row 1:")), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_1, 1, wxALIGN_LEFT, 2);

	m_row_2 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, wxT("Row 2:")), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_2, 1, wxALIGN_LEFT, 2);

	m_row_3 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, "Row 3:"), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_3, 1, wxALIGN_LEFT, 2);

	m_row_4 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, wxT("Row 4:")), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_4, 1, wxALIGN_LEFT, 2);

	pane_sizer->AddSpacer(3);
	pane_sizer->AddSpacer(3);

	pane->SetSizer(pane_sizer);
	pane_sizer->SetSizeHints(this);
	
	this->Bind(wxEVT_COLLAPSIBLEPANE_CHANGED, [=](wxCollapsiblePaneEvent&) {
		this->Fit();
	});
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to resize parent on wxCollapsiblePane expansion

Post by doublemax »

As the code does not compile and is out of context: Did you check the "collpane" sample that comes with wxWidgets?
Use the source, Luke!
mmead
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Jun 08, 2021 7:30 pm

Re: How to resize parent on wxCollapsiblePane expansion

Post by mmead »

Hi,

My apologies about the incomplete code. :)

Yes, I checked the collpane sample. There were a couple issues with my code:

1) I was calling SetSizeHints on the underlying wxCollapsiblePane pane, which was causing the pane to be initially sized to the total size of its contents even when the pane was collapsed.
2) I was not handling the wxEVT_COLLAPSIBLEPANE_CHANGED events properly. I needed to Bind to this event in the parent and re-layout the parent and all its wxCollapsiblePane children when a pane expands/collapses.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to resize parent on wxCollapsiblePane expansion

Post by doublemax »

So this is solved now?
Use the source, Luke!
Post Reply