Backlog/projects/tools/newProjectMaker.zig

84 lines
2.0 KiB
Zig

pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "main");
allocator: std.mem.Allocator,
textBuffer: [8192]u8,
pub fn init(allocator: std.mem.Allocator) !*@This() {
const self = try allocator.create(@This());
self.* = .{
.allocator = allocator,
.textBuffer = std.mem.zeroes([8192]u8),
};
return self;
}
pub fn prepare(self: *@This()) !void {
_ = self;
core.engine_log("program ready", .{});
}
pub fn tick(self: *@This(), dt: f64) void {
_ = dt;
ig.setNextWindowPos(.{ .x = 200, .y = 200 }, .{}, .{});
if (ig.begin("New Project...", null, .{
.always_auto_resize = true,
.no_move = true,
.no_resize = true,
.no_collapse = true,
})) {
ig.setNextItemWidth(600);
if (ig.inputText(
"##Path",
&self.textBuffer,
self.textBuffer.len,
.{ .no_blank = true },
null,
null,
)) {
core.engine_log("huh", .{});
}
ig.sameLine(0, 3);
if (ig.button("...", .{})) {
core.engine_log("opening NFD", .{});
core.asyncOpenFolder(.{
.callback = onFolderSelected,
.callbackContext = self,
}) catch @panic(" unable to open dialog");
}
if (ig.button("Create", .{})) {
core.engine_log("creating project: ", .{});
}
}
ig.end();
}
pub fn onFolderSelected(
ctx: ?*anyopaque,
path: ?[]const u8,
) void {
const self: *@This() = @ptrCast(@alignCast(ctx));
if (path) |p| {
std.mem.copyForwards(u8, &self.textBuffer, p);
self.textBuffer[p.len] = 0;
}
}
pub fn deinit(self: *@This()) void {
self.allocator.destroy(self);
}
pub fn main() anyerror!void {
var spec = try api.getSpec("New Project Dialogue");
_ = api.startEngine(&NeonObjectTable, &spec);
}
const std = @import("std");
const api = @import("backlog");
const ig = api.imgui.api;
const core = api.core;