Skip to content
CShift0.45

Ui

Struct · namespace System.Ui · Since 0.32

struct Ui : IWindowFrame

The user interface: one value for the whole program, created once and given every frame to the code that draws it. Copies share the same state (it is held by reference), so a Ui can be passed to functions by value.

A frame is Ui.Begin, the widgets and groups, then Ui.End (or Window.Show, which calls it). Widgets are laid out from top to bottom; Ui.Row puts them side by side, Ui.Columns into a grid. Every widget has an id, made from its label and the groups around it: two widgets with the same label in the same group need different ids, either with ## (only what is before it is shown: "Delete##3") or with using (ui.Id(i)).

Name Description
Create A new Ui with the light theme.
static Ui Create()

A new Ui with the light theme.

Name Description
Begin Starts a frame for a window: its input, size and scale (and with commands if the window draws them itself).
BeginCommands Starts a frame that is not drawn into an image but recorded as commands (Ui.Commands), for a renderer of your own; font gives the sizes of the text (see Font.Metrics).
Commands The drawing commands of the last frame begun with Ui.BeginCommands (the list is used again by the next one).
CommandsHash A hash of Ui.Commands: frames that draw the same have the same hash, so a renderer can skip a frame whose hash is the one of the frame it shows (the mouse moved over nothing) without comparing the commands.
End Ends the frame and gives the image it drew (the same image every frame, as long as the size stays).
Frame The image of the last frame.
ShowIn Ends the frame and shows it in window; window.Show(ui) calls it.
Cursor The mouse pointer that the last frame asks for.
WaitMilliseconds How long the program may wait for input before it draws the next frame: 0 if the layout is not settled yet (a panel changed its size), the time until the text cursor blinks, or -1 (no limit).
RequestFrame Asks for the next frame after milliseconds at the latest, even if there is no input (an animation): the next Window.Update after Window.Show of this frame waits at most that long.
SetTheme Uses other colors from the next widget on.
GetTheme The colors in use.
Scale The scale of the current frame (1 = 96 dpi).
Font The font of the current frame.
Input The input of the current frame.
Canvas The canvas that the current frame draws on, for drawing of your own (see Ui.Area); with commands (Ui.BeginCommands) it draws into an empty image.
Area Takes a rectangle of the layout for drawing of your own: width (0: as wide as there is room) x height (0: down to the bottom of the window) pixels at scale 1.
Hovered True if the widget (or Ui.Area) placed last is under the mouse.
Clicked True in the frame in which the widget placed last was clicked with the left button.
RightClicked True in the frame in which the widget placed last was clicked with the right button (pressed and released on it): the secondary action, or Ui.OpenPopup for a context menu.
Held True while the left button that went down on the widget placed last is held (dragging, painting into an area), also in the frame in which it went down and up again (a quick click on a slow frame) and in the frame of its release.
RightHeld True while the right button that went down on the widget placed last is held (as Ui.Held).
SetCursor The mouse pointer for this frame, whatever the widgets under it ask for (call it after the Ui.Area it is for, while that is hovered: if (ui.Hovered()) ui.SetCursor(Cursor.Crosshair);).
FillRect Fills a rectangle (pixels of the frame).
DrawText Draws text with its top left corner at (x, y) in the font of the Ui (in the layer that is being drawn).
DrawImage Draws an image with its top left corner at (x, y) (in the layer that is being drawn).
Row The widgets in the block go side by side, each as wide as it needs (text boxes, sliders and the like take the rest of the line).
Column The widgets in the block go below each other (inside a Ui.Row: a column in it).
Columns The widgets in the block go into a grid of count columns of equal width, row by row.
Panel A framed group with a title (empty: none); the widgets in the block go below each other.
Scroll An area of the given height (pixels at scale 1; 0: down to the bottom of the window) whose content scrolls: with the mouse wheel and a scroll bar.
ScrollArea An area of width x height (pixels at scale 1; 0: the room there is, down to the bottom of the window) whose content scrolls both ways: content wider than it (an Ui.Area of a fixed size, a long row) gets a horizontal scroll bar.
ScrollX How far the scroll area with this id (in this group) is scrolled to the right, in pixels of the frame.
ScrollY How far the scroll area with this id is scrolled down, in pixels of the frame.
SetScroll Scrolls the area with this id from the next frame on (pixels of the frame; it keeps to the content).
Id Makes the ids of the widgets in the block different from those of the same widgets elsewhere (lists).
OpenPopup Opens the popup with this id at the mouse (a context menu: if (ui.RightClicked()) ui.OpenPopup("tile");).
IsPopupOpen True if the popup with this id is open.
Popup The content of the popup with this id: while it is open, the widgets in the block are drawn in a frame over the rest (where Ui.OpenPopup put it); while it is closed they draw nothing and do nothing.
MenuItem An item of a popup or menu; true in the frame in which it was chosen, which closes the popups.
CloseCurrentPopup Closes the popup that is being drawn (and the ones opened from it).
Modal A dialog in the middle of the window, with a title, over the dimmed rest of the window, which gets no input while it is shown.
MenuBar A bar of menus across the frame: `using (ui.MenuBar()) { using (ui.Menu(“File”)) { …
Menu A menu of a Ui.MenuBar: its title in the bar, and while it is open (a click on the title) the widgets in the block in a popup below it (Ui.MenuItem).
Tooltip Shows a text next to the mouse while it rests on the widget placed last (after half a second).
FileDialog A modal dialog for choosing a file, made of widgets (not the dialog of the system): the folder as a text box with “Up”, its folders and files (Directory.GetEntries), the name of the file, OK and Cancel.
FileDialogPaths The files chosen with the dialog id when it last returned UiDialogResult.Ok (several with FileDialogMode.OpenMany, else one; empty before).
Label Text in one line.
Note Text in the muted color of the theme.
Text Text that is wrapped at the width of the layout (also at line ends).
Button A button; true in the frame in which it was clicked (also with Enter or Space when it has the focus).
Checkbox A check box; true in the frame in which the user changed value.
Radio One of a group of options: value becomes option when it is chosen; true in that frame.
Slider A slider from min to max; true in the frames in which the user changed value.
TextBox A line of editable text; true in the frames in which the user changed text.
Submitted True in the frame in which Enter was pressed in the text box with this id.
ProgressBar A bar that is filled from 0.0 to 1.0.
ListItem A line of a list that can be selected; true in the frame in which it was clicked.
TreeNode A node of a tree: an arrow that opens and closes it, and a label that can be selected.
TreeLeaf A leaf of a tree: a line of a list whose label lines up with the labels of the nodes next to it; true in the frame in which it was clicked.
SetTreeOpen Opens or closes the tree node with this label (from this frame on, if it comes after this).
Indent The widgets of the block are moved to the right by one step of a tree (16 pixels at scale 1), in a column: `using (ui.Indent()) { …
Splitter A bar that the mouse drags to change size (pixels at scale 1, kept from min to max).
TabBar A row of tabs (Ui.Tab) with a line under it: `using (ui.TabBar()) { ui.Tab(“Map”, ref tab, 0); …
Tab A tab of a Ui.TabBar: it is shown as chosen when selected == index, and a click (Enter or Space) sets selected to index; true in that frame.
ComboBox A drop-down list: shows the item selected (an index into items), and a click opens the list over the other widgets (it scrolls if it is long).
IntBox A text box for a whole number from min to max: it takes digits and -, Up and Down add or subtract 1, and the number is kept in the range.
Image An image, in its own size.
Separator A horizontal line.
Space Empty space of the given size (pixels at scale 1): down in a column, to the right in a row.
LastRect The rectangle of the widget (or group) that was placed last, in pixels of the frame.
IsHovered True if the widget with this id (a label with its ## part) is under the mouse in this frame - for widgets that come before; it is known once they are drawn.
HasFocus True if the widget with this id has the keyboard focus.
SetFocus Gives the keyboard focus to the widget with this id from the next frame on (0 ids: none).
void Begin(Window window)

Starts a frame for a window: its input, size and scale (and with commands if the window draws them itself).

void Begin(Window window, double zoom)

The same with the scale of the window multiplied by zoom (1.25: everything a quarter larger). For a window, use this rather than Ui.Begin with the window’s input and size: that one always draws pixels, which a window that draws commands (AmigaOS) does not show.

void Begin(Input input, int width, int height, double scale)

Starts a frame of the given size in pixels; scale is 1 at 96 dpi.

void BeginCommands(Input input, int width, int height, double scale, Font font)

Starts a frame that is not drawn into an image but recorded as commands (Ui.Commands), for a renderer of your own; font gives the sizes of the text (see Font.Metrics).

List<UiCommand> Commands()

The drawing commands of the last frame begun with Ui.BeginCommands (the list is used again by the next one).

uint32 CommandsHash()

A hash of Ui.Commands: frames that draw the same have the same hash, so a renderer can skip a frame whose hash is the one of the frame it shows (the mouse moved over nothing) without comparing the commands.

Since 0.33

Image End()

Ends the frame and gives the image it drew (the same image every frame, as long as the size stays).

Image Frame()

The image of the last frame.

void ShowIn(ref Window window)

Ends the frame and shows it in window; window.Show(ui) calls it. The next Window.Update waits for input as long as the frame allows (Ui.WaitMilliseconds).

Since 0.45

Cursor Cursor()

The mouse pointer that the last frame asks for.

int WaitMilliseconds()

How long the program may wait for input before it draws the next frame: 0 if the layout is not settled yet (a panel changed its size), the time until the text cursor blinks, or -1 (no limit).

void RequestFrame(int milliseconds)

Asks for the next frame after milliseconds at the latest, even if there is no input (an animation): the next Window.Update after Window.Show of this frame waits at most that long. Only for the current frame, so a program that animates calls it every frame; with several calls the shortest wins, and so does a shorter wait that the Ui needs itself (see Ui.WaitMilliseconds). 0: the next frame at once.

if (animating)
ui.RequestFrame(166); // the next tile of the animation

Since 0.35

void SetTheme(Theme theme)

Uses other colors from the next widget on.

Theme GetTheme()

The colors in use.

double Scale()

The scale of the current frame (1 = 96 dpi).

Font Font()

The font of the current frame.

Input Input()

The input of the current frame.

Canvas Canvas()

The canvas that the current frame draws on, for drawing of your own (see Ui.Area); with commands (Ui.BeginCommands) it draws into an empty image.

Rect Area(int width, int height)

Takes a rectangle of the layout for drawing of your own: width (0: as wide as there is room) x height (0: down to the bottom of the window) pixels at scale 1. Returns it in pixels of the frame. It takes the mouse like a widget: Ui.Hovered, Ui.Held, Ui.Clicked and Ui.RightClicked tell what the mouse does with it.

Rect Area(string id, int width, int height)

The same with an id of its own (areas that are not always drawn, or in a different order).

Since 0.34

bool Hovered()

True if the widget (or Ui.Area) placed last is under the mouse.

Since 0.34

bool Clicked()

True in the frame in which the widget placed last was clicked with the left button.

Since 0.34

bool RightClicked()

True in the frame in which the widget placed last was clicked with the right button (pressed and released on it): the secondary action, or Ui.OpenPopup for a context menu.

Since 0.34

bool Held()

True while the left button that went down on the widget placed last is held (dragging, painting into an area), also in the frame in which it went down and up again (a quick click on a slow frame) and in the frame of its release.

Since 0.34

bool RightHeld()

True while the right button that went down on the widget placed last is held (as Ui.Held).

Since 0.34

void SetCursor(Cursor cursor)

The mouse pointer for this frame, whatever the widgets under it ask for (call it after the Ui.Area it is for, while that is hovered: if (ui.Hovered()) ui.SetCursor(Cursor.Crosshair);).

Since 0.34

void FillRect(Rect rect, Color color)

Fills a rectangle (pixels of the frame). Unlike Ui.Canvas, this draws in the layer that is being drawn: inside a Ui.Popup or Ui.Modal on top of the frame, and as commands with Ui.BeginCommands.

Since 0.34

void DrawText(int x, int y, string text, Color color)

Draws text with its top left corner at (x, y) in the font of the Ui (in the layer that is being drawn).

Since 0.34

void DrawImage(Image image, int x, int y)

Draws an image with its top left corner at (x, y) (in the layer that is being drawn).

Since 0.34

void DrawImage(Image image, Rect source, Rect target)

Draws the part source of an image scaled to target (nearest neighbour), in the layer that is being drawn.

Since 0.34

UiScope Row()

The widgets in the block go side by side, each as wide as it needs (text boxes, sliders and the like take the rest of the line).

UiScope Column()

The widgets in the block go below each other (inside a Ui.Row: a column in it).

UiScope Column(int width)

Inside a Ui.Row: a column of a fixed width (pixels at scale 1), or with 0 one that takes the rest of the row (several share it equally). A side bar next to a view: using (ui.Row()) { using (ui.Column(220)) { ... } using (ui.Column(0)) { ... } }.

Since 0.34

UiScope Columns(int count)

The widgets in the block go into a grid of count columns of equal width, row by row.

UiScope Panel(string title)

A framed group with a title (empty: none); the widgets in the block go below each other.

UiScope Scroll(string id, int height)

An area of the given height (pixels at scale 1; 0: down to the bottom of the window) whose content scrolls: with the mouse wheel and a scroll bar.

UiScope ScrollArea(string id, int width, int height)

An area of width x height (pixels at scale 1; 0: the room there is, down to the bottom of the window) whose content scrolls both ways: content wider than it (an Ui.Area of a fixed size, a long row) gets a horizontal scroll bar. The wheel scrolls up and down, Shift with the wheel (and the horizontal wheel) to the sides.

Since 0.34

int ScrollX(string id)

How far the scroll area with this id (in this group) is scrolled to the right, in pixels of the frame.

Since 0.34

int ScrollY(string id)

How far the scroll area with this id is scrolled down, in pixels of the frame.

Since 0.34

void SetScroll(string id, int x, int y)

Scrolls the area with this id from the next frame on (pixels of the frame; it keeps to the content).

Since 0.34

UiScope Id(int value)

Makes the ids of the widgets in the block different from those of the same widgets elsewhere (lists).

UiScope Id(string value)

The same with a text.

void OpenPopup(string id)

Opens the popup with this id at the mouse (a context menu: if (ui.RightClicked()) ui.OpenPopup("tile");). It stays open until an item is chosen (Ui.MenuItem), Ui.CloseCurrentPopup, Escape, or a click outside. The id of a popup is the same in every group of the frame: it can be opened inside a scroll area or a row and drawn somewhere else.

Since 0.34

bool IsPopupOpen(string id)

True if the popup with this id is open.

Since 0.34

UiScope Popup(string id)

The content of the popup with this id: while it is open, the widgets in the block are drawn in a frame over the rest (where Ui.OpenPopup put it); while it is closed they draw nothing and do nothing.

Since 0.34

bool MenuItem(string label)

An item of a popup or menu; true in the frame in which it was chosen, which closes the popups.

Since 0.34

bool MenuItem(string label, string shortcut)

The same with the text of a shortcut on the right (“Ctrl+S”); it is only shown, the program handles the keys.

Since 0.34

void CloseCurrentPopup()

Closes the popup that is being drawn (and the ones opened from it).

Since 0.34

UiScope Modal(string id, string title)

A dialog in the middle of the window, with a title, over the dimmed rest of the window, which gets no input while it is shown. It is shown as long as the program draws it: if (app.Asking) using (ui.Modal("ask", "Unsaved changes")) { ... if (ui.Button("Cancel")) app.Asking = false; }.

Since 0.34

UiScope MenuBar()

A bar of menus across the frame: using (ui.MenuBar()) { using (ui.Menu("File")) { ... } }.

Since 0.34

UiScope Menu(string label)

A menu of a Ui.MenuBar: its title in the bar, and while it is open (a click on the title) the widgets in the block in a popup below it (Ui.MenuItem).

Since 0.34

void Tooltip(string text)

Shows a text next to the mouse while it rests on the widget placed last (after half a second).

Since 0.34

UiDialogResult FileDialog(string id, string title, ref string path)

A modal dialog for choosing a file, made of widgets (not the dialog of the system): the folder as a text box with “Up”, its folders and files (Directory.GetEntries), the name of the file, OK and Cancel. It starts in the folder of path and shows it as long as the program draws it; path becomes the chosen file when it returns UiDialogResult.Ok: if (app.Opening) { var r = ui.FileDialog("open", "Open map", ref app.Path); if (r != UiDialogResult.None) app.Opening = false; }.

Since 0.34

UiDialogResult FileDialog(string id, string title, ref string path, FileDialogMode mode)

The same for a mode: FileDialogMode.Open (as above), FileDialogMode.OpenMany (several files: click them, Ui.FileDialogPaths has them after OK), FileDialogMode.Save (asks before replacing a file) or FileDialogMode.Folder (only folders; OK chooses the folder shown).

In the browser (--backend wasm) the user’s files are not in the file system of the page, so the dialog works with the browser: to open, it shows a button that opens the browser’s file chooser; the chosen files (or the folder with all its files) are copied into /home/web_user/files/, and path is the first of them (the folder). To save, it asks only for a name and gives /home/web_user/downloads/<name>: when the program has written that file and waits for input again, the page offers it as a download. “Files of the page” shows the dialog of widgets for the files of the page itself.

Since 0.37

List<string> FileDialogPaths(string id)

The files chosen with the dialog id when it last returned UiDialogResult.Ok (several with FileDialogMode.OpenMany, else one; empty before).

Since 0.37

void Label(string text)

Text in one line.

void Note(string text)

Text in the muted color of the theme.

void Text(string text)

Text that is wrapped at the width of the layout (also at line ends).

bool Button(string label)

A button; true in the frame in which it was clicked (also with Enter or Space when it has the focus).

bool Checkbox(string label, ref bool value)

A check box; true in the frame in which the user changed value.

bool Radio(string label, ref int value, int option)

One of a group of options: value becomes option when it is chosen; true in that frame.

bool Slider(string id, ref double value, double min, double max)

A slider from min to max; true in the frames in which the user changed value. With the keyboard: the arrow keys move it by 1/100 of the range.

bool Slider(string id, ref int value, int min, int max)

A slider for whole numbers.

bool TextBox(string id, ref string text)

A line of editable text; true in the frames in which the user changed text. Keys: the arrows, Home, End, Backspace, Delete, with Shift to select; Ctrl+A, Ctrl+C, Ctrl+X, Ctrl+V; Escape ends the editing.

bool Submitted(string id)

True in the frame in which Enter was pressed in the text box with this id.

void ProgressBar(double fraction)

A bar that is filled from 0.0 to 1.0.

bool ListItem(string label, bool selected)

A line of a list that can be selected; true in the frame in which it was clicked.

UiTreeNode TreeNode(string label, bool selected)

A node of a tree: an arrow that opens and closes it, and a label that can be selected. The Ui keeps whether it is open (closed at first, see Ui.SetTreeOpen); a click on the arrow, Right and Left (with the focus) open and close it, a click on the label, Enter or Space select it. Draw its children when it is open: if (ui.TreeNode("Maps", sel == 0).Open) using (ui.Indent()) { ... }.

Since 0.42

bool TreeLeaf(string label, bool selected)

A leaf of a tree: a line of a list whose label lines up with the labels of the nodes next to it; true in the frame in which it was clicked.

Since 0.42

void SetTreeOpen(string label, bool open)

Opens or closes the tree node with this label (from this frame on, if it comes after this). Call it in the group in which the node is drawn: its id comes from the label and the groups around it (see Ui.Id).

Since 0.42

UiScope Indent()

The widgets of the block are moved to the right by one step of a tree (16 pixels at scale 1), in a column: using (ui.Indent()) { ... }.

Since 0.42

bool Splitter(string id, ref int size, int min, int max)

A bar that the mouse drags to change size (pixels at scale 1, kept from min to max). In a row it stands between two columns, as high as the row so far, and changes a width: using (ui.Column(left)) {...} ui.Splitter("left", ref left, 100, 400); using (ui.Column()) {...}. In a column it lies under a widget and changes a height (of a Ui.Scroll above it, say). With the focus the arrow keys move it by 8. True in the frames in which size changed (the Ui then draws another frame at once, so the widgets before it get the new size).

Since 0.42

UiScope TabBar()

A row of tabs (Ui.Tab) with a line under it: using (ui.TabBar()) { ui.Tab("Map", ref tab, 0); ... }; then draw the page of tab.

Since 0.42

bool Tab(string label, ref int selected, int index)

A tab of a Ui.TabBar: it is shown as chosen when selected == index, and a click (Enter or Space) sets selected to index; true in that frame.

Since 0.42

bool ComboBox(string id, ref int selected, List<string> items)

A drop-down list: shows the item selected (an index into items), and a click opens the list over the other widgets (it scrolls if it is long). Choosing an item sets selected and closes it, Escape or a click outside closes it too. With the focus: Up and Down choose the previous or next item, Enter or Space open the list (in it Up, Down and Enter). True in the frame in which selected changed.

Since 0.34

bool IntBox(string id, ref int value, int min, int max)

A text box for a whole number from min to max: it takes digits and -, Up and Down add or subtract 1, and the number is kept in the range. True in the frame in which value changed.

Since 0.34

void Image(Image image)

An image, in its own size.

void Separator()

A horizontal line.

void Space(int size)

Empty space of the given size (pixels at scale 1): down in a column, to the right in a row.

Rect LastRect()

The rectangle of the widget (or group) that was placed last, in pixels of the frame.

bool IsHovered(string id)

True if the widget with this id (a label with its ## part) is under the mouse in this frame - for widgets that come before; it is known once they are drawn.

bool HasFocus(string id)

True if the widget with this id has the keyboard focus.

void SetFocus(string id)

Gives the keyboard focus to the widget with this id from the next frame on (0 ids: none).