2023-10-04 14:20:49 +02:00
|
|
|
const std = @import("std");
|
2023-10-13 15:53:58 +02:00
|
|
|
const raylib = @import("raylib.zig");
|
2023-10-27 14:23:40 +02:00
|
|
|
const c = @cImport({
|
2023-10-04 14:20:49 +02:00
|
|
|
@cInclude("sqlite3.h");
|
|
|
|
});
|
2023-10-04 14:20:49 +02:00
|
|
|
|
|
|
|
pub fn main() !void {
|
2023-10-27 14:23:40 +02:00
|
|
|
const alloc = std.heap.page_allocator;
|
|
|
|
|
2023-10-04 14:20:49 +02:00
|
|
|
const screen_width = 800;
|
|
|
|
const screen_height = 450;
|
2023-10-13 18:16:41 +02:00
|
|
|
raylib.InitWindow(screen_width, screen_height, "FabApp");
|
2023-10-04 14:20:49 +02:00
|
|
|
raylib.SetTargetFPS(60);
|
2023-10-13 18:16:41 +02:00
|
|
|
|
|
|
|
var file_dialog_state = raylib.InitGuiWindowFileDialog(raylib.GetWorkingDirectory());
|
2023-10-27 14:23:40 +02:00
|
|
|
// const ext = ".sqlite3";
|
|
|
|
// @memcpy(file_dialog_state.filterExt[0..ext.len], ext);
|
2023-10-13 18:16:41 +02:00
|
|
|
|
2023-10-27 14:23:40 +02:00
|
|
|
var db: ?*c.sqlite3 = undefined;
|
2023-10-13 18:16:41 +02:00
|
|
|
|
2023-10-27 14:23:40 +02:00
|
|
|
while (!raylib.WindowShouldClose()) {
|
|
|
|
//
|
|
|
|
// Update
|
|
|
|
//
|
2023-10-13 18:16:41 +02:00
|
|
|
{
|
2023-10-27 14:23:40 +02:00
|
|
|
if (file_dialog_state.SelectFilePressed) {
|
|
|
|
// C-strings -> slices
|
|
|
|
const dir = std.mem.sliceTo(&file_dialog_state.dirPathText, 0);
|
|
|
|
const file = std.mem.sliceTo(&file_dialog_state.fileNameText, 0);
|
2023-10-13 18:16:41 +02:00
|
|
|
|
2023-10-27 14:23:40 +02:00
|
|
|
// slices -> C-string (null-terminated)
|
|
|
|
const db_path = try std.fs.path.joinZ(alloc, &[_][]const u8{ dir, file });
|
|
|
|
defer alloc.free(db_path);
|
|
|
|
|
|
|
|
const result = c.sqlite3_open(db_path.ptr, &db);
|
|
|
|
if (result != c.SQLITE_OK or db == null) {
|
|
|
|
std.debug.print("[SQLite] err {}: {s}\n", .{ result, c.sqlite3_errmsg(db) });
|
|
|
|
_ = c.sqlite3_close(db);
|
|
|
|
} else {
|
|
|
|
std.debug.print("[SQLite] Success\n", .{});
|
|
|
|
}
|
2023-10-13 18:16:41 +02:00
|
|
|
}
|
2023-10-27 14:23:40 +02:00
|
|
|
file_dialog_state.SelectFilePressed = false;
|
2023-10-13 18:16:41 +02:00
|
|
|
}
|
|
|
|
|
2023-10-27 14:23:40 +02:00
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
}
|
2023-10-04 14:20:49 +02:00
|
|
|
}
|
|
|
|
raylib.CloseWindow();
|
2023-10-04 14:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|