const std = @import("std"); const builtin = @import("builtin"); const dvui = @import("dvui"); const SDLBackend = @import("sdl-backend"); pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); var backend = try SDLBackend.initWindow(.{ .allocator = allocator, .size = .{ .w = 800.0, .h = 600.0 }, .title = "My DVUI App", .vsync = true, }); defer backend.deinit(); var win = try dvui.Window.init(@src(), allocator, backend.backend(), .{ .theme = switch (backend.preferredColorScheme() orelse .light) { .light => dvui.Theme.builtin.adwaita_light, .dark => dvui.Theme.builtin.adwaita_dark, }, }); defer win.deinit(); var interrupted = false; main_loop: while (true) { // beginWait coordinates with waitTime below to run frames only when needed const nstime = win.beginWait(interrupted); // marks the beginning of a frame for dvui, can call dvui functions after this try win.begin(nstime); // send all SDL events to dvui for processing try backend.addAllEvents(&win); // if dvui widgets might not cover the whole window, then need to clear // the previous frame's render _ = SDLBackend.c.SDL_SetRenderDrawColor(backend.renderer, 0, 0, 0, 255); _ = SDLBackend.c.SDL_RenderClear(backend.renderer); const keep_running = gui_frame(); if (!keep_running) break :main_loop; // marks end of dvui frame, don't call dvui functions after this // - sends all dvui stuff to backend for rendering, must be called before renderPresent() const end_micros = try win.end(.{}); // cursor management try backend.setCursor(win.cursorRequested()); try backend.textInputRect(win.textInputRequested()); // render frame to OS try backend.renderPresent(); // waitTime and beginWait combine to achieve variable framerates const wait_event_micros = win.waitTime(end_micros); interrupted = try backend.waitEventTimeout(wait_event_micros); } } fn gui_frame() bool { return true; }