From 1bba303cc3bd197c84dc32dcd0ed2add759fca44 Mon Sep 17 00:00:00 2001 From: and3md Date: Sat, 19 Aug 2017 15:37:29 +0200 Subject: [PATCH] Fix grid scroll pos on startup, extend scroll area on options (fullRowOnTop, fullColumnOnLeft). --- src/dlangui/widgets/grid.d | 59 +++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/dlangui/widgets/grid.d b/src/dlangui/widgets/grid.d index 8d450b48..0cc5d603 100644 --- a/src/dlangui/widgets/grid.d +++ b/src/dlangui/widgets/grid.d @@ -1174,9 +1174,39 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler return super.onMouseEvent(event); } + protected bool _fullColumnOnLeft = true; + /// Extends scroll area to show full column at left when scrolled to rightmost column + @property bool fullColumnOnLeft() { return _fullColumnOnLeft; } + /// Extends scroll area to show full column at left when scrolled to rightmost column + @property GridWidgetBase fullColumnOnLeft(bool newFullColumnOnLeft) { + if (_fullColumnOnLeft != newFullColumnOnLeft) { + _fullColumnOnLeft = newFullColumnOnLeft; + updateScrollBars(); + } + return this; + } + + protected bool _fullRowOnTop = true; + /// Extends scroll area to show full row at top when scrolled to end row + @property bool fullRowOnTop() { return _fullColumnOnLeft; } + /// Extends scroll area to show full row at top when scrolled to end row + @property GridWidgetBase fullRowOnTop(bool newFullRowOnTop) { + if (_fullRowOnTop != newFullRowOnTop) { + _fullRowOnTop = newFullRowOnTop; + updateScrollBars(); + } + return this; + } /// calculate scrollable area info protected void calcScrollableAreaPos() { + // don't calc if client rect was not set + if (_clientRect.size.x == 0 && _clientRect.size.y == 0) { + _scrollX = 0; + _scrollY = 0; + return; + } + if (_scrollX < 0) _scrollX = 0; if (_scrollY < 0) @@ -1196,22 +1226,23 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler _fullScrollableArea.right = clientPixels.x; if (_fullScrollableArea.bottom < clientPixels.y) _fullScrollableArea.bottom = clientPixels.y; - + // extending scroll area if necessary - int maxscrollx = _fullScrollableArea.right - scrollableClient.x; - int col = colByAbsoluteX(maxscrollx); - int maxscrolly = _fullScrollableArea.bottom - scrollableClient.y; - int row = rowByAbsoluteY(maxscrolly); - Rect rc = cellRectNoScroll(col, row); + if (_fullRowOnTop || _fullColumnOnLeft) { + int maxscrollx = _fullScrollableArea.right - scrollableClient.x; + int col = colByAbsoluteX(maxscrollx); + int maxscrolly = _fullScrollableArea.bottom - scrollableClient.y; + int row = rowByAbsoluteY(maxscrolly); + Rect rc = cellRectNoScroll(col, row); - // extend scroll area to show full column at left when scrolled to rightmost column - if (maxscrollx >= nonscrollPixels.x && rc.left < maxscrollx) { - _fullScrollableArea.right += rc.right - maxscrollx; - } + // extend scroll area to show full column at left when scrolled to rightmost column + if (_fullColumnOnLeft && maxscrollx >= nonscrollPixels.x && rc.left < maxscrollx) + _fullScrollableArea.right += rc.right - maxscrollx; - // extend scroll area to show full row at top when scrolled to end row - if (maxscrolly >= nonscrollPixels.y && rc.top < maxscrolly) { - _fullScrollableArea.bottom += rc.bottom - maxscrolly; + + // extend scroll area to show full row at top when scrolled to end row + if (_fullRowOnTop && maxscrolly >= nonscrollPixels.y && rc.top < maxscrolly) + _fullScrollableArea.bottom += rc.bottom - maxscrolly; } // scrollable area @@ -1659,6 +1690,8 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler } protected int measureColWidth(int x) { + if (!showRowHeaders && x < _headerCols) + return 0; int m = 0; for (int i = 0; i < _rows; i++) { Point sz = measureCell(x - _headerCols, i - _headerRows);