Weird panel sizing in wxNotebook when using wxNB_MULTILINE style

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
Gabriele Giuseppini
Experienced Solver
Experienced Solver
Posts: 56
Joined: Fri Oct 12, 2018 6:12 pm
Location: Amsterdam, the Netherlands

Weird panel sizing in wxNotebook when using wxNB_MULTILINE style

Post by Gabriele Giuseppini »

Dear wx gurus,

I'm having an issue with multi-line notebooks in 3.1.4 on MSW.

When the notebook is created *without* the multi-line flag, it behaves as expected:
Image

However, when it's created *with* the multi-line flag, the sizing goes bananas, see how the parent panel becomes taller for no reason:
Image

Here's the code I'm using for this example:

Code: Select all

MyFrame::MyFrame(const wxString& title)
       : wxFrame(
           nullptr,
           wxID_ANY,
           title,
           wxDefaultPosition,
           wxDefaultSize,
           wxDEFAULT_FRAME_STYLE | wxMAXIMIZE,
           _T("Main Frame"))
{
    wxBoxSizer * dialogVSizer = new wxBoxSizer(wxVERTICAL);

    wxNotebook * notebook = new wxNotebook(
        this,
        wxID_ANY,
        wxDefaultPosition,
        wxDefaultSize,
        wxNB_TOP | wxNB_MULTILINE | wxNB_NOPAGETHEME);

    {
        wxPanel * panel = new wxPanel(notebook);

        wxBoxSizer * sizer = new wxBoxSizer(wxVERTICAL);

        sizer->AddSpacer(50);

        wxButton * button = new wxButton(panel, wxID_ANY, "Button 1 With Some Long Label");
        sizer->Add(button, 0, wxALL, 10);

        sizer->AddSpacer(20);

        panel->SetSizer(sizer);

        notebook->AddPage(panel, _("Page 1"));
    }

    {
        wxPanel * panel = new wxPanel(notebook);

        wxBoxSizer * sizer = new wxBoxSizer(wxVERTICAL);

        sizer->AddSpacer(50);

        wxButton * button = new wxButton(panel, wxID_ANY, "Button 2 With Some Longer Label");
        sizer->Add(button, 0, wxALL, 10);

        sizer->AddSpacer(20);

        panel->SetSizer(sizer);

        notebook->AddPage(panel, _("Page 2"));
    }

    dialogVSizer->Add(notebook, 0);

    SetSizerAndFit(dialogVSizer);

    Centre(wxCENTER_ON_SCREEN | wxBOTH);
}
Am I doing anything wrong?
Gabriele Giuseppini
Experienced Solver
Experienced Solver
Posts: 56
Joined: Fri Oct 12, 2018 6:12 pm
Location: Amsterdam, the Netherlands

Re: Weird panel sizing in wxNotebook when using wxNB_MULTILINE style

Post by Gabriele Giuseppini »

Edit: it appears that invoking `dialogVSizer->Fit(notebook);` after adding the notebook to the sizer, would solve the issue, suggesting that somehow the notebook is oversized when it's added to the sizer.

It this expected?
Post Reply