Level 1, your loop
isolen_open returns an isolen_app*. Each isolen_next_frame hands out an isolen_frame that is painted and presented when the next call is made or the app closes.
Reach for this level when the app has work that one callback cannot express, such as a worker thread, a socket or a state machine of its own. isolen_next_frame blocks while the app is idle. A thread that changes what is on screen calls isolen_wake to get a frame promptly. It returns false once the window closes or isolen_quit is called.
#include "isolenui/app/app.h"
#include <atomic>
#include <thread>
#include "isolenui/kit/kit.h"
// level one keeps its own loop, next_frame hands out the frame that is
// painted and presented when the following call is made or the app closes
int main(int argc, char** argv)
{
isolen_app_desc d = isolen_app_defaults();
d.title = "isolen ui, level one";
isolen_app* app = isolen_open(&d, argc, argv);
if (!app) {
return 1;
}
// a loader thread changes state the ui shows, isolen_wake makes the idle
// loop run a frame soon instead of waiting for the next input event
std::atomic<uint32_t> loaded{0};
std::thread loader([&] {
for (uint32_t i = 1; i <= 100; ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds(20));
loaded.store(i, std::memory_order_relaxed);
isolen_wake(app);
}
});
const char* const* files = nullptr;
const uint32_t file_count = isolen_args(app, &files);
isolen_frame f = {};
uint32_t frames = 0;
while (isolen_next_frame(app, &f)) {
ui::ctx* u = f.ui;
ui_box(u, ui::col().pad(24.0f).gap(8.0f))
{
ui::textf(u, ui::body(u), "frame %u, dt %.3f", frames, f.dt);
ui::textf(u, ui::caption(u), "%u files on the command line",
file_count);
ui::progress(u, float(loaded.load(std::memory_order_relaxed)) / 100.0f);
for (uint32_t i = 0; i < file_count; ++i) {
ui::key(u, uint64_t(i));
ui::text(u, files[i], ui::mono(u));
}
}
++frames;
}
loader.join();
isolen_close(app);
return 0;
}While the user resizes the window, or moves it on Windows, the system holds the thread and your loop stops. The engine keeps drawing through isolen_app_desc::view meanwhile, so set it to the same function your loop calls. See live resize.
Arguments
isolen_args returns the positional arguments the engine did not consume, such as files dragged onto the executable, and writes a pointer to them into out. The array lives as long as the app.