zig-microui/src/main.zig

46 lines
1.0 KiB
Zig

const std = @import("std");
const c = @cImport({
@cInclude("SDL2/SDL.h");
@cInclude("microui.h");
@cInclude("renderer.h");
});
export fn text_width(font: c.mu_Font, text: [*c]const u8, len: c_int) c_int {
var actual_len: c_int = len;
if (actual_len == -1) {
actual_len = @intCast(c_int, std.mem.len(text));
}
return c.r_get_text_width(text, actual_len);
}
export fn text_height(font: c.mu_Font) c_int {
// TODO handle font data?
return c.r_get_text_height();
}
pub fn main() anyerror!void {
_ = c.SDL_Init(c.SDL_INIT_EVERYTHING);
c.r_init();
var ctx = try std.heap.c_allocator.create(c.mu_Context);
defer std.heap.c_allocator.destroy(ctx);
c.mu_init(ctx);
ctx.text_width = text_width;
ctx.text_height = text_height;
while (true) {
var e: c.SDL_Event = undefined;
while (c.SDL_PollEvent(&e) != 0) {
switch (e.@"type") {
c.SDL_QUIT => std.os.exit(0),
else => @panic("fuck"),
}
}
}
}