Skip to content
CShift0.32

Ui

Struct · namespace System.Ui · Since 0.32

struct Ui

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).
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.
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).
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 pixels at scale 1.
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) whose content scrolls: with the mouse wheel and a scroll bar.
Id Makes the ids of the widgets in the block different from those of the same widgets elsewhere (lists).
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.
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(UiInput input, int width, int height, double scale)

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

void BeginCommands(UiInput 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).

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.

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 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.

UiInput 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 pixels at scale 1. Returns it in pixels of the frame.

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 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) whose content scrolls: with the mouse wheel and a scroll bar.

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 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.

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).