A lightweight C++23 UI library for Windows and Linux, using SDL2 as the renderer.
int quit(WidgetHandle, void *instance) {
if (instance != nullptr) {
auto *ctx = static_cast<Context *>(instance);
ctx->mRequestShutdown = true;
return ResultOk;
}
return ErrorCode;
}
int main(int argc, char *argv[]) {
if (Style style = TinyUi::getDefaultStyle(); !TinyUi::createContext("Sample-Screen", style)) {
return -1;
}
if (TinyUi::initScreen(20, 20, 1024, 768) == -1) {
const auto &ctx = TinyUi::getContext();
ctx.mLogger(LogSeverity::Error, "Cannot init screen");
return ErrorCode;
}
constexpr int32_t ButtonHeight = 18;
WidgetHandle rootPanel = Widgets::panel(WidgetHandle::getRootHandle(), "Sample-Dialog", Rect(90, 5, 220, 60), nullptr);
if (!panel.isValid()) {
const auto &ctx = TinyUi::getContext();
ctx.mLogger(LogSeverity::Error, "Cannot create panel");
return ErrorCode;
}
auto &ctx = TinyUi::getContext();
auto *dynamicQuitCallback = new CallbackI(quit, (void*) &ctx);
Widgets::label(rootPanel, "Hi, World!", Rect(100, 10, 200, ButtonHeight), Alignment::Center);
Widgets::textButton(rootPanel, "Quit", Rect(100, 30, 200, ButtonHeight), Alignment::Center, dynamicQuitCallback);
while (TinyUi::run()) {
TinyUi::render();
}
TinyUi::release();
return 0;
}