mirror of https://github.com/buggins/dlangui.git
support multiple views for same EditableContent - demo
This commit is contained in:
parent
8b0570b22e
commit
08fb2f27d3
|
@ -189,6 +189,12 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
editors.addChild(createEditorSettingsControl(editBox));
|
editors.addChild(createEditorSettingsControl(editBox));
|
||||||
editors.addChild(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);
|
tabs.addTab(editors, "Editors"d);
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -260,7 +260,7 @@ class UndoBuffer {
|
||||||
|
|
||||||
/// Editable Content change listener
|
/// Editable Content change listener
|
||||||
interface EditableContentListener {
|
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)
|
/// editable plain text (singleline/multiline)
|
||||||
|
@ -333,8 +333,9 @@ class EditableContent {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleContentChange(EditOperation op, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source) {
|
void handleContentChange(EditOperation op, ref TextRange rangeBefore, ref TextRange rangeAfter, Object source) {
|
||||||
return contentChangeListeners(this, op, rangeBefore, rangeAfter, source);
|
// call listeners
|
||||||
|
contentChangeListeners(this, op, rangeBefore, rangeAfter, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return text for specified range
|
/// return text for specified range
|
||||||
|
@ -766,20 +767,20 @@ class EditWidgetBase : WidgetGroup, EditableContentListener {
|
||||||
protected void updateMaxLineWidth() {
|
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();
|
updateMaxLineWidth();
|
||||||
measureVisibleText();
|
measureVisibleText();
|
||||||
if (source is this) {
|
if (source is this) {
|
||||||
_caretPos = rangeAfter.end;
|
_caretPos = rangeAfter.end;
|
||||||
_selectionRange.start = _caretPos;
|
_selectionRange.start = _caretPos;
|
||||||
_selectionRange.end = _caretPos;
|
_selectionRange.end = _caretPos;
|
||||||
|
ensureCaretVisible();
|
||||||
} else {
|
} else {
|
||||||
correctCaretPos();
|
correctCaretPos();
|
||||||
// TODO: do something better (e.g. take into account ranges when correcting)
|
// TODO: do something better (e.g. take into account ranges when correcting)
|
||||||
}
|
}
|
||||||
ensureCaretVisible();
|
|
||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1813,8 +1814,10 @@ class EditBox : EditWidgetBase, OnScrollHandler {
|
||||||
|
|
||||||
updateMaxLineWidth();
|
updateMaxLineWidth();
|
||||||
|
|
||||||
//measureText();
|
|
||||||
Point textSz = measureVisibleText();
|
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);
|
measuredContent(parentWidth, parentHeight, textSz.x + vsbwidth, textSz.y + hsbheight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1869,7 +1872,7 @@ class EditBox : EditWidgetBase, OnScrollHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// frame around current line
|
// 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));
|
buf.drawFrame(visibleRect, 0xA0808080, Rect(1,1,1,1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -713,10 +713,12 @@ Theme createDefaultTheme() {
|
||||||
//listItem.createState(State.Selected, State.Selected).backgroundColor(0xC04040FF).textColor(0x000000);
|
//listItem.createState(State.Selected, State.Selected).backgroundColor(0xC04040FF).textColor(0x000000);
|
||||||
//listItem.createState(State.Enabled, 0).textColor(0x80000000); // half transparent text for disabled item
|
//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);
|
Style editLine = res.createSubstyle("EDIT_LINE").backgroundImageId("editbox_background")
|
||||||
editLine.fontFace("Arial").fontFamily(FontFamily.SansSerif).fontSize(16);
|
.padding(Rect(5,6,5,6)).margins(Rect(2,2,2,2)).minWidth(40)
|
||||||
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);
|
.fontFace("Arial").fontFamily(FontFamily.SansSerif).fontSize(16);
|
||||||
editBox.fontFace("Courier New").fontFamily(FontFamily.MonoSpace).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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue