goome

How the ui kit works

Immediate mode, like Dear ImGui but made for overlays first. You keep your own variables and call the widgets every frame.

the ui demo from c-goome on the test backend

The loop

goome_ui *u = goome_ui_new(g);
double x = 40, y = 40, w = 300, h = 0, volume = 0.5;
int muted = 0, running = 1;

while (running) {
    goome_event ev;
    while (goome_poll(g, &ev, 16) > 0) {
        if (ev.type == GOOME_QUIT) running = 0;
        goome_ui_feed(u, &ev);
    }
    if (!goome_ui_begin(u, 0)) continue;
    if (goome_ui_window(u, "Settings", &x, &y, &w, &h, GOOME_WIN_MOVE | GOOME_WIN_COLLAPSE, NULL)) {
        if (goome_ui_button(u, "Say hi")) puts("hi");
        goome_ui_slider(u, "Volume", &volume, 0, 1, "%.2f");
        goome_ui_toggle(u, "Muted", &muted);
    }
    goome_ui_window_end(u);
    goome_ui_end(u);
}
goome_ui_free(u);

Every frame:

  1. feed it every event with goome_ui_feed. It returns 1 when the UI used the event
  2. goome_ui_begin(u, mon) starts the frame on a monitor. NULL means skip this frame
  3. call your windows and widgets
  4. goome_ui_end(u) draws it all and sends it, with every window as a hit rect

Values

The slider doesnt own volume, you do. Change it anywhere and the slider shows it next frame. Same with window x, y, w, h, save them and pass them back next run to restore the layout.

Widgets that change something return 1 on the frame they changed it (C#, Rust, Go and Zig return true, Python and Node set ui.changed). Java, Python, Node and Lua widgets give back the new value instead, Java has ui.changed() and Lua gives back if it changed as a second value.

Ids

Widgets keep a bit of state (hover animation, scroll offset, text cursor) by id, and the id is the label. Same label in the same window = shared state.

Anything after ## is part of the id but not shown, so "Save##top" and "Save##bottom" are two buttons that both say Save. In a loop push something unique:

for (int i = 0; i < n; i++) {
    char id[16];
    snprintf(id, sizeof(id), "%d", i);
    goome_ui_push_id(u, id);
    if (goome_ui_button(u, "Delete")) remove_item(i);
    goome_ui_pop_id(u);
}

Drawing less

Only draw after an event or while goome_ui_animating(u) says somethings still moving (a hover fading in, a toggle sliding over, your own animations 0.5). See Frames, damage and pacing.

Widgets

#define GOOME_NO_UI before the implementation leaves the UI kit out.

Edit this page on GitHub