67 lines
2.2 KiB
Zig
67 lines
2.2 KiB
Zig
const std = @import("std");
|
|
const raylib = @import("raylib.zig");
|
|
const sqlite = @cImport({
|
|
@cInclude("sqlite3.h");
|
|
});
|
|
|
|
pub fn main() !void {
|
|
const alloc = std.heap.page_allocator;
|
|
|
|
const screen_width = 800;
|
|
const screen_height = 450;
|
|
raylib.InitWindow(screen_width, screen_height, "FabApp");
|
|
raylib.SetTargetFPS(60);
|
|
|
|
var file_dialog_state = raylib.InitGuiWindowFileDialog(raylib.GetWorkingDirectory());
|
|
// const ext = ".sqlite3";
|
|
// @memcpy(file_dialog_state.filterExt[0..ext.len], ext);
|
|
|
|
var db: *anyopaque = undefined;
|
|
|
|
while (!raylib.WindowShouldClose()) {
|
|
//
|
|
// Update
|
|
//
|
|
{
|
|
if (file_dialog_state.SelectFilePressed) {
|
|
const db_path = try std.fs.path.join(alloc, &[_][]const u8{ &file_dialog_state.dirPathText, &file_dialog_state.fileNameText });
|
|
defer alloc.free(db_path);
|
|
const rc = sqlite.sqlite3_open(@ptrCast(db_path), @alignCast(@ptrCast(db)));
|
|
if (rc != 0) {
|
|
std.debug.print("Can't open database: {s}", .{sqlite.sqlite3_errmsg(@ptrCast(db))});
|
|
_ = sqlite.sqlite3_close(@ptrCast(db));
|
|
}
|
|
}
|
|
file_dialog_state.SelectFilePressed = false;
|
|
}
|
|
|
|
//
|
|
// Render
|
|
//
|
|
{
|
|
raylib.BeginDrawing();
|
|
defer raylib.EndDrawing();
|
|
raylib.ClearBackground(raylib.RAYWHITE);
|
|
|
|
{
|
|
if (file_dialog_state.windowActive) raylib.GuiLock();
|
|
defer raylib.GuiUnlock();
|
|
|
|
const button_size = 200;
|
|
if (raylib.GuiButton(.{ .x = (screen_width - button_size) / 2, .y = (screen_height - button_size) / 2, .width = 200, .height = 200 }, "Load db file") == 1) {
|
|
file_dialog_state.windowActive = true;
|
|
}
|
|
}
|
|
|
|
raylib.GuiWindowFileDialog(&file_dialog_state);
|
|
}
|
|
}
|
|
raylib.CloseWindow();
|
|
}
|
|
|
|
test "simple test" {
|
|
var list = std.ArrayList(i32).init(std.testing.allocator);
|
|
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
|
|
try list.append(42);
|
|
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
|
}
|