38 lines
878 B
Zig
38 lines
878 B
Zig
const std = @import("std");
|
|
const log = std.log.scoped(.imgui);
|
|
|
|
const ImGui = @This();
|
|
|
|
const Command = union(enum) {
|
|
text: [:0]const u8
|
|
};
|
|
|
|
arena_state: std.heap.ArenaAllocator,
|
|
commands: std.ArrayList(Command),
|
|
|
|
pub fn init(gpa: std.mem.Allocator) ImGui {
|
|
return ImGui{
|
|
.arena_state = .init(gpa),
|
|
.commands = .empty
|
|
};
|
|
}
|
|
|
|
pub fn deinit(self: *ImGui) void {
|
|
self.arena_state.deinit();
|
|
self.* = undefined;
|
|
}
|
|
|
|
pub fn text(self: *ImGui, comptime fmt: []const u8, args: anytype) void {
|
|
const arena = self.arena_state.allocator();
|
|
|
|
const formatted = std.fmt.allocPrintSentinel(arena, fmt, args, 0) catch |e| {
|
|
log.warn("formatting text failed: {}", .{e});
|
|
return;
|
|
};
|
|
|
|
self.commands.append(arena, .{ .text = formatted }) catch |e| {
|
|
log.warn("appending command failed: {}", .{e});
|
|
return;
|
|
};
|
|
}
|