A first app
The fastest way in is level zero. Hand isolen_run a view callback and a title, then declare the tree inside the callback. The engine owns the loop, the window and the frame.
Before you start
Clone isolenui with --recursive so its engines come with it, as shown in project layout. Every header below is included with the isolenui/ prefix.
The whole program
isolen_app_defaults fills in a working isolen_app_desc: an automatic backend, vsync on, our own title bar and the bundled Objectivity atlas. A first app usually only overrides title, the size and view.
#include "isolenui/app/app.h"
#include "isolenui/kit/kit.h"
// level zero never touches a window or a frame, it only gets a view callback
// the engine runs whenever something on screen could have changed
static void draw(isolen_frame* f, void* user)
{
(void)user;
ui::ctx* u = f->ui;
// the shell body is already a ui::view, so this column scrolls with it
// once the window is too short for it
ui_box(u, ui::col().pad(24.0f).gap(12.0f))
{
ui::text(u, "isolen ui", ui::head(u));
ui::text(u, "a presentation engine's element and layout api",
ui::body(u));
if (ui::button(u, "quit")) {
isolen_quit(f->app);
}
}
}
int main(int argc, char** argv)
{
isolen_app_desc d = isolen_app_defaults();
d.title = "isolen ui demo";
d.width = 1280;
d.height = 720;
d.view = draw;
return isolen_run(&d, argc, argv);
}What happens each frame
- The shell opens a root box the size of the window, draws the title bar and opens a scrolling body for you.
- Your view declares its boxes and widgets into that body.
ui_boxopens a box and closes it at the end of the braces. - The solver sizes the tree and the device paints it. Your callback never sees a rectangle.
Because the body is a ui::view(), a page taller than the window scrolls on its own. Nothing else in the tree scrolls unless you ask it to. Overflow and views explains why.
Next
Widgets and state wires widgets to your own data. The app shell covers every field of the description, and flexbox covers the layout under every box.