Can column of wxGridBagSizer expand? 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
Ronald
I live to help wx-kind
I live to help wx-kind
Posts: 162
Joined: Mon Mar 05, 2018 4:17 am

Can column of wxGridBagSizer expand?

Post by Ronald » Sat Apr 04, 2020 8:29 pm

In the sample code below, when the window resizes, can the 2nd column of wxGridBagSizer fit horizontally?

Code: Select all

wxBoxSizer * sizer_1 = new wxBoxSizer(wxVERTICAL);
{
    wxGridBagSizer * sizer_2 = new wxGridBagSizer(10, 10);
    {
        int row = 0;

        wxSize path_text_ctrl_size(500, 25);

        {
            sizer_2->Add(new wxStaticText(this, wxID_ANY, L"Input file paths"),
                            wxGBPosition(row, 0),
                            wxDefaultSpan,
                            wxALIGN_TOP);
            _lv_input_file_paths = new FilePathListView(this);
            sizer_2->Add(_lv_input_file_paths,
                            wxGBPosition(row, 1),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL | wxEXPAND);
            sizer_2->Add(new wxButton(this, ID_BTN_SELECT_INPUT_FILES, L"...", wxDefaultPosition, wxSize(30, 25)),
                            wxGBPosition(row, 2),
                            wxDefaultSpan,
                            wxALIGN_TOP);
        }
        {
            ++row;
            sizer_2->Add(new wxStaticText(this, wxID_ANY, L"Input root path"),
                            wxGBPosition(row, 0),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL);
            _text_ctrl_input_root_path = new wxTextCtrl(this,
                                                        wxID_ANY,
                                                        wxEmptyString,
                                                        wxDefaultPosition,
                                                        path_text_ctrl_size);
            sizer_2->Add(_text_ctrl_input_root_path,
                            wxGBPosition(row, 1),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL | wxEXPAND);
            sizer_2->Add(new wxButton(this, ID_BTN_INPUT_ROOT, L"...", wxDefaultPosition, wxSize(30, 25)),
                            wxGBPosition(row, 2),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL);
        }
        {
            ++row;
            sizer_2->Add(new wxStaticText(this, wxID_ANY, L"Output folder path"),
                            wxGBPosition(row, 0),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL);
            _text_ctrl_output_folder_path = new wxTextCtrl(this,
                                                            wxID_ANY,
                                                            wxEmptyString,
                                                            wxDefaultPosition,
                                                            path_text_ctrl_size);
            sizer_2->Add(_text_ctrl_output_folder_path,
                            wxGBPosition(row, 1),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL | wxEXPAND);
            sizer_2->Add(new wxButton(this, ID_BTN_SET_OUTPUT_FOLDER_PATH, L"...", wxDefaultPosition, wxSize(30, 25)),
                            wxGBPosition(row, 2),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL);
        }
        {
            ++row;
            sizer_2->Add(new wxStaticText(this, wxID_ANY, L"Include folder path (optional)"),
                            wxGBPosition(row, 0),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL);
            _text_ctrl_optional_include_folder_path = new wxTextCtrl(this,
                                                                        wxID_ANY,
                                                                        wxEmptyString,
                                                                        wxDefaultPosition,
                                                                        path_text_ctrl_size);
            sizer_2->Add(_text_ctrl_optional_include_folder_path,
                            wxGBPosition(row, 1),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL | wxEXPAND);
            sizer_2->Add(new wxButton(this, ID_BTN_SET_PROTOBUF_INCLUDE_FOLDER_PATH, L"...", wxDefaultPosition, wxSize(30, 25)),
                            wxGBPosition(row, 2),
                            wxDefaultSpan,
                            wxALIGN_CENTER_VERTICAL);
        }
        {
            ++row;
            wxBoxSizer * sizer_3 = new wxBoxSizer(wxHORIZONTAL);
            {
                sizer_3->Add(new wxButton(this, ID_BTN_COMPILE, L"Compile", wxDefaultPosition, wxSize(80, 25)));
            }
            sizer_2->Add(sizer_3,
                            wxGBPosition(row, 1),
                            wxGBSpan(1, 2),
                            wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT);
        }
    }
    sizer_1->Add(sizer_2, 1, wxEXPAND | wxALL, 20);
}
SetSizer(sizer_1);

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

Re: Can column of wxGridBagSizer expand?

Post by doublemax » Sat Apr 04, 2020 11:33 pm

wxGridBagSizer derives from wxFlexGridSizer, so you can use wxFlexGridSizer::AddGrowableCol
https://docs.wxwidgets.org/trunk/classw ... bcd5585b6e
Use the source, Luke!

Ronald
I live to help wx-kind
I live to help wx-kind
Posts: 162
Joined: Mon Mar 05, 2018 4:17 am

Re: Can column of wxGridBagSizer expand?

Post by Ronald » Sun Apr 05, 2020 6:09 am

doublemax wrote:
Sat Apr 04, 2020 11:33 pm
wxGridBagSizer derives from wxFlexGridSizer, so you can use wxFlexGridSizer::AddGrowableCol
https://docs.wxwidgets.org/trunk/classw ... bcd5585b6e
Nice, it works, thanks.
BTW, it actually sets an existing column growable instead of adding a new growable column, right?

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

Re: Can column of wxGridBagSizer expand?

Post by doublemax » Sun Apr 05, 2020 11:17 am

Ronald wrote:
Sun Apr 05, 2020 6:09 am
BTW, it actually sets an existing column growable instead of adding a new growable column, right?
Yes. The naming is a little ambiguous.
Use the source, Luke!

Post Reply