Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work in progress: Add raygui support #39

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const std = @import("std");
const Builder = std.build.Builder;
const raylib = @import("lib.zig");
const raygui = @import("raygui/lib.zig");

const Program = struct {
name: []const u8,
Expand Down Expand Up @@ -59,7 +60,12 @@ pub fn build(b: *Builder) void {
.name = "texture_outline",
.path = "examples/shaders/texture_outline.zig",
.desc = "Uses a shader to create an outline around a sprite",
}
},
.{
.name = "raygui_button",
.path = "examples/core/raygui_button.zig",
.desc = "A simple button in Raygui",
},
// .{
// .name = "models_loading",
// .path = "examples/models/models_loading.zig",
Expand All @@ -85,6 +91,10 @@ pub fn build(b: *Builder) void {
raylib.addAsPackage("raylib", exe);
raylib.math.addAsPackage("raylib-math", exe);

// Add raygui
raygui.link(exe);
raygui.addAsPackage("raygui", exe);

const run_cmd = exe.run();
const run_step = b.step(ex.name, ex.desc);
run_step.dependOn(&run_cmd.step);
Expand Down
39 changes: 39 additions & 0 deletions examples/core/raygui_button.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const std = @import("std");
const rl = @import("raylib");
const rlm = @import("raylib-math");
const rg = @import("raygui");

pub fn main() anyerror!void {
std.debug.print("jtest {}", .{rg.my_function()});
// rg.GuiEnable();
// const screenWidth = 800;
// const screenHeight = 800;

// rl.InitWindow(screenWidth, screenHeight, "raylib [button] example");
// rl.SetTargetFPS(60); // Set our game to run at 60 frames-per-second
// //--------------------------------------------------------------------------------------
// // Main game loop
// while (!rl.WindowShouldClose()) // Detect window close button or ESC key
// {
// // Update
// //----------------------------------------------------------------------------------

// //----------------------------------------------------------------------------------

// // Draw
// //----------------------------------------------------------------------------------
// rl.BeginDrawing();
// rl.ClearBackground(rl.RAYWHITE);
// if (rg.GuiButton(.{ .x = -60 + screenWidth / 2, .y = -15 + screenHeight / 2, .width = 120, .height = 30 }, "Button")) {
// std.debug.print("Button Pressed!\n", .{});
// }
// rl.EndDrawing();
// //----------------------------------------------------------------------------------
// }

// // De-Initialization
// // --------------------------------------------------------------------------------------

// rl.CloseWindow(); // Close window and OpenGL context
// // --------------------------------------------------------------------------------------
}
6 changes: 6 additions & 0 deletions lib/raygui-zig.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// const rl = @import("raylib-zig.zig");

// const Rectangle = rl.Rectangle;
// pub extern fn GuiButton(bounds: Rectangle, text: [*c]const u8) bool;
// pub extern fn GuiEnable() void;
pub extern fn my_function() c_int;
45 changes: 45 additions & 0 deletions raygui/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const std = @import("std");

pub fn addRaygui(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();

const raygui = b.addStaticLibrary("raygui", srcdir ++ "/raygui.h");
raygui.setTarget(target);
raygui.setBuildMode(mode);
// Make raylib.h available for import to raygui.h
raygui.addIncludePath("raylib/src");
raygui.linkLibC();

const raylib_flags = &[_][]const u8{
"-std=gnu99",
"-DPLATFORM_DESKTOP",
"-DGL_SILENCE_DEPRECATION=199309L",
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
};
raygui.addCSourceFiles(&.{
srcdir ++ "/raygui.c",
}, raylib_flags);
raygui.defineCMacroRaw("RAYGUI_IMPLEMENTATION");

return raygui;
}

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.
const target = b.standardTargetOptions(.{});

const lib = addRaygui(b, target);
lib.setOutputDir(srcdir);
lib.install();
}

const srcdir = getSrcDir();

fn getSrcDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
18 changes: 18 additions & 0 deletions raygui/lib.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const std = @import("std");
const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep;
const rayguiBuild = @import("build.zig");

const srcdir = getSrcDir();

fn getSrcDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}

pub fn link(exe: *LibExeObjStep) void {
exe.linkLibrary(rayguiBuild.addRaygui(exe.builder, exe.target));
}

pub fn addAsPackage(name: []const u8, to: *LibExeObjStep) void {
to.addPackagePath(name, "lib/raygui-zig.zig");
}
1 change: 1 addition & 0 deletions raygui/my_header.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "my_header.h"
8 changes: 8 additions & 0 deletions raygui/my_header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef MY_HEADER_H
#define MY_HEADER_H

int my_function(){
return 3;
}

#endif
1 change: 1 addition & 0 deletions raygui/raygui.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "raygui.h"