From e56d3c4df37f0644754a27ba40d2646a59cd9984 Mon Sep 17 00:00:00 2001 From: James Johnson Date: Thu, 11 Jan 2018 08:07:56 -0500 Subject: [PATCH] Version 2 starting implementation --- src/dlangui/core/editable.d | 9 ++++ src/dlangui/widgets/editors.d | 83 ++++++++++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/src/dlangui/core/editable.d b/src/dlangui/core/editable.d index 3973d65c..3a781b36 100644 --- a/src/dlangui/core/editable.d +++ b/src/dlangui/core/editable.d @@ -450,6 +450,15 @@ struct LineSpan { int start; /// number of lines it spans int len; + /// the wrapping points + WrapPoint[] wrapPoints; + + dstring[] wrappedContent; +} + +struct WrapPoint { + int wrapPos; + int wrapWidth; } /// interface for custom syntax highlight, comments toggling, smart indents, and other language dependent features for source code editors diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 6460dc7e..2693b351 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -391,12 +391,28 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction return this; } - void wrapLine(dstring line, int maxWidth) { - + dstring[] wrapLine(dstring line, int maxWidth) { + return []; } /// information about line span into several lines - in word wrap mode protected LineSpan[] _span; + + int wrapsUpTo(int line) + { + if(line < _span.length) + { + + int sum; + for(int i = 0; i 0) { + if (txt.length > 0 || _wordWrap) { CustomCharProps[] highlight = _visibleLinesHighlights[i]; - if (highlight) - font.drawColoredText(buf, rc.left - _scrollPos.x, rc.top + i * _lineHeight, txt, highlight, tabSize); + if (_wordWrap) + { + dstring[] wrappedLine; + if (doRewrap) + wrappedLine = wrapLine(txt, _firstVisibleLine + i); + else + if (i < _span.length) + wrappedLine = _span[i].wrappedContent; + int accumulativeLength; + CustomCharProps[] wrapProps; + foreach (int q, curWrap; wrappedLine) + { + auto lineOffset = q + i + wrapsUpTo(i); + if (highlight) + { + wrapProps = highlight[accumulativeLength .. $]; + accumulativeLength += curWrap.length; + font.drawColoredText(buf, rc.left - _scrollPos.x, rc.top + lineOffset * _lineHeight, curWrap, wrapProps, tabSize); + } + else + font.drawText(buf, rc.left - _scrollPos.x, rc.top + lineOffset * _lineHeight, curWrap, textColor, tabSize); + + } + } else - font.drawText(buf, rc.left - _scrollPos.x, rc.top + i * _lineHeight, txt, textColor, tabSize); + { + if (highlight) + font.drawColoredText(buf, rc.left - _scrollPos.x, rc.top + i * _lineHeight, txt, highlight, tabSize); + else + font.drawText(buf, rc.left - _scrollPos.x, rc.top + i * _lineHeight, txt, textColor, tabSize); + } } }