Compare commits

...

2 Commits

Author SHA1 Message Date
Fabien Freling 770ba3a991 switch from raylib to capy 2024-05-05 21:03:10 +02:00
Fabien Freling f5a5157e80 update flake 2024-05-04 14:54:49 +02:00
12 changed files with 103 additions and 106 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
libraylib.a

6
.gitmodules vendored
View File

@ -1,6 +0,0 @@
[submodule "3rdparty/raylib"]
path = 3rdparty/raylib
url = https://github.com/raysan5/raylib
[submodule "3rdparty/raygui"]
path = 3rdparty/raygui
url = https://github.com/raysan5/raygui.git

1
3rdparty/raygui vendored

@ -1 +0,0 @@
Subproject commit 865bb293764073c01e74314ef647464f1f10fd96

1
3rdparty/raylib vendored

@ -1 +0,0 @@
Subproject commit ca12ef48e9e9f4eae03b1ca43ec3eb0a78d63dd3

View File

@ -1,48 +1,29 @@
const std = @import("std");
const raylib = @import("./3rdparty/raylib/src/build.zig");
const capy = @import("capy");
pub fn build(b: *std.build.Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const exe = b.addExecutable(.{
.name = "doggo",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = mode,
});
const exe = b.addExecutable("doggo", "src/main.zig");
exe.setTarget(target);
b.installArtifact(exe);
const ray = raylib.addRaylib(b, exe.target);
exe.linkLibrary(ray);
exe.addIncludeDir("3rdparty/raylib/src");
exe.addIncludeDir("3rdparty/raygui/src");
exe.addIncludeDir("3rdparty/raygui/examples");
const raylib_flags = &[_][]const u8{
"-std=gnu99",
"-DPLATFORM_DESKTOP",
"-DGL_SILENCE_DEPRECATION=199309L",
"-fno-sanitize=undefined",
};
exe.addCSourceFile("src/raylib.c", raylib_flags);
exe.setBuildMode(mode);
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_cmd = try capy.install(exe, .{ .args = b.args });
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
run_step.dependOn(run_cmd);
const exe_tests = b.addTest("src/main.zig");
exe_tests.setTarget(target);
exe_tests.setBuildMode(mode);
const exe_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = mode,
});
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);

19
build.zig.zon Normal file
View File

@ -0,0 +1,19 @@
.{
.name = "doggo",
.version = "0.1.0",
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
.dependencies = .{
.capy = .{
.url = "https://github.com/ffreling/capy/archive/refs/heads/zig-0.12.0.tar.gz",
.hash = "12207fd2f0d02eb929d1e8a05843de4dc3f4b362055e9e47a014fb6b806a592d9808",
},
.zigimg = .{
.url = "https://github.com/zigimg/zigimg/archive/8873f29fc449e1b63400e9f4ad86d3c76204f962.tar.gz",
.hash = "122019f6439545235af116d0d8eb81fde1ff05fdb070da57c723772c557f84c5bf39",
},
},
}

View File

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1651369430,
"narHash": "sha256-d86uUm0s11exU9zLo2K1AwtJQJDKubFpoF0Iw767uT4=",
"lastModified": 1714750952,
"narHash": "sha256-oOUdvPrO8CbupgDSaPou+Jv6GL+uQA2QlE33D7OLzkM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b283b64580d1872333a99af2b4cef91bb84580cf",
"rev": "5fd8536a9a5932d4ae8de52b7dc08d92041237fc",
"type": "github"
},
"original": {

View File

@ -4,24 +4,15 @@
outputs = { self, nixpkgs }:
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
# packages.x86_64-linux.hello = pkgs.hello;
# packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
# defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello;
devShell.x86_64-linux = with pkgs;
mkShell {
buildInputs = [
nativeBuildInputs = [
just
zig
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXext
xorg.libXrandr
xorg.libXinerama
libGL
libGLU
zls
];
buildInputs = [
gtk4
];
};
};

View File

@ -1,2 +1,7 @@
alias b := build
build:
zig build
alias r := run
run:
nixGL zig build run
zig build run

View File

@ -1,40 +1,61 @@
const std = @import("std");
const r = @import("raylib.zig");
const capy = @import("capy");
pub fn main() anyerror!void {
r.InitWindow(800, 450, "doggo");
defer r.CloseWindow();
// This is required for your app to build to WebAssembly and other particular architectures
pub usingnamespace capy.cross_platform;
// var selected_filename: [512]u8 = undefined;
var file_dialog_state = r.InitGuiFileDialog(420, 310, r.GetWorkingDirectory(), false);
pub fn main() !void {
try capy.backend.init();
while (!r.WindowShouldClose()) {
// Update
if (file_dialog_state.SelectFilePressed) {
std.log.info("{s} / {s}", .{ file_dialog_state.dirPathText, file_dialog_state.fileNameText });
}
var window = try capy.Window.init();
try window.set(
capy.label(.{ .text = "Hello, World", .alignment = .Center }),
);
// Draw
r.BeginDrawing();
defer r.EndDrawing();
window.setTitle("Hello");
window.setPreferredSize(250, 100);
window.show();
r.ClearBackground(r.RAYWHITE);
r.DrawText("Congrats! You created your first window!", 190, 200, 20, r.LIGHTGRAY);
if (file_dialog_state.fileDialogActive) {
r.GuiLock();
}
if (r.GuiButton(r.Rectangle{ .x = 190, .y = 250, .width = 150, .height = 30 }, "Button")) {
std.log.info("Button pressed", .{});
file_dialog_state.fileDialogActive = true;
}
r.GuiUnlock();
r.GuiFileDialog(&file_dialog_state);
}
capy.runEventLoop();
}
test "basic test" {
try std.testing.expectEqual(10, 3 + 7);
}
// const std = @import("std");
// const r = @import("raylib.zig");
// pub fn main() anyerror!void {
// r.InitWindow(800, 450, "doggo");
// defer r.CloseWindow();
// // var selected_filename: [512]u8 = undefined;
// var file_dialog_state = r.InitGuiWindowFileDialog(r.GetWorkingDirectory());
// while (!r.WindowShouldClose()) {
// // Update
// if (file_dialog_state.SelectFilePressed) {
// std.log.info("{s} / {s}", .{ file_dialog_state.dirPathText, file_dialog_state.fileNameText });
// }
// // Draw
// r.BeginDrawing();
// defer r.EndDrawing();
// r.ClearBackground(r.RAYWHITE);
// r.DrawText("Congrats! You created your first window!", 190, 200, 20, r.LIGHTGRAY);
// if (file_dialog_state.windowActive) {
// r.GuiLock();
// }
// if (r.GuiButton(r.Rectangle{ .x = 190, .y = 250, .width = 150, .height = 30 }, "Button") == 1) {
// std.log.info("Button pressed", .{});
// file_dialog_state.windowActive = true;
// }
// r.GuiUnlock();
// r.GuiWindowFileDialog(&file_dialog_state);
// }
// }
// test "basic test" {
// try std.testing.expectEqual(10, 3 + 7);
// }

View File

@ -1,6 +0,0 @@
#define RAYGUI_IMPLEMENTATION
#include <raygui.h>
#undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again
#define GUI_FILE_DIALOG_IMPLEMENTATION
#include <custom_file_dialog/gui_file_dialog.h>

View File

@ -1,5 +0,0 @@
pub usingnamespace @cImport({
@cInclude("raylib.h");
@cInclude("raygui.h");
@cInclude("custom_file_dialog/gui_file_dialog.h");
});