Fix Windows paint on resize issue. Automatically resize to fit tabs and button content

This commit is contained in:
Lam Wei Lun
2026-08-25 15:18:38 +08:00
parent d4cb739b8b
commit 795514900d
6 changed files with 58 additions and 4 deletions
+7
View File
@@ -7,6 +7,7 @@ BEGIN_EVENT_TABLE(StaticBox, wxWindow)
// catch paint events
//EVT_ERASE_BACKGROUND(StaticBox::eraseEvent)
EVT_SIZE(StaticBox::sizeEvent)
EVT_PAINT(StaticBox::paintEvent)
END_EVENT_TABLE()
@@ -140,6 +141,12 @@ void StaticBox::eraseEvent(wxEraseEvent& evt)
#endif
}
void StaticBox::sizeEvent(wxSizeEvent& evt)
{
Refresh();
evt.Skip();
}
void StaticBox::paintEvent(wxPaintEvent& evt)
{
// depending on your system you may need to look at double-buffered dcs
+2
View File
@@ -46,6 +46,8 @@ public:
protected:
void eraseEvent(wxEraseEvent& evt);
void sizeEvent(wxSizeEvent& evt);
void paintEvent(wxPaintEvent& evt);
void render(wxDC& dc);
+9
View File
@@ -295,6 +295,15 @@ void TabCtrl::relayout()
Layout();
}
int TabCtrl::buttons_best_width() const
{
// Mirrors relayout(): a 10px leading spacer plus every button's min width and spacing.
int width = 10;
for (const Button *btn : btns)
width += btn->GetMinSize().x + TAB_BUTTON_SPACE * 2;
return width;
}
void TabCtrl::buttonClicked(wxCommandEvent &event)
{
SetFocus();
+2
View File
@@ -73,6 +73,8 @@ private:
void relayout();
int buttons_best_width() const;
void buttonClicked(wxCommandEvent & event);
void keyDown(wxKeyEvent &event);