Wxwidgets C++ – Multiple sizers, multiple panels

Trying to implement a game menu with buttons. When button clicked it enters a submenu which is a new panel. It all works but the problems come with sizers. I have also sizers for every panel and at first when I boot up the program the main menus sizer works – when the window size is changed the maximum size is the sizes of buttons. Now when I go to a submenu, the sizers stop functioning and also when going back to main menu, it doesn’t work there either. What am I doing wrong?

I tried passing

this

into other panel SetSizeHints(), but it turned out it becomes NULL at some point. So I tried passing the panels themselves, but it doesn’t work aswell. My code:

#include "MainFrame.h"
#include "Stats.h"
#include <cstring>
#include <wx/wx.h>
#include "FileAlgo.h"
#include <string>

char sym;


MainFrame::MainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title), main_panel(nullptr), stats_panel(nullptr), game_panel(nullptr) {
    main_panel = new wxPanel(this);
    wxButton* button_start = new wxButton(main_panel, wxID_ANY, "1. Start", wxPoint(325, 150), wxSize(100, 35));
    wxButton* button_stats = new wxButton(main_panel, wxID_ANY, "2. Stats", wxPoint(325, 250), wxSize(100, 35));
    wxButton* button_exit = new wxButton(main_panel, wxID_ANY, "3. Exit", wxPoint(325, 350), wxSize(100, 35));
    
    wxBoxSizer* boxSizer = new wxBoxSizer(wxVERTICAL);
    wxSizerFlags flags = wxSizerFlags().CenterHorizontal().Border(wxALL, 25);

    
    boxSizer->AddStretchSpacer(1);
    boxSizer->Add(button_start, flags);
    boxSizer->Add(button_stats, flags);
    boxSizer->Add(button_exit, flags);
    boxSizer->AddStretchSpacer(1);
    main_panel->SetSizer(boxSizer);
    boxSizer->SetSizeHints(this);

    button_start->Bind(wxEVT_BUTTON, &MainFrame::OnStartClicked, this);
    button_stats->Bind(wxEVT_BUTTON, &MainFrame::OnStatsClicked, this);
    button_exit->Bind(wxEVT_BUTTON, &MainFrame::OnExitClicked, this);
    CreateStatusBar();
    SetClientSize(700, 500);
}

void MainFrame::OnStartClicked(wxCommandEvent& evt) {
    wxLogStatus("Button Clicked1");
    if (!game_panel) {
        //genFile()
        std::vector<std::string> text = readFromFile(genFile());
        //std::string tekst_blokk(text.begin(), text.end());
        /*for (char sym : text) {
            tekst_blokk += sym;
        }*/
        std::string tekst_to_display;
        for (const auto& text_line : text) {
            tekst_to_display += text_line;
        }
        game_panel = new wxPanel(this);
        wxStaticText* game_text = new wxStaticText(game_panel, wxID_ANY, tekst_to_display);
        wxBoxSizer* boxSizerGM = new wxBoxSizer(wxVERTICAL);
        wxSizerFlags flags_gm = wxSizerFlags().CenterHorizontal().Border(wxALL, 25);

        boxSizerGM->AddStretchSpacer(1);
        boxSizerGM->Add(game_text, flags_gm);
        boxSizerGM->AddStretchSpacer(1);
        game_panel->SetSizer(boxSizerGM);
        boxSizerGM->SetSizeHints(game_panel);
    }
    main_panel->Hide();
    game_panel->Show();
    game_panel->SetSize(GetClientSize());
    Layout();
}
void MainFrame::OnExitStatsClicked(wxCommandEvent& evt) {
    stats_panel->Hide();
    main_panel->Show();
}

void MainFrame::OnStatsClicked(wxCommandEvent& evt) {
    wxLogStatus("Button Clicked2");
    if (!stats_panel) {
        Stats gameStats;
        stats_panel = new wxPanel(this);

        wxButton* button_exit_st = new wxButton(stats_panel, wxID_ANY, "Peamenüü", wxPoint(325, 250), wxSize(100, 35));
        std::vector<std::string> lastTenLines = gameStats.getLastTenLines();
        std::string statistika{};
        for (const auto& line : lastTenLines) {
            statistika += line + 'n';
        }
        //wxLogStatus(statistika);
        wxStaticText* stat_box = new wxStaticText(stats_panel, wxID_ANY, statistika);

        wxBoxSizer* boxSizerST = new wxBoxSizer(wxVERTICAL);
        wxSizerFlags flags_st = wxSizerFlags().CenterHorizontal().Border(wxALL, 25);

        boxSizerST->AddStretchSpacer(1);
        boxSizerST->Add(stat_box, flags_st);
        boxSizerST->Add(button_exit_st, flags_st);
        boxSizerST->AddStretchSpacer(1);
        stats_panel->SetSizer(boxSizerST);
        boxSizerST->SetSizeHints(stats_panel);
        button_exit_st->Bind(wxEVT_BUTTON, &MainFrame::OnExitStatsClicked, this);
    }
    main_panel->Hide();
    stats_panel->Show();
    stats_panel->SetSize(GetClientSize());
    Layout();
    
    }
void MainFrame::OnExitClicked(wxCommandEvent& evt) {
    wxLogStatus("Éxiting");
    Close(true);
}


Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật