ui
What a script asks of the UI and tells it: where a widget node drew, focus, the screen's classes, the scale, the theme, the clipboard, when a pass runs…
What a script asks of the UI and tells it: where a widget node drew, focus, the screen's classes, the scale, the theme, the clipboard, when a pass runs and the control tables a form writes. Nothing here draws; a UI is widget nodes in a scene.
38 functions, 65 constants. Scripts reach it as ui::.
Functions
Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.
| function | acts on | what it does |
|---|---|---|
chord_text(string) -> string |
— | A chord as a widget's shortcut and [input.actions] spell it, cmd+shift+KeyS, in the spelling the platform shows: ⇧⌘S on a Mac, Ctrl+Shift+S elsewhere. What a row naming a command writes beside it. A chord no key reads is an error. |
clear_focus() |
— | Focus nothing, as a pad's back button leaves a menu; the widget focus leaves hears focus_exited. |
click(Node, ui::ClickOptions?) -> bool |
— | Click a widget node as the pointer would, at the next tick and with no window needed: what a test harness drives the game with. False for a node a pointer could not click, hidden, disabled or not a widget; { hidden: true } clicks a hidden one anyway, as a test emitting its signal would. |
colors_apart(any) -> [ui::ColorsApart] |
— | Every pair of a widget_theme document's colours that say something by hue (primary, success, warning, danger), closest first, as { first, second, distance, vision }: how far apart they stand in CIELAB for the colour vision that sees them closest. Under 10 the two read as one colour to that reader. |
complete_theme(any) -> any |
— | The theme document with every colour and size it leaves out derived from its sources, and dark stated. |
contrast(string, string) -> float |
— | The WCAG contrast ratio between two #rrggbb colours, 1 to 21. Body text wants 4.5, large or bold text 3. |
contrast_pairs(any, string) -> [ui::ContrastPair] |
— | Every ink a widget_theme document's roles draw on the fill each draws it on, as { role, ink, fill, ratio, need }. A role with no fill is read on the ground token; need is 3 for large or bold text and 4.5 otherwise. |
edit(Node, any) -> bool |
— | Change a widget's value as the reader would, at the next tick, so it announces value_changed: a number for a slider or a number field, text for a text field, a dropdown's pick, a list's row or a tab, a colour for a swatch, a boolean for a fold. False for a disabled widget or a value its kind does not take. |
finish_loading() |
— | Say the load is through, which lets a held splash go once splash_seconds has also passed. The editor calls it once its shell has settled. |
focus_down() |
— | The same downwards, by neighbour_down. |
focus_left() |
— | The same to the left, by neighbour_left. |
focus_next() |
— | Move focus to the next widget in scene order, wrapping past the last. |
focus_previous() |
— | Move focus to the previous widget in scene order, wrapping past the first. |
focus_right() |
— | The same to the right, by neighbour_right. |
focus_up() |
— | Move focus to the nearest widget above, as the up arrow does: the one the focused widget names in neighbour_up, else by where the widgets were drawn, round to the bottom past the top. What a stick or a d-pad's action calls. |
focused_widget() -> Node |
— | The widget node focus is on, or nil. |
glyph(string) -> string |
— | The character the icon font of the theme in force draws the glyph called name with, in the running project's own faces (the editor's, in the editor): for text that carries an icon among its words. Empty when the font has no glyph by that name. A widget's icon, a row's and a mark's take the name itself. |
height_class() -> string |
— | How much height this screen has, as ui::SHORT or ui::TALL. |
natural_size(Node) -> Vec2 |
— | The width and height a widget node asks for before its container grows or shrinks it, as CSS's max-content, in design pixels: its content and padding, or what it or its role states, a container's from its children's. What a row of words weighs against its room. Zero until it has been laid out once; a hidden one keeps what it asked for when last shown. |
pasted_text() -> string |
— | The text the last UI pass saw pasted, empty when it saw none: the platform clipboard is not readable on demand. The pasted event carries text no field took as it arrives. |
patch(Node, ui::Control) -> bool |
— | What patch names written onto a widget node and remembered, so the next write compares against it: for a value that follows the node, what it leaves out is not asked about. False where nothing moved. |
pixels_per_design() -> float |
— | How many of the window's own pixels a design pixel covers this frame: the UI scale, the display's scale and the reader's text size together. Divide input::mouse_position() by it for design pixels. |
request_repaint(ui::RepaintOptions?) |
— | Run the frame and its UI pass under [window] low_processor; call it every frame something on screen moves without input, such as while the scene plays. after seconds asks for one that far ahead instead. |
save_pasted_image(string) -> bool |
— | Write the image last pasted where no field took it, which the image_pasted event announced with its { width, height }, to path as a PNG. Answers false when there is none, or it was written already. |
scale() -> float |
— | The global UI scale: how many screen pixels a design pixel is drawn at, on top of the display's own. |
set_clipboard(string) |
— | Copy text to the system clipboard. The next UI pass hands it over, and asks for itself. |
set_focus(Node) |
— | Put focus on a widget node. A node focus cannot activate is refused at the next draw. |
set_load_progress(float, str?) |
— | Report how far a load is, zero to one. This is what holds [application] splash past its seconds, and what draws the bar under it. |
set_scale(float) |
— | Set the global UI scale, clamped to between 0.25 and 3.0. It is egui's zoom factor, so it grows every control and every font; screen_size already answers in the design pixels it leaves. |
set_theme(any) |
— | Put a theme in force over [ui] theme and theme_dark, for every widget and egui's own controls: a widget_theme file's path, or a theme document, with source colours under colors and sizes under sizes. What the document leaves out is derived from its sources. A root's own theme still dresses its subtree with that one, and nil goes back to the project's. |
tab_rect(Node) -> ui::Rect? |
— | Where a tabs page's own button in the strip was last drawn, as { x, y, width, height } in design pixels; empty before the strip has drawn. widget_rect on the same node answers with the page body. |
takes_pointer_at(Vec2) -> bool |
— | Whether the UI would take a press at this point, in design pixels, by the same layers as wants_pointer: what an editor asks of a point it is about to act on. |
wants_keyboard() -> bool |
— | Whether a UI widget held keyboard focus when the last pass ended, so the game should leave key presses alone. |
wants_pointer() -> bool |
— | Whether the UI has the pointer or finger, so the game should leave it alone: what stops a tap on a HUD button also firing the shot behind it. A press is routed once, from the top: an open dialog, then a popup or window, then a widget that is not interactive = false or a seam between boxes, and the world last; it keeps that answer until the button comes up. False without a window. |
widget_rect(Node) -> ui::Rect? |
— | Where a widget node was last drawn, as { x, y, width, height } in design pixels; empty until it has drawn once. |
width_class() -> string |
— | How much width this screen has, as ui::NARROW, ui::MEDIUM or ui::WIDE. Read every frame: a rotation changes it. A run with no window answers ui::WIDE. |
window_size() -> Vec2 |
— | The window's width and height, in design pixels; a headless run, and a script's init before the window opens, answer the [window] size the project states at the UI scale. |
write([Node], [ui::Control]) -> bool |
— | Write each control table onto the widget node in its place, the lists side by side and in one call however long: each key to the component that holds it, visible to the node, and only what moved since the last write, a key an earlier write named and this one leaves out put back to its shape's default. A control carrying controls is a row; its children are the caller's to write. What names who hears it, on_click, on_change, on_submit, target and data, is never written. True when an earlier write differed. |
Constants
| name | value |
|---|---|
ALIGN_BASELINE |
"baseline" |
ALIGN_CENTER |
"center" |
ALIGN_END |
"end" |
ALIGN_START |
"start" |
ALIGN_STRETCH |
"stretch" |
ANCHOR_BOTTOM_LEFT |
"bottom_left" |
ANCHOR_BOTTOM_RIGHT |
"bottom_right" |
ANCHOR_CENTER |
"center" |
ANCHOR_CENTER_BOTTOM |
"center_bottom" |
ANCHOR_CENTER_LEFT |
"center_left" |
ANCHOR_CENTER_RIGHT |
"center_right" |
ANCHOR_CENTER_TOP |
"center_top" |
ANCHOR_FILL |
"fill" |
ANCHOR_FILL_ACROSS |
"fill_across" |
ANCHOR_FILL_BOTTOM |
"fill_bottom" |
ANCHOR_FILL_DOWN |
"fill_down" |
ANCHOR_FILL_LEFT |
"fill_left" |
ANCHOR_FILL_RIGHT |
"fill_right" |
ANCHOR_FILL_TOP |
"fill_top" |
ANCHOR_TOP_LEFT |
"top_left" |
ANCHOR_TOP_RIGHT |
"top_right" |
FONT_STYLE_ITALIC |
"italic" |
FONT_STYLE_NORMAL |
"normal" |
FONT_STYLE_OBLIQUE |
"oblique" |
HEIGHT_SHORT |
"short" |
HEIGHT_TALL |
"tall" |
INPUT_POINTER |
"pointer" |
INPUT_TOUCH |
"touch" |
MODIFIER_ALT |
"alt" |
MODIFIER_CMD |
"cmd" |
MODIFIER_CTRL |
"ctrl" |
MODIFIER_SHIFT |
"shift" |
WIDGET_BUTTON |
"button" |
WIDGET_CHECKBOX |
"checkbox" |
WIDGET_CODE |
"code" |
WIDGET_COLOR_PICKER |
"color_picker" |
WIDGET_COLUMN |
"column" |
WIDGET_DIALOG |
"dialog" |
WIDGET_DROPDOWN |
"dropdown" |
WIDGET_FOLD |
"fold" |
WIDGET_GRID |
"grid" |
WIDGET_IMAGE |
"image" |
WIDGET_LABEL |
"label" |
WIDGET_LIST |
"list" |
WIDGET_MENU |
"menu" |
WIDGET_NUMBER_FIELD |
"number_field" |
WIDGET_PANEL |
"panel" |
WIDGET_PROGRESS_BAR |
"progress_bar" |
WIDGET_ROW |
"row" |
WIDGET_SCROLL |
"scroll" |
WIDGET_SEPARATOR |
"separator" |
WIDGET_SLIDER |
"slider" |
WIDGET_SPINNER |
"spinner" |
WIDGET_STACK |
"stack" |
WIDGET_SWITCH |
"switch" |
WIDGET_TABLE |
"table" |
WIDGET_TABS |
"tabs" |
WIDGET_TEXT_AREA |
"text_area" |
WIDGET_TEXT_FIELD |
"text_field" |
WIDGET_TREE |
"tree" |
WIDGET_VIEWPORT |
"viewport" |
WIDGET_WINDOW |
"window" |
WIDTH_MEDIUM |
"medium" |
WIDTH_NARROW |
"narrow" |
WIDTH_WIDE |
"wide" |