const std = @import("std"); const c = @import("c.zig"); pub fn main() !void { if (c.mgl_init() != 0) return error.MglInitFailed; defer c.mgl_deinit(); var window: c.mgl_window = undefined; if (c.mgl_window_create(&window, "mgl", &.{ .size = .{ .x = 1280, .y = 720 } }) != 0) return error.MglFailedToCreateWindow; defer c.mgl_window_deinit(&window); var font_file: c.mgl_memory_mapped_file = undefined; if (c.mgl_mapped_file_load("/usr/share/fonts/noto/NotoSans-Regular.ttf", &font_file, &.{ .readable = true, .writable = false }) != 0) return error.MglFailedToLoadFontFile; defer c.mgl_mapped_file_unload(&font_file); var font: c.mgl_font = undefined; if (c.mgl_font_load_from_file(&font, &font_file, 26) != 0) return error.MglFailedToLoadFont; defer c.mgl_font_unload(&font); var text: c.mgl_text = undefined; c.mgl_text_init(&text, &font, "hello world", 11); defer c.mgl_text_deinit(&text); var event: c.mgl_event = undefined; while (c.mgl_window_is_open(&window)) { while (c.mgl_window_poll_event(&window, &event)) { switch (event.type) { c.MGL_EVENT_TEXT_ENTERED => { const str = event.unnamed_0.text.str[0..@intCast(event.unnamed_0.text.size)]; std.debug.print("text event, codepoint: {any}, str: {s}\n", .{ event.unnamed_0.text.codepoint, str }); }, else => std.debug.print("unhandled event: {any}\n", .{ event.type }), } } c.mgl_window_clear(&window, c.mgl_color{ .r = 0, .g = 0, .b = 0, .a = 255}); c.mgl_text_draw(c.mgl_get_context(), &text); c.mgl_window_display(&window); } }