doublemax wrote: ↑Fri Jul 09, 2021 3:12 pm
Catch the size event of the status bar, not the frame. And, in 99.9% of all cases when you have an wxEVT_SIZE event handler, you need to call event.Skip in it.
I see. I tried catching the event for status bar, looks like its working now, I did ran the app at first without the event.Skip() it crashed immediately.
Code: Select all
MainFrame::MainFrame()
: wxFrame(NULL, wxID_ANY, "Sample Hive", wxDefaultPosition),
m_ConfigFilepath("config.yaml"), m_DatabaseFilepath("sample.hive")
{
m_StatusBar = CreateStatusBar(3);
int status_width[3] = { -2, -6, -1 };
m_StatusBar->SetStatusWidths(3, status_width);
bm = new wxStaticBitmap(m_StatusBar, wxID_ANY, wxBitmap(ICON_APP));
Then I connected the status bar to the event,
Code: Select all
m_StatusBar->Connect(wxEVT_SIZE, wxSizeEventHandler(MainFrame::OnResizeStatusBar), NULL, this);
Here is the event handler,
Code: Select all
void MainFrame::OnResizeStatusBar(wxSizeEvent& event)
{
wxLogDebug("RESIZING..");
wxRect rect;
m_StatusBar->GetFieldRect(2, rect);
wxSize bmsize = bm->GetSize();
bm->Move(rect.x + (rect.width - bmsize.x),
rect.y + (rect.height - bmsize.y));
event.Skip();
}
There is one problem however, initially it draws the bitmap in the bottom left, beginning of the statusbar.
But when I resize the window, then it moves to the right position,
Also when I resize the window a bit too small, the bitmap starts overlapping the text and the second section of the statusbar, moves a little too much backwards then I would like, I want it to always be under the wxDVLC, just starting from the below the sash line of wxDirCtrl. Can sizers be places in the statusbar to properly layout widgets?
Maybe I should start with setting the minimum size of the window, and it should not be resizable below that. But what about the statusbar section widths? Do I set it to something like m_BottomSplitter->GetMinWidth() ?