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 pooled rows. Nothing here draws; a UI is widget nodes in a scene.
37 functions, 63 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 |
|---|---|---|
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. |
fill_slot(Node, int, ui::Control?) -> bool |
— | One child of host, the one at slot, filled as fill_strip fills each, made with any before it that are missing, or hidden for nil. The others are left as they are, so a list of hundreds of rows writes the few on screen and, as they scroll, the ones entering. True when the control's table differed from the last one written to it. |
fill_strip(string, [ui::Control]) -> bool |
— | Put one widget node per control table under the node at host, made, reused and hidden as the list changes; a node is written only when its table changed. A control's on_click or on_change hears the reader's edit and on_submit hears Enter as they happen: the name of a method, called on the nearest node above the control whose script has it with the control's data, then the edit, then the control's node. So a strip that did not change need not be filled again, and a control carrying controls is a row holding them. True when a control's table differed from the last one written to it. |
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. |
height_class() -> string |
— | How much height this screen has, as ui::SHORT or ui::TALL. |
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_control(Node, [int], ui::Control) -> bool |
— | What patch names written to the pooled control at at, child indices down from host, and remembered, so the next fill compares against it. For a value that follows the node: what the patch leaves out is not asked about, and a handler's name is a fill's to give. False where no control is there or 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. |
set_widget_layer(bool, Vec2?, Vec2?) |
— | Turn drawing of the scene's widget nodes on or off, and confine it to the rect at position of size, in design pixels; the whole window when either is left out. |
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. |
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_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_WINDOW |
"window" |
WIDTH_MEDIUM |
"medium" |
WIDTH_NARROW |
"narrow" |
WIDTH_WIDE |
"wide" |