System.Ui
User interfaces in immediate mode: the program describes its whole window again for every frame, from its own state, and a widget reports what the user did with it as its result. There are no widget objects, callbacks or events to unsubscribe, and the state stays in the program’s own structs.
using System.Ui;
struct App { int Count; string Name; bool Loud; }
void Draw(Ui ui, ref App app){ ui.Label($"Count: {app.Count}"); using (ui.Row()) { if (ui.Button("-")) app.Count -= 1; if (ui.Button("+")) app.Count += 1; } ui.TextBox("name", ref app.Name); ui.Checkbox("Loud", ref app.Loud);}
int Main(){ var window = try Window.Open("Counter", 320, 200); var ui = Ui.Create(); var app = App { Name = "World" }; while (window.Update()) { ui.Begin(window); Draw(ui, ref app); window.Show(ui); } return 0;}A Ui draws into an Image with the software renderer of Canvas, so it also works without a window (tests,
screenshots: Ui.Begin with a UiInput of your own). Sizes are in pixels at a scale of 1 (96 dpi); a Window
reports the scale of its screen, and the Ui picks a font and the sizes for it.
Drawing for System.Ui: Canvas draws rectangles, rounded rectangles, circles, lines, text and images into an
Image (with clipping, transparency and smooth edges); Font is a bitmap font for its text.
A window on the screen for System.Ui: it collects the input of the mouse and the keyboard for a frame and shows the image of a frame. Windows has it with Win32 (stdlib/os/windows/ui.cshift), Linux with X11 (stdlib/os/posix/ui.cshift, libX11 is loaded when the first window opens, so programs without windows do not need it), the browser with a <canvas> (stdlib/os/wasi/ui.cshift and web/cshift.js, –backend wasm), AmigaOS with Intuition and graphics.library (stdlib/amiga/ui.cshift: the frames are drawn from their commands).
| Type | Description |
|---|---|
UiInput |
What the user did since the last frame: the state of the mouse and the keys that were pressed. |
Theme |
The colors of a Ui: Theme.Light (the default) or Theme.Dark, or your own. |
UiScope |
The end of a group that Ui.Row, Ui.Columns, Ui.Panel, Ui.Scroll and Ui.Id started: `using (ui.Row()) { … |
UiCommand |
One drawing operation of a frame, recorded when a Ui draws with commands instead of pixels (Ui.BeginCommands, Ui.Commands): for windows that draw themselves (the one of AmigaOS draws with graphics.library). |
Ui |
The user interface: one value for the whole program, created once and given every frame to the code that draws it. |
Rect |
A rectangle in pixels: X and Y are its top left corner. |
Font |
A bitmap font: every character is a cell of the same size. |
Canvas |
Draws into an Image: everything is clipped to Clip, colors with an alpha below 255 are blended with what is already there, and the edges of rounded rectangles, circles and lines are smooth. |
Window |
A window that shows the frames of a Ui (or images of your own, for games). |
Clipboard |
The text of the system’s clipboard (Ui.TextBox uses it for Ctrl+C, Ctrl+X and Ctrl+V). |
Key |
The keys that UiInput.Keys reports. |
Cursor |
The shape of the mouse pointer that a frame asks for (see Ui.Cursor). |
UiCommandKind |
What a UiCommand draws. |
UiError |
The errors of opening a window. |