Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions bindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
}
],
"returnType": "i32",
"description": "Label control, shows text",
"description": "Label control",
"custom": false
},
{
Expand Down Expand Up @@ -406,7 +406,7 @@
}
],
"returnType": "i32",
"description": "Label button control, show true when clicked",
"description": "Label button control, returns true when clicked",
"custom": false
},
{
Expand All @@ -426,7 +426,7 @@
}
],
"returnType": "i32",
"description": "Toggle Button control, returns true when active",
"description": "Toggle Button control",
"custom": false
},
{
Expand All @@ -446,7 +446,7 @@
}
],
"returnType": "i32",
"description": "Toggle Group control, returns active toggle index",
"description": "Toggle Group control",
"custom": false
},
{
Expand All @@ -466,7 +466,7 @@
}
],
"returnType": "i32",
"description": "Toggle Slider control, returns true when clicked",
"description": "Toggle Slider control",
"custom": false
},
{
Expand Down Expand Up @@ -506,7 +506,7 @@
}
],
"returnType": "i32",
"description": "Combo Box control, returns selected item index",
"description": "Combo Box control",
"custom": false
},
{
Expand All @@ -530,7 +530,7 @@
}
],
"returnType": "i32",
"description": "Dropdown Box control, returns selected item",
"description": "Dropdown Box control",
"custom": false
},
{
Expand Down Expand Up @@ -562,7 +562,7 @@
}
],
"returnType": "i32",
"description": "Spinner control, returns selected value",
"description": "Spinner control",
"custom": false
},
{
Expand Down Expand Up @@ -650,7 +650,7 @@
}
],
"returnType": "i32",
"description": "Slider control, returns selected value",
"description": "Slider control",
"custom": false
},
{
Expand Down Expand Up @@ -682,7 +682,7 @@
}
],
"returnType": "i32",
"description": "Slider Bar control, returns selected value",
"description": "Slider Bar control",
"custom": false
},
{
Expand Down Expand Up @@ -714,7 +714,7 @@
}
],
"returnType": "i32",
"description": "Progress Bar control, shows current progress value",
"description": "Progress Bar control",
"custom": false
},
{
Expand Down Expand Up @@ -774,7 +774,7 @@
}
],
"returnType": "i32",
"description": "Grid control, returns mouse cell position",
"description": "Grid control",
"custom": false
},
{
Expand All @@ -798,7 +798,7 @@
}
],
"returnType": "i32",
"description": "List View control, returns selected list item index",
"description": "List View control",
"custom": false
},
{
Expand Down Expand Up @@ -1010,7 +1010,7 @@
}
],
"returnType": "i32",
"description": "Color Panel control that returns HSV color value, used by GuiColorPickerHSV()",
"description": "Color Panel control that updates Hue-Saturation-Value color value, used by GuiColorPickerHSV()",
"custom": false
}
],
Expand Down Expand Up @@ -2635,17 +2635,17 @@
"description": ""
},
{
"name": "ICON_220",
"name": "ICON_WARNING",
"value": 220,
"description": ""
},
{
"name": "ICON_221",
"name": "ICON_HELP_BOX",
"value": 221,
"description": ""
},
{
"name": "ICON_222",
"name": "ICON_INFO_BOX",
"value": 222,
"description": ""
},
Expand Down Expand Up @@ -3296,6 +3296,13 @@
"description": "",
"custom": false
},
{
"name": "RAYGUI_MIN_MOUSE_WHEEL_SPEED",
"typ": "i32",
"value": "20",
"description": "",
"custom": false
},
{
"name": "RAYGUI_TOGGLEGROUP_MAX_ITEMS",
"typ": "i32",
Expand Down Expand Up @@ -3369,7 +3376,7 @@
{
"name": "RAYGUI_GRID_ALPHA",
"typ": "f32",
"value": "0.15",
"value": "1.5e-1",
"description": "",
"custom": false
},
Expand Down
46 changes: 29 additions & 17 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) !void {
const jsons = b.step("parse", "parse raygui headers and generate raylib parser output as json");
const raylib_parser_build = b.addExecutable(.{
.name = "raylib_parser",
.root_source_file = std.build.FileSource.relative("raylib_parser.zig"),
.root_source_file = std.Build.LazyPath.relative("raylib_parser.zig"),
.target = target,
.optimize = .ReleaseFast,
});
Expand All @@ -31,7 +31,7 @@ pub fn build(b: *std.Build) !void {
const intermediate = b.step("intermediate", "generate intermediate representation of the results from 'zig build parse' (keep custom=true)");
var intermediateZig = b.addRunArtifact(b.addExecutable(.{
.name = "intermediate",
.root_source_file = std.build.FileSource.relative("intermediate.zig"),
.root_source_file = std.Build.LazyPath.relative("intermediate.zig"),
.target = target,
}));
intermediate.dependOn(&intermediateZig.step);
Expand All @@ -40,7 +40,7 @@ pub fn build(b: *std.Build) !void {
const bindings = b.step("bindings", "generate bindings in from bindings.json");
var generateZig = b.addRunArtifact(b.addExecutable(.{
.name = "generate",
.root_source_file = std.build.FileSource.relative("generate.zig"),
.root_source_file = std.Build.LazyPath.relative("generate.zig"),
.target = target,
}));
const fmt = b.addFmt(.{ .paths = &.{generate.outputFile} });
Expand All @@ -65,22 +65,34 @@ const sep = std.fs.path.sep_str;
const dir_raygui = cwd ++ sep ++ "raygui/src";

/// add this package to lib
pub fn addTo(b: *std.Build, lib: *std.Build.Step.Compile, target: std.Target.Query, optimize: std.builtin.Mode) void {
_ = b;
_ = optimize;
_ = target;

pub fn addTo(
b: *std.Build,
lib: *std.Build.Step.Compile,
target: std.Target.Query,
optimize: std.builtin.Mode,
) void {
if (lib.root_module.import_table.get("raylib") orelse lib.root_module.import_table.get("raylib.zig") orelse lib.root_module.import_table.get("raylib-zig")) |raylib| {
lib.root_module.addAnonymousImport("raygui", .{
.root_source_file = .{ .path = cwd ++ sep ++ "raygui.zig" },
.imports = &.{
.{ .name = "raylib", .module = raylib },
const rayguiLib = b.addStaticLibrary(
.{
.name = "raygui.zig",
.target = b.resolveTargetQuery(target),
.optimize = optimize,
.root_source_file = .{ .path = cwd ++ sep ++ "raygui.zig" },
},
});
lib.addIncludePath(.{ .path = dir_raygui });
lib.addIncludePath(.{ .path = cwd });
lib.linkLibC();
lib.addCSourceFile(.{ .file = .{ .path = cwd ++ sep ++ "raygui_marshal.c" }, .flags = &.{"-DRAYGUI_IMPLEMENTATION"} });
);

rayguiLib.linkLibC();

for (raylib.include_dirs.items) |includedItem| {
rayguiLib.addIncludePath(includedItem.path);
}

rayguiLib.addIncludePath(.{ .path = dir_raygui });
rayguiLib.addIncludePath(.{ .path = cwd });
rayguiLib.addCSourceFile(.{ .file = .{ .path = cwd ++ sep ++ "raygui_marshal.c" }, .flags = &.{"-DRAYGUI_IMPLEMENTATION"} });
rayguiLib.root_module.addImport("raylib", raylib);

lib.root_module.addImport("raygui", &rayguiLib.root_module);
} else {
std.debug.panic("lib needs to have 'raylib', 'raylib.zig' or 'raylib-zig' as module dependency", .{});
}
Expand Down
22 changes: 12 additions & 10 deletions generate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn writeFunctions(

//--- body ------------------------------
if (isPointer(func.returnType)) {
try file.writeAll(try allocPrint(allocator, "return @ptrCast({s},\n", .{func.returnType}));
try file.writeAll(try allocPrint(allocator, "return @as({s},@ptrCast(\n", .{func.returnType}));
} else if (isPrimitiveOrPointer(func.returnType)) {
try file.writeAll("return ");
} else if (!returnTypeIsVoid) {
Expand All @@ -187,34 +187,36 @@ fn writeFunctions(

if (!isPrimitiveOrPointer(func.returnType)) {
if (bindings.containsStruct(stripType(func.returnType))) {
try file.writeAll(try allocPrint(allocator, "@ptrCast([*c]raygui.{s}, &out),\n", .{func.returnType}));
try file.writeAll(try allocPrint(allocator, "@as([*c]raygui.{s}, @ptrCast(&out)),\n", .{func.returnType}));
} else if (!returnTypeIsVoid) {
try file.writeAll(try allocPrint(allocator, "@ptrCast([*c]{s}, &out),\n", .{func.returnType}));
try file.writeAll(try allocPrint(allocator, "@as([*c]{s}, @ptrCast(&out)),\n", .{func.returnType}));
}
}

for (func.params) |param| {
if (isFunctionPointer(param.typ)) {
try file.writeAll(try allocPrint(allocator, "@ptrCast({s}),\n", .{param.name}));
} else if (bindings.containsStruct(stripType(param.typ)) and isPointer(param.typ)) {
try file.writeAll(try allocPrint(allocator, "@intToPtr([*c]raygui.{s}, @ptrToInt({s})),\n", .{ stripType(param.typ), param.name }));
try file.writeAll(try allocPrint(allocator, "@as([*c]raygui.{s}, @ptrFromInt(@intFromPtr({s}))),\n", .{ stripType(param.typ), param.name }));
} else if (bindings.containsEnum(param.typ)) {
try file.writeAll(try allocPrint(allocator, "@enumToInt({s}),\n", .{param.name}));
try file.writeAll(try allocPrint(allocator, "@intFromEnum({s}),\n", .{param.name}));
} else if (bindings.containsStruct(stripType(param.typ))) {
try file.writeAll(try allocPrint(allocator, "@intToPtr([*c]raygui.{s}, @ptrToInt(&{s})),\n", .{ stripType(param.typ), param.name }));
try file.writeAll(try allocPrint(allocator, "@as([*c]raygui.{s}, @ptrFromInt(@intFromPtr(&{s}))),\n", .{ stripType(param.typ), param.name }));
} else if (isPointer(param.typ)) {
if (isConst(param.typ)) {
try file.writeAll(try allocPrint(allocator, "@intToPtr([*c]const {s}, @ptrToInt({s})),\n", .{ stripType(param.typ), param.name }));
if (std.mem.endsWith(u8, param.typ, "anyopaque")) {
try file.writeAll(try allocPrint(allocator, "{s},\n", .{param.name}));
} else if (isConst(param.typ)) {
try file.writeAll(try allocPrint(allocator, "@as([*c]const {s}, @ptrFromInt(@intFromPtr({s}))),\n", .{ stripType(param.typ), param.name }));
} else {
try file.writeAll(try allocPrint(allocator, "@ptrCast([*c]{s}, {s}),\n", .{ stripType(param.typ), param.name }));
try file.writeAll(try allocPrint(allocator, "@as([*c]{s}, @ptrCast({s})),\n", .{ stripType(param.typ), param.name }));
}
} else {
try file.writeAll(try allocPrint(allocator, "{s},\n", .{param.name}));
}
}

if (isPointer(func.returnType)) {
try file.writeAll("),\n);\n");
try file.writeAll("),\n));\n");
} else {
try file.writeAll(");\n");
}
Expand Down
Loading