Can't get gridbag sizer cell to expand

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
DaveNadler
Knows some wx things
Knows some wx things
Posts: 43
Joined: Thu Nov 17, 2011 2:13 pm

Can't get gridbag sizer cell to expand

Post by DaveNadler » Sat May 16, 2020 3:17 pm

OK, I've done something silly, but what?
I'm using a gridbag sizer, right column is supposed to be entirely filled with a list.
But the window does not grow.
What have I done wrong?
Video here: http://www.nadler.com/backups/GridBagSi ... blems1.mp4
Code below.
Thanks in advance for any pointers!
Best Regards, Dave

PS: Latest downloaded Windows wxWidgets on Windows 10.

Code: Select all

    // To force simulation log to take all available space, it is placed in
    // an EXPAND sizer. The sizer is added to the top-level gridbag sizer (not the control)
    wxBoxSizer* rBoxSizer = new wxBoxSizer(wxVERTICAL);
    rBoxSizer->Add(m_simLogWindow, 1, wxEXPAND, 0); // Add an expandable control

    // GridBag:
    // - column 0 is LCD then Simulation Controls
    // - column 1 is Simulation Log   
    wxGridBagSizer* gbSizer = new wxGridBagSizer(); // can grow in both dimensions
    // column 0
    gbSizer->Add(m_ButterflySimCanvas, wxGBPosition(0, 0), wxGBSpan(1, 1), wxALIGN_LEFT|wxALIGN_TOP, 5);
    gbSizer->Add(m_SimulationControlPanel, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALIGN_LEFT, 5);
    // column 1
    gbSizer->Add(rBoxSizer, wxGBPosition(0, 1), wxGBSpan(2,1), wxALIGN_NOT, 5);

    gbSizer->AddGrowableCol(0);
    gbSizer->AddGrowableCol(1);
    gbSizer->AddGrowableRow(0); // allows simulation log to fill all available space?
    gbSizer->Fit(this);

    this->SetSizer(gbSizer);
    this->Layout();

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

Re: Can't get gridbag sizer cell to expand

Post by doublemax » Sat May 16, 2020 3:44 pm

Code: Select all

gbSizer->Add(rBoxSizer, wxGBPosition(0, 1), wxGBSpan(2,1), wxALIGN_NOT, 5);
Use wxEXPAND instead of wxALIGN_NOT here.

For m_ButterflySimCanvas, wxEXPAND might be better, too, but that's up to you.
Use the source, Luke!

DaveNadler
Knows some wx things
Knows some wx things
Posts: 43
Joined: Thu Nov 17, 2011 2:13 pm

Re: Can't get gridbag sizer cell to expand

Post by DaveNadler » Sat May 16, 2020 4:36 pm

Much better, Thanks!
Two remaining problems:
1) I'm failing to limit the height of the "Simulation Control" panel
2) the caption bar is getting clobbered, sometimes...
Video here: http://www.nadler.com/backups/GridBagSi ... blems2.mp4
Revised code below.
Thanks Again!!
Best Regards, Dave

Code: Select all

    // Simulation Control Panel 
    m_SimulationControlPanel = new SimulationControlPanel(this);
    m_SimulationControlPanel->Fit(); // sets size to minimum required
    // Set max sim panel height to max height required
    wxSize simPanelSize = m_SimulationControlPanel->GetSize();
    simPanelSize.x = -1; // allow width to expand
    m_SimulationControlPanel->SetMaxSize(simPanelSize);
 
    // Log panel 
    m_simLogWindow = new SimLogCtrl(this, wxID_ANY,
        wxDefaultPosition, wxDefaultSize);

    UpdateUI();

    // ====================  component layout and sizers  ====================
    
    // GridBag:
    // - column 0 is LCD then Simulation Controls
    // - column 1 is Simulation Log   
    wxGridBagSizer* gbSizer = new wxGridBagSizer(); // can grow in both dimensions
    // column 0
    gbSizer->Add(m_ButterflySimCanvas, wxGBPosition(0, 0), wxGBSpan(1, 1), wxALIGN_LEFT|wxALIGN_TOP| wxEXPAND, 5);
    gbSizer->Add(m_SimulationControlPanel, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALIGN_LEFT, 5);
    // column 1
    gbSizer->Add(m_simLogWindow, wxGBPosition(0, 1), wxGBSpan(2,1), wxEXPAND, 5);

    gbSizer->AddGrowableCol(0);
    gbSizer->AddGrowableCol(1);
    gbSizer->AddGrowableRow(0); // allows simulation log to fill all available space?
    gbSizer->Fit(this);

    this->SetSizer(gbSizer);
    this->Layout();

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

Re: Can't get gridbag sizer cell to expand

Post by doublemax » Sat May 16, 2020 5:17 pm

The bottom row shouldn't grow at all with the current sizer code.

Code: Select all

    m_SimulationControlPanel = new SimulationControlPanel(this);
    m_SimulationControlPanel->Fit(); // sets size to minimum required
    // Set max sim panel height to max height required
    wxSize simPanelSize = m_SimulationControlPanel->GetSize();
    simPanelSize.x = -1; // allow width to expand
    m_SimulationControlPanel->SetMaxSize(simPanelSize);
Check the value you're getting here for the height. I suspect the height is too big. What happens if you comment out everything from Fit() to SetMaxSize(), the code really shouldn't be needed.

As for the statusbar problem, i don't think the problem is in the sizer code either. Try replacing m_simLogWindow with a colored panel for a test and check if the same problem occurs.
Use the source, Luke!

DaveNadler
Knows some wx things
Knows some wx things
Posts: 43
Joined: Thu Nov 17, 2011 2:13 pm

Re: Can't get gridbag sizer cell to expand

Post by DaveNadler » Sat May 16, 2020 5:55 pm

I commented out the code you suggested and got same behavior.
I'll go check now on the status-bar-clobbering...
Thanks for the help!

Post Reply