dlangui.widgets.editors
This module contains implementation of editors.EditLine - single line editor.
EditBox - multiline editor
Synopsis:
import dlangui.widgets.editors;
License:
Boost License 1.0
Authors:
Vadim Lopatin, coolreader.org@gmail.com
- enum EditorActions: int;
- Editor action codes
- Left
- move cursor one char left
- SelectLeft
- move cursor one char left with selection
- Right
- move cursor one char right
- SelectRight
- move cursor one char right with selection
- Up
- move cursor one line up
- SelectUp
- move cursor one line up with selection
- Down
- move cursor one line down
- SelectDown
- move cursor one line down with selection
- WordLeft
- move cursor one word left
- SelectWordLeft
- move cursor one word left with selection
- WordRight
- move cursor one word right
- SelectWordRight
- move cursor one word right with selection
- PageUp
- move cursor one page up
- SelectPageUp
- move cursor one page up with selection
- PageDown
- move cursor one page down
- SelectPageDown
- move cursor one page down with selection
- PageBegin
- move cursor to the beginning of page
- SelectPageBegin
- move cursor to the beginning of page with selection
- PageEnd
- move cursor to the end of page
- SelectPageEnd
- move cursor to the end of page with selection
- LineBegin
- move cursor to the beginning of line
- SelectLineBegin
- move cursor to the beginning of line with selection
- LineEnd
- move cursor to the end of line
- SelectLineEnd
- move cursor to the end of line with selection
- DocumentBegin
- move cursor to the beginning of document
- SelectDocumentBegin
- move cursor to the beginning of document with selection
- DocumentEnd
- move cursor to the end of document
- SelectDocumentEnd
- move cursor to the end of document with selection
- DelPrevChar
- delete char before cursor (backspace)
- DelNextChar
- delete char after cursor (del key)
- DelPrevWord
- delete word before cursor (ctrl + backspace)
- DelNextWord
- delete char after cursor (ctrl + del key)
- InsertNewLine
- insert new line (Enter)
- PrependNewLine
- insert new line after current position (Ctrl+Enter)
- ToggleReplaceMode
- Turn On/Off replace mode
- Copy
- Copy selection to clipboard
- Cut
- Cut selection to clipboard
- Paste
- Paste selection from clipboard
- Undo
- Undo last change
- Redo
- Redo last undoed change
- Tab
- Tab (e.g., Tab key to insert tab character or indent text)
- BackTab
- Tab (unindent text, or remove whitespace before cursor, usually Shift+Tab)
- SelectAll
- Select whole content (usually, Ctrl+A)
- ScrollLineUp
- Scroll one line up (not changing cursor)
- ScrollLineDown
- Scroll one line down (not changing cursor)
- ScrollPageUp
- Scroll one page up (not changing cursor)
- ScrollPageDown
- Scroll one page down (not changing cursor)
- ScrollLeft
- Scroll window left
- ScrollRight
- Scroll window right
- ZoomIn
- Zoom in editor font
- ZoomOut
- Zoom out editor font
- dstring[] splitDString(dstring source, dchar delimiter = EOL);
- split dstring by delimiters
- dstring concatDStrings(dstring[] lines, dstring delimiter = SYSTEM_DEFAULT_EOL);
- concat strings from array using delimiter
- dstring replaceEolsWithSpaces(dstring source);
- replace end of lines with spaces
- struct TextPosition;
- text content position
- struct TextRange;
- text content range
- enum EditAction: int;
- action performed with editable contents
- class EditOperation;
- edit operation details for EditableContent
- @property EditAction action();
- action performed
- @property ref TextRange range();
- source range to replace with new content
- @property ref TextRange newRange();
- new range after operation applied
- protected dstring[] _content;
- new content for range (if required for this action)
- protected dstring[] _oldContent;
- old content for range
- bool merge(EditOperation op);
- try to merge two operations (simple entering of characters in the same line), return true if succeded
- class UndoBuffer;
- Undo/Redo buffer
- @property bool hasUndo();
- returns true if buffer contains any undo items
- @property bool hasRedo();
- returns true if buffer contains any redo items
- void saveForUndo(EditOperation op);
- adds undo operation
- EditOperation undo();
- returns operation to be undone (put it to redo), null if no undo ops available
- EditOperation redo();
- returns operation to be redone (put it to undo), null if no undo ops available
- void clear();
- clears both undo and redo buffers
- interface EditableContentListener;
- Editable Content change listener
- class EditableContent;
- editable plain text (singleline/multiline)
- Signal!EditableContentListener contentChangeListeners;
- listeners for edit operations
- @property bool multiline();
- returns true if miltyline content is supported
- @property dstring text();
- returns all lines concatenated delimited by '\n'
- @property EditableContent text(dstring newContent);
- replace whole text with another content
- @property int length();
- returns line text
- dstring line(int index);
- returns line text by index, "" if index is out of bounds
- TextPosition lineEnd(int lineIndex);
- returns text position for end of line lineIndex
- TextPosition firstNonSpace(int lineIndex);
- returns position before first non-space character of line, returns 0 position if no non-space chars
- TextPosition lastNonSpace(int lineIndex);
- returns position after last non-space character of line, returns 0 position if no non-space chars on line
- int lineLength(int lineIndex);
- returns text position for end of line lineIndex
- int maxLineLength();
- returns maximum length of line
- dstring[] rangeText(TextRange range);
- return text for specified range
- void correctPosition(ref TextPosition position);
- when position is out of content bounds, fix it to nearest valid position
- void correctRange(ref TextRange range);
- when range positions is out of content bounds, fix it to nearest valid position
- protected void removeLines(int start, int removedCount);
- removes removedCount lines starting from start
- protected void insertLines(int start, int count);
- inserts count empty lines at specified position
- protected void replaceRange(TextRange before, TextRange after, dstring[] newContent);
- inserts or removes lines, removes text in range
- TextPosition moveByWord(TextPosition p, int direction, bool camelCasePartsAsWords);
- change text position to nearest word bound (direction < 0 - back, > 0 - forward)
- bool performOperation(EditOperation op, Object source);
- edit content
- @property bool hasUndo();
- return true if there is at least one operation in undo buffer
- @property bool hasRedo();
- return true if there is at least one operation in redo buffer
- bool undo();
- undoes last change
- bool redo();
- redoes last undone change
- void clearUndo();
- clear undo/redp history
- abstract class EditWidgetBase: dlangui.widgets.scroll.ScrollWidgetBase, dlangui.widgets.editors.EditableContentListener, dlangui.widgets.menu.MenuItemActionHandler;
- base for all editor widgets
- bool onMenuItemAction(const Action action);
- bool canShowPopupMenu(int x, int y);
- returns true if widget can show popup (e.g. by mouse right click at point x,y)
- bool isActionEnabled(const Action action);
- override to change popup menu items state
- void showPopupMenu(int x, int y);
- shows popup at (x,y)
- uint getCursorType(int x, int y);
- returns mouse cursor type for widget
- @property bool wantTabs();
- when true, Tab / Shift+Tab presses are processed internally in widget (e.g. insert tab character) instead of focus change navigation.
- @property EditWidgetBase wantTabs(bool wantTabs);
- sets tab size (in number of spaces)
- @property bool readOnly();
- readonly flag (when true, user cannot change content of editor)
- @property EditWidgetBase readOnly(bool readOnly);
- sets readonly flag
- @property bool replaceMode();
- replace mode flag (when true, entered character replaces character under cursor)
- @property EditWidgetBase replaceMode(bool replaceMode);
- sets replace mode flag
- @property bool useSpacesForTabs();
- when true, spaces will be inserted instead of tabs
- @property EditWidgetBase useSpacesForTabs(bool useSpacesForTabs);
- set new Tab key behavior flag: when true, spaces will be inserted instead of tabs
- @property int tabSize();
- returns tab size (in number of spaces)
- @property EditWidgetBase tabSize(int newTabSize);
- sets tab size (in number of spaces)
- @property EditableContent content();
- editor content object
- protected bool _ownContent;
- when ownContent is false, content should not be destroyed in editor destructor
- @property EditWidgetBase content(EditableContent content);
- set content object
- @property dstring text();
- get widget text
- @property Widget text(dstring s);
- set text
- @property Widget text(UIString s);
- set text
- protected Rect caretRect();
- returns cursor rectangle
- protected void drawCaret(DrawBuf buf);
- draws caret
- protected void correctCaretPos();
- when cursor position or selection is out of content bounds, fix it to nearest valid position
- protected dstring spacesForTab(int currentPos);
- generate string of spaces, to reach next tab position
- protected bool wholeLinesSelected();
- returns true if one or more lines selected fully
- protected dstring indentLine(dstring src, bool back);
- change line indent
- protected void indentRange(bool back);
- indent / unindent range
- protected Action findKeyAction(uint keyCode, uint flags);
- map key to action
- bool onKeyEvent(KeyEvent event);
- handle keys
- bool onMouseEvent(MouseEvent event);
- process mouse event; return true if event is processed by widget.
- class EditLine: dlangui.widgets.editors.EditWidgetBase;
- single line editor
- void measure(int parentWidth, int parentHeight);
- measure
- bool onKeyEvent(KeyEvent event);
- handle keys
- bool onMouseEvent(MouseEvent event);
- process mouse event; return true if event is processed by widget.
- void layout(Rect rc);
- Set widget rectangle to specified value and layout widget contents. (Step 2 of two phase layout).
- protected void drawLineBackground(DrawBuf buf, Rect lineRect, Rect visibleRect);
- override to custom highlight of line background
- void onDraw(DrawBuf buf);
- draw content
- class EditBox: dlangui.widgets.editors.EditWidgetBase;
- single line editor
- protected void updateHScrollBar();
- update horizontal scrollbar widget position
- protected void updateVScrollBar();
- update verticat scrollbar widget position
- bool onHScroll(ScrollEvent event);
- process horizontal scrollbar event
- bool onVScroll(ScrollEvent event);
- process vertical scrollbar event
- Point fullContentSize();
- calculate full content size in pixels
- void measure(int parentWidth, int parentHeight);
- measure
- protected void drawLineBackground(DrawBuf buf, int lineIndex, Rect lineRect, Rect visibleRect);
- override to custom highlight of line background