Module gui::gui_app
GUI: the application object.
A GuiApp owns any number of windows and runs them from one event loop: it pumps the platform's events, routes each to the window it belongs to (to that window's widget tree and/or your event callback), fires timers and per-frame animation callbacks, repaints the windows that changed and presents them, and closes a window when its close button is clicked (unless the GUI_EVENT_CLOSE is prevent_default()ed).
struct GuiApp app = GuiApp::new();
?&GuiWindow ow = app.open_window("Hello", 480, 320);
match (ow) {
case some(win): { app.set_root(win, build_ui()); }
case null: { return 1; } // no display
}
int code = app.run(); // until the last window closes or quit()
app.free();
Driving the loop yourself (a game loop, an embedding host, or a WebAssembly page that can't block): call app.pump(0) once per frame — it does one iteration without waiting and returns 0 once the app should stop. app.pump(timeoutMs) with a positive timeout waits up to that long for the next event, timer or frame.
Rendering: a window with a widget root is laid out and painted by its GuiUi; a window with an on_draw callback gets a GuiCanvas over its buffer (after the widgets, if it has both); a window with neither shows whatever you put in win.pixels yourself. Windows are repainted only when something changed: an input event, a resize, a timer or animation callback, or app.redraw(win). on_frame callbacks run once per frame (frame_interval(), 60 Hz by default) while they return 1, with the frame time in milliseconds — the animation API.
Timers: set_timeout(ms, cb, data) runs cb once, set_interval(ms, ...) every ms until cancel_timer(id) (ids are never 0). They run on the loop (never concurrently with event handling), as close to their due time as the loop allows.
Structs
| GuiAppWindow | One window and what the app does with it (internal; see the methods). |
| GuiTimer | |
| GuiApp |