From d39fadd1d07e073771960d72d6294cb40cc7bc1f Mon Sep 17 00:00:00 2001 From: James Johnson Date: Thu, 11 Jan 2018 09:59:15 -0500 Subject: [PATCH] CaretRect in progress --- src/dlangui/core/editable.d | 16 +++++++++++++++- src/dlangui/widgets/editors.d | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/dlangui/core/editable.d b/src/dlangui/core/editable.d index 3a781b36..b6f8e4de 100644 --- a/src/dlangui/core/editable.d +++ b/src/dlangui/core/editable.d @@ -452,8 +452,22 @@ struct LineSpan { int len; /// the wrapping points WrapPoint[] wrapPoints; - + /// the wrapped text dstring[] wrappedContent; + + int widthAccumulation(int wrapLine) + { + int widthTotal; + for (int i; i < wrapLine; i++) + { + if (i < this.wrapPoints.length - 1) + { + int curWidth = this.wrapPoints[i].wrapWidth; + widthTotal += curWidth; + } + } + return widthTotal; + } } struct WrapPoint { diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 44cb04e3..79f73803 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -1264,6 +1264,8 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction handleAction(ACTION_EDITOR_SELECT_ALL); super.handleFocusChange(focused); } + + protected int _firstVisibleLine; /// returns cursor rectangle protected Rect caretRect() { @@ -1280,10 +1282,18 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction } } if (_wordWrap) + { + _scrollPos.x = 0; + int wrapLine = findWrapLine(_caretPos); + int xOffset; + if (wrapLine > 0) { - _scrollPos.x = 0; - caretRc.offset(_clientRect.left, _clientRect.top); + LineSpan curSpan = getSpan(_caretPos.line); + xOffset = curSpan.widthAccumulation(wrapLine); } + auto yOffset = -1 * _lineHeight * (wrapsUpTo(_caretPos.line - _firstVisibleLine) + wrapLine); + caretRc.offset(_clientRect.left - xOffset, _clientRect.top - yOffset); + } else caretRc.offset(_clientRect.left, _clientRect.top); return caretRc; @@ -2470,7 +2480,7 @@ class EditBox : EditWidgetBase { } } - protected int _firstVisibleLine; + //protected int _firstVisibleLine; protected int _maxLineWidth; protected int _numVisibleLines; // number of lines visible in client area