Skip to content

Commit 236c485

Browse files
committed
fix bad tabs paint when opening first file
SetSelected() triggers sync paint which happened before we did layout so it was painting text in the wrong {0,0} position.
1 parent f82aca8 commit 236c485

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/wingui/WinGui.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,8 +3034,6 @@ void TabsCtrl::LayoutTabs() {
30343034
tabSize = {dx, dy};
30353035
// logfa("TabsCtrl::Layout size: (%d, %d), tab size: (%d, %d)\n", rect.dx, rect.dy, tabSize.dx, tabSize.dy);
30363036

3037-
HwndTabsSetItemSize(hwnd, tabSize);
3038-
30393037
int closeDy = DpiScale(hwnd, 8);
30403038
int closeDx = closeDy;
30413039
int closeY = (dy - closeDy) / 2;
@@ -3070,7 +3068,7 @@ void TabsCtrl::LayoutTabs() {
30703068
}
30713069
free(tools);
30723070

3073-
HwndScheduleRepaint(hwnd);
3071+
HwndTabsSetItemSize(hwnd, tabSize);
30743072
}
30753073

30763074
// Finds the index of the tab, which contains the given point.
@@ -3127,7 +3125,7 @@ bool TabsCtrl::IsValidIdx(int idx) {
31273125
return idx >= 0 && idx < TabCount();
31283126
}
31293127

3130-
void TabsCtrl::Paint(HDC hdc, RECT& rc) {
3128+
void TabsCtrl::Paint(HDC hdc, const RECT& rc) {
31313129
TabsCtrl::MouseState tabState = TabStateFromMousePosition(lastMousePos);
31323130
int tabUnderMouse = tabState.tabIdx;
31333131
bool overClose = tabState.overClose && tabState.tabInfo->canClose;
@@ -3699,8 +3697,11 @@ int TabsCtrl::InsertTab(int idx, TabInfo* tab) {
36993697
return res;
37003698
}
37013699
tabs.InsertAt(idx, tab);
3702-
SetSelected(idx);
3700+
// LayoutTabs() must be before SetSelected() because SetSelected()
3701+
// triggers sync repaint which paints tab texts in wrong positions
3702+
// because we didn't position them yet in layout.
37033703
LayoutTabs();
3704+
SetSelected(idx);
37043705
TabsCtrlUpdateAfterChangingTabsCount(this);
37053706
return idx;
37063707
}

src/wingui/WinGui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ struct TabsCtrl : Wnd {
803803
void LayoutTabs();
804804
void ScheduleRepaint();
805805
TabsCtrl::MouseState TabStateFromMousePosition(const Point& p);
806-
void Paint(HDC hdc, RECT& rc);
806+
void Paint(HDC hdc, const RECT& rc);
807807
HBITMAP RenderForDragging(int idx);
808808
};
809809

0 commit comments

Comments
 (0)