UI module

text_editor

procedureextensionexperimentalsince 0.31.0Source

A multi-line text editor over edit: line numbers, selection, scrolling, undo and the clipboard. Returns true on the frame the text changed. It fills the space it is given.

Example↗
#import "Basic";
#import "Extensions/UI";

Notes :: struct {
    edit: Text_Edit;
    dirty: bool;
}

main :: () {
    notes: Notes;
    run_app(.{title = "Notes", width = 480, height = 320}, *notes, build);
}

build :: (notes: *Notes) {
    if text_editor(*notes.edit, .{line_numbers = true}) notes.dirty = true;
}

This one is only checked to compile, not run.

Example↗
doc: Text_Edit;
defer free_text_edit(*doc);
set_contents(*doc, "first line\nsecond line");
ui := headless();
defer free_ui(*ui);
build := (e: *Text_Edit) { for column() { text_editor(e, .{ line_numbers = true }); } };
frame(*ui, *doc, build);
assert(find_role(*ui, .TEXT_EDITOR) != null);
text_editor :: (
    edit: *Text_Edit,
    options: Editor_Options = .{},
    loc := #caller_location
) -> changed: bool

A multi-line text editor over edit: line numbers, selection, scrolling, undo and the clipboard. Returns true on the frame the text changed. It fills the space it is given.

Parameters

edit: *Text_Edit
the text being edited.
options: Editor_Options = .{}
font, size, line numbers, highlighting, marks, read-only mode and tab width.
loc := #caller_location
the call site. It identifies the widget from one frame to the next, so leave the default.

Returns

changed: bool
Example↗
#import "Basic";
#import "Extensions/UI";

Notes :: struct {
    edit: Text_Edit;
    dirty: bool;
}

main :: () {
    notes: Notes;
    run_app(.{title = "Notes", width = 480, height = 320}, *notes, build);
}

build :: (notes: *Notes) {
    if text_editor(*notes.edit, .{line_numbers = true}) notes.dirty = true;
}

This one is only checked to compile, not run.

Example↗
doc: Text_Edit;
defer free_text_edit(*doc);
set_contents(*doc, "first line\nsecond line");
ui := headless();
defer free_ui(*ui);
build := (e: *Text_Edit) { for column() { text_editor(e, .{ line_numbers = true }); } };
frame(*ui, *doc, build);
assert(find_role(*ui, .TEXT_EDITOR) != null);

See also