diff options
author | Alexander Neumann <an2048@gmail.com> | 2019-11-06 18:26:53 +0100 |
---|---|---|
committer | Alexander Neumann <an2048@gmail.com> | 2019-11-06 18:26:53 +0100 |
commit | 8c6cb582c05e57a9433b906a5a4ffbad7e7fb6f7 (patch) | |
tree | 1efd5728bf44066cfc24038cc4c087f8c9fd68a0 | |
parent | ImageList: Add DrawPixels (diff) | |
download | wireguard-windows-8c6cb582c05e57a9433b906a5a4ffbad7e7fb6f7.tar.xz wireguard-windows-8c6cb582c05e57a9433b906a5a4ffbad7e7fb6f7.zip |
TableView: Prevent painting glitch that could occur on size change
-rw-r--r-- | tableview.go | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/tableview.go b/tableview.go index 764589ae..b0593ef3 100644 --- a/tableview.go +++ b/tableview.go @@ -659,6 +659,13 @@ func (tv *TableView) Invalidate() error { return tv.WidgetBase.Invalidate() } +func (tv *TableView) redrawItems() { + first := win.SendMessage(tv.hwndNormalLV, win.LVM_GETTOPINDEX, 0, 0) + last := first + win.SendMessage(tv.hwndNormalLV, win.LVM_GETCOUNTPERPAGE, 0, 0) + 1 + win.SendMessage(tv.hwndFrozenLV, win.LVM_REDRAWITEMS, first, last) + win.SendMessage(tv.hwndNormalLV, win.LVM_REDRAWITEMS, first, last) +} + // UpdateItem ensures the item at index will be redrawn. // // If the model supports sorting, it will be resorted. @@ -741,10 +748,7 @@ func (tv *TableView) attachModel() { col := sorter.SortedColumn() tv.setSortIcon(col, sorter.SortOrder()) - first := win.SendMessage(tv.hwndNormalLV, win.LVM_GETTOPINDEX, 0, 0) - last := first + win.SendMessage(tv.hwndNormalLV, win.LVM_GETCOUNTPERPAGE, 0, 0) + 1 - win.SendMessage(tv.hwndFrozenLV, win.LVM_REDRAWITEMS, first, last) - win.SendMessage(tv.hwndNormalLV, win.LVM_REDRAWITEMS, first, last) + tv.redrawItems() }) } } @@ -2471,6 +2475,23 @@ func (tv *TableView) WndProc(hwnd win.HWND, msg uint32, wp, lp uintptr) uintptr tv.updateLVSizes() + // FIXME: The InvalidateRect and redrawItems calls below prevent + // painting glitches on resize. Though this seems to work reasonably + // well, in the long run we would like to find the root cause of this + // issue and come up with a better fix. + dpi := uint32(tv.DPI()) + var rc win.RECT + + vsbWidth := win.GetSystemMetricsForDpi(win.SM_CXVSCROLL, dpi) + rc = win.RECT{wp.Cx - vsbWidth - 1, 0, wp.Cx, wp.Cy} + win.InvalidateRect(tv.hWnd, &rc, true) + + hsbHeight := win.GetSystemMetricsForDpi(win.SM_CYHSCROLL, dpi) + rc = win.RECT{0, wp.Cy - hsbHeight - 1, wp.Cx, wp.Cy} + win.InvalidateRect(tv.hWnd, &rc, true) + + tv.redrawItems() + case win.WM_TIMER: if !win.KillTimer(tv.hWnd, wp) { lastError("KillTimer") |