first iteration of main.zig
This commit is contained in:
parent
4ee7afe1fe
commit
7e3c4d43c7
3 changed files with 48 additions and 2 deletions
|
@ -37,8 +37,9 @@ pub fn build(b: *Builder) void {
|
|||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
const exe = b.addExecutable("microui-demo", null);
|
||||
const exe = b.addExecutable("microui-demo", "src/main.zig");
|
||||
exe.linkLibC();
|
||||
exe.addIncludeDir("./src");
|
||||
exe.addIncludeDir("./microui-src");
|
||||
for (source_files) |source| {
|
||||
exe.addCSourceFile(source, &c_args);
|
||||
|
|
|
@ -232,7 +232,7 @@ static int text_height(mu_Font font) {
|
|||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main_old(int argc, char **argv) {
|
||||
/* init SDL and renderer */
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
r_init();
|
||||
|
|
45
src/main.zig
Normal file
45
src/main.zig
Normal file
|
@ -0,0 +1,45 @@
|
|||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue