diff options
author | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-10-28 17:36:08 +0100 |
---|---|---|
committer | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-10-28 17:36:08 +0100 |
commit | b5318414da6bb2b356f67b16252f1da8dcdd0084 (patch) | |
tree | 7617b5b2dab98859fd14f6a8a9c6fda2cd004841 | |
parent | Table[Model|View]: Add [Publish]RowsChanged for more efficient update of a range of rows (diff) | |
download | wireguard-windows-b5318414da6bb2b356f67b16252f1da8dcdd0084.tar.xz wireguard-windows-b5318414da6bb2b356f67b16252f1da8dcdd0084.zip |
TableView: Implement width calculation of StretchLastColumn ourselves
This is done to avoid flicker when scrolling vertically in presence of a long text that would normally cause the horizontal scroll bar to show up.
-rw-r--r-- | tableview.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tableview.go b/tableview.go index 39f3fb2d..41c5fa74 100644 --- a/tableview.go +++ b/tableview.go @@ -1414,7 +1414,31 @@ func (tv *TableView) StretchLastColumn() error { return nil } - if 0 == win.SendMessage(tv.hwndNormalLV, win.LVM_SETCOLUMNWIDTH, uintptr(colCount-1), win.LVSCW_AUTOSIZE_USEHEADER) { + var hwnd win.HWND + if tv.visibleColumnCount()-tv.visibleFrozenColumnCount() == 0 { + hwnd = tv.hwndFrozenLV + } else { + hwnd = tv.hwndNormalLV + } + + width := tv.ClientBoundsPixels().Width + lastIndexInLV := -1 + var lastIndexInLVWidth int + for _, tvc := range tv.columns.items { + colWidth := tvc.Width() + if index := tvc.indexInListView(); int(index) > lastIndexInLV { + lastIndexInLV = int(index) + lastIndexInLVWidth = colWidth + } + width -= colWidth + } + width += lastIndexInLVWidth + + if hasWindowLongBits(tv.hwndNormalLV, win.GWL_STYLE, win.WS_VSCROLL) { + width -= int(win.GetSystemMetricsForDpi(win.SM_CXVSCROLL, uint32(tv.DPI()))) + } + + if 0 == win.SendMessage(hwnd, win.LVM_SETCOLUMNWIDTH, uintptr(colCount-1), uintptr(width)) { return newError("LVM_SETCOLUMNWIDTH failed") } |