From 08fb2f27d38e8465a38320ea21ac6c274a2a5a61 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 24 Apr 2014 16:12:02 +0400 Subject: [PATCH] support multiple views for same EditableContent - demo --- examples/example1/src/main.d | 6 ++++++ src/dlangui/widgets/editors.d | 19 +++++++++++-------- src/dlangui/widgets/styles.d | 10 ++++++---- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/examples/example1/src/main.d b/examples/example1/src/main.d index b15bb318..19add55b 100644 --- a/examples/example1/src/main.d +++ b/examples/example1/src/main.d @@ -189,6 +189,12 @@ extern (C) int UIAppMain(string[] args) { editors.addChild(createEditorSettingsControl(editBox)); editors.addChild(editBox); + editors.addChild(new TextWidget(null, "EditBox: additional view for the same content (split view testing)"d)); + EditBox editBox2 = new EditBox("editbox2", ""d); + editBox2.content = editBox.content; // view the same content as first editbox + editors.addChild(editBox2); + editors.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT); + tabs.addTab(editors, "Editors"d); //========================================================================== diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index a775e754..48ec7f89 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -260,7 +260,7 @@ class UndoBuffer { /// Editable Content change listener interface EditableContentListener { - bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source); + void onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source); } /// editable plain text (singleline/multiline) @@ -333,8 +333,9 @@ class EditableContent { return m; } - bool handleContentChange(EditOperation op, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source) { - return contentChangeListeners(this, op, rangeBefore, rangeAfter, source); + void handleContentChange(EditOperation op, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source) { + // call listeners + contentChangeListeners(this, op, rangeBefore, rangeAfter, source); } /// return text for specified range @@ -766,20 +767,20 @@ class EditWidgetBase : WidgetGroup, EditableContentListener { protected void updateMaxLineWidth() { } - override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source) { + override void onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source) { updateMaxLineWidth(); measureVisibleText(); if (source is this) { _caretPos = rangeAfter.end; _selectionRange.start = _caretPos; _selectionRange.end = _caretPos; + ensureCaretVisible(); } else { correctCaretPos(); // TODO: do something better (e.g. take into account ranges when correcting) } - ensureCaretVisible(); invalidate(); - return true; + return; } @@ -1813,8 +1814,10 @@ class EditBox : EditWidgetBase, OnScrollHandler { updateMaxLineWidth(); - //measureText(); Point textSz = measureVisibleText(); + //int maxy = _lineHeight * 10; // limit measured height + //if (textSz.y > maxy) + // textSz.y = maxy; measuredContent(parentWidth, parentHeight, textSz.x + vsbwidth, textSz.y + hsbheight); } @@ -1869,7 +1872,7 @@ class EditBox : EditWidgetBase, OnScrollHandler { } // frame around current line - if (lineIndex == _caretPos.line && _selectionRange.singleLine && _selectionRange.start.line == _caretPos.line) { + if (focused && lineIndex == _caretPos.line && _selectionRange.singleLine && _selectionRange.start.line == _caretPos.line) { buf.drawFrame(visibleRect, 0xA0808080, Rect(1,1,1,1)); } } diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index f680eb76..61fa184a 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -713,10 +713,12 @@ Theme createDefaultTheme() { //listItem.createState(State.Selected, State.Selected).backgroundColor(0xC04040FF).textColor(0x000000); //listItem.createState(State.Enabled, 0).textColor(0x80000000); // half transparent text for disabled item - Style editLine = res.createSubstyle("EDIT_LINE").backgroundImageId("editbox_background").padding(Rect(5,6,5,6)).margins(Rect(2,2,2,2)).minWidth(40); - editLine.fontFace("Arial").fontFamily(FontFamily.SansSerif).fontSize(16); - Style editBox = res.createSubstyle("EDIT_BOX").backgroundImageId("editbox_background").padding(Rect(5,6,5,6)).margins(Rect(2,2,2,2)).minWidth(100).minHeight(60); - editBox.fontFace("Courier New").fontFamily(FontFamily.MonoSpace).fontSize(16); + Style editLine = res.createSubstyle("EDIT_LINE").backgroundImageId("editbox_background") + .padding(Rect(5,6,5,6)).margins(Rect(2,2,2,2)).minWidth(40) + .fontFace("Arial").fontFamily(FontFamily.SansSerif).fontSize(16); + Style editBox = res.createSubstyle("EDIT_BOX").backgroundImageId("editbox_background") + .padding(Rect(5,6,5,6)).margins(Rect(2,2,2,2)).minWidth(100).minHeight(60).layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT) + .fontFace("Courier New").fontFamily(FontFamily.MonoSpace).fontSize(16); return res; }