[wip] load sqlite
This commit is contained in:
parent
3abe6d39c4
commit
d8e986d623
1 changed files with 38 additions and 12 deletions
50
src/main.zig
50
src/main.zig
|
@ -5,30 +5,56 @@ const sqlite = @cImport({
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
const alloc = std.heap.page_allocator;
|
||||||
|
|
||||||
const screen_width = 800;
|
const screen_width = 800;
|
||||||
const screen_height = 450;
|
const screen_height = 450;
|
||||||
raylib.InitWindow(screen_width, screen_height, "FabApp");
|
raylib.InitWindow(screen_width, screen_height, "FabApp");
|
||||||
raylib.SetTargetFPS(60);
|
raylib.SetTargetFPS(60);
|
||||||
|
|
||||||
var file_dialog_state = raylib.InitGuiWindowFileDialog(raylib.GetWorkingDirectory());
|
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()) {
|
while (!raylib.WindowShouldClose()) {
|
||||||
raylib.BeginDrawing();
|
//
|
||||||
defer raylib.EndDrawing();
|
// Update
|
||||||
raylib.ClearBackground(raylib.RAYWHITE);
|
//
|
||||||
|
|
||||||
{
|
{
|
||||||
if (file_dialog_state.windowActive) raylib.GuiLock();
|
if (file_dialog_state.SelectFilePressed) {
|
||||||
defer raylib.GuiUnlock();
|
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 button_size = 200;
|
const rc = sqlite.sqlite3_open(@ptrCast(db_path), @alignCast(@ptrCast(db)));
|
||||||
if (raylib.GuiButton(.{ .x = (screen_width - button_size) / 2, .y = (screen_height - button_size) / 2, .width = 200, .height = 200 }, "Load db file") == 1) {
|
if (rc != 0) {
|
||||||
file_dialog_state.windowActive = true;
|
std.debug.print("Can't open database: {s}", .{sqlite.sqlite3_errmsg(@ptrCast(db))});
|
||||||
|
_ = sqlite.sqlite3_close(@ptrCast(db));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
file_dialog_state.SelectFilePressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.GuiWindowFileDialog(&file_dialog_state);
|
//
|
||||||
// // if (GuiButton((Rectangle){ 20, 20, 140, 30 }, GuiIconText(ICON_FILE_OPEN, "Open Image"))) fileDialogState.windowActive = true;
|
// 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();
|
raylib.CloseWindow();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue