Text Widgets¶
Label¶
Static text with alignment, color, and font options.
Constructor: new Widgets.Label(text, {halign})
Options:
halign– horizontal alignment ("left","center","right")
Methods:
Method |
Description |
|---|---|
|
Set label text. |
|
Return current text. |
|
Set background and foreground colors. |
|
Set horizontal alignment ( |
|
Set vertical alignment ( |
Callbacks: None.
let label = new Widgets.Label("Status: OK", {halign: "left"});
label.set_color(null, "green");
TextEntry¶
Single-line text input with optional line history.
Constructor: new Widgets.TextEntry({text, editable, linehistory, password})
Options:
text– initial texteditable– whether text is editablelinehistory– enable up/down arrow line historypassword– mask input as password
Methods:
Method |
Description |
|---|---|
|
Set text content. |
|
Return current text. |
|
Clear the text field. |
|
Set display width in characters. |
Callbacks:
activated– fired when Enter is pressed.
let entry = new Widgets.TextEntry({linehistory: true});
entry.add_callback('activated', (w) => {
console.log("Entered:", w.get_text());
w.clear();
});
TextEntrySet¶
Text entry with a submit button.
Constructor: new Widgets.TextEntrySet({text, value, editable, linehistory})
Options:
text– button label textvalue– initial entry texteditable– whether text is editablelinehistory– enable line history
Methods:
Method |
Description |
|---|---|
|
Set the button label. |
|
Set entry text. |
|
Return current text. |
|
Clear the text field. |
|
Set display width in characters. |
Callbacks:
activated– fired when the button is pressed or Enter is pressed.
TextArea¶
Multi-line text editor.
Constructor: new Widgets.TextArea(text, {wrap, editable})
Options:
wrap– enable text wrappingeditable– whether text is editable
Methods:
Method |
Description |
|---|---|
|
Set text content. |
|
Return current text. |
|
Append text at the end. |
|
Clear all text. |
|
Set editable state. |
|
Set word-wrap mode. |
|
Limit visible lines (scrollback). |
Callbacks: None.
let log = new Widgets.TextArea("", {wrap: true, editable: false});
log.set_limit(1000);
log.append_text("Application started.\n");
HtmlView¶
Read-only rich HTML content display with pgwidgets-style scrollbars.
Constructor: new Widgets.HtmlView(html)
Methods:
Method |
Description |
|---|---|
|
Set HTML content, replacing existing content. |
|
Return current HTML content. |
|
Append HTML to existing content. |
|
Remove all content. |
|
Scroll to the top. |
|
Scroll to the bottom. |
Callbacks: None.
let view = new Widgets.HtmlView("<h1>Hello</h1><p>Rich content here.</p>");
vbox.add_widget(view, 1);
// Update content dynamically
view.set_html("<h2>Updated</h2><p>New content.</p>");
view.append_html("<p>Another paragraph.</p>");
TextSource¶
Source code editor with line numbers, syntax highlighting support, tags, undo/redo, and find/replace.
Constructor: new Widgets.TextSource(text, {wrap, line_numbers, icon_gutter, editable, font_family, font_size})
Options:
wrap– wrap modeline_numbers– show line numbersicon_gutter– show icon guttereditable– whether text is editablefont_family– font family namefont_size– font size
Positions in the buffer are expressed as TextBufferRef instances —
live references that automatically track edits. The only place a
caller deals in raw integer offsets is when minting a ref via
create_ref(offset, gravity). Every other position-taking or
position-returning method on the public API uses refs.
Methods:
Method |
Description |
|---|---|
|
Set or get text content. |
|
Return text length (characters). |
|
Return the text between two refs as a plain string. Smaller offset becomes the start. |
|
Insert text at the position of ref with optional tag names. |
|
Delete the text between two refs. |
|
Clear all text. |
|
Set editable state. |
|
Set wrap mode. |
|
Show/hide line numbers. |
|
Show/hide icon gutter. |
|
Anchor an icon to ref; it follows the ref’s line as the
buffer is edited. |
|
Get a live ref at the cursor, or move the cursor to a ref. |
|
Get or set the selection range as a pair of live refs. |
|
Create a named style tag. |
|
Remove a tag definition. |
|
Apply a tag to a range. |
|
Remove a tag from a range. |
|
Return tag names active at the position of ref. |
|
Return tag names active anywhere in the range. |
|
True if any interval of name is currently applied anywhere in the buffer. Cheap (scans the tag-interval list, not the buffer text). |
|
Create a live |
|
Stop tracking ref. |
|
Like |
|
Return the ref bound to name, or |
|
Drop the binding for name and invalidate the ref. No-op if name is not bound. |
|
Fresh refs at the start / end of the buffer. |
|
Returns |
|
Fresh refs at the start / end of line lineno. |
|
Undo or redo. |
|
Check undo/redo availability. |
|
Find next match; returns |
|
Find all non-overlapping matches; returns an array of ref pairs. |
|
Find and replace; returns the number of replacements. |
|
Scroll the view so the line containing ref is visible. |
|
Scroll to cursor position. |
Callbacks:
changed– text content changed.cursor_moved– cursor position changed; fires with a freshTextBufferRefat the new cursor position.line_clicked– a line number was clicked; fires with the line index.icon_clicked– a gutter icon was clicked; fires with(line, ref), whererefis the registered ref that owns the icon (ornullif the click was on a line with no icon).
let editor = new Widgets.TextSource("", {
line_numbers: true,
editable: true,
font_family: "monospace",
font_size: 14
});
editor.create_tag("keyword", {color: "blue", fontWeight: "bold"});
editor.add_callback('changed', (w) => console.log("Modified"));
TextBufferRef¶
A live reference to a position in a TextSource buffer.
Created via editor.create_ref(offset, gravity). As the buffer
is edited the ref’s offset auto-tracks insertions and deletions, so
a ref keeps pointing at the same logical position even when text
shifts before it.
Gravity controls behaviour when text is inserted exactly at the ref’s position:
'right'(default) – the ref moves with the inserted text and ends up after it.'left'– the ref stays before the inserted text.
If a delete range covers the ref’s position, the ref snaps to the start of the deleted range.
Lifecycle. Anonymous refs created via create_ref are tracked
weakly by the buffer — once you drop your last reference they
become eligible for garbage collection without an explicit
remove_ref(ref) call. Refs anchored by the buffer (named refs
from create_named_ref, icon refs registered via set_icon(ref,
url)) are held strongly and live until you explicitly drop the
binding (remove_named_ref(name), set_icon(ref, null)) or
until set_text invalidates everything.
Inspection:
Method |
Description |
|---|---|
|
Return the current character offset. |
|
Return |
|
Whether the ref is still tracked (false after
|
|
Return the 0-based line number this ref is on. |
|
Return |
Mutation – absolute position:
Method |
Description |
|---|---|
|
Move to offset; clamped to |
|
Move to the start of line lineno; clamped to the last line. |
|
Move to the same offset as other (must belong to the same buffer). |
|
Return a new live ref at the same offset and gravity. |
Mutation – relative movement:
Method |
Description |
|---|---|
|
Move to the start / end of the current line. |
|
Move to the start of the adjacent line; no-op at the buffer boundaries. |
|
Move forward / backward one character; clamped at the buffer boundaries. |
If the ref carries an icon (registered via editor.set_icon(ref,
url)), moving the ref re-renders the icon gutter so the icon
follows.
Mutating methods on an invalidated ref throw. Inspection methods on an invalidated ref still return the last known state.
let ref = editor.create_ref(0);
ref.set_line(10); // jump to line 10
ref.to_line_end(); // end of line 10
let endOfLine10 = ref.copy();
ref.to_next_line(); // start of line 11
editor.apply_tag("hilite", ref, endOfLine10); // wrong order:
// apply_tag swaps internally if start > end.