From 57041e707c06360808c9026f41c968c914e5415c Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Sat, 4 Jan 2025 00:24:09 +0100 Subject: [PATCH] [raygui] Allow GuiControlProperty and GuiDefaultProperty as types for property in GuiGetStyle/GuiSetStyle (#131) --- lib/generate_functions.py | 2 ++ lib/preludes/raygui-prelude.zig | 34 +++++++++++++++++++++++++ lib/raygui.zig | 44 +++++++++++++++++++++++++-------- 3 files changed, 70 insertions(+), 10 deletions(-) diff --git a/lib/generate_functions.py b/lib/generate_functions.py index b9d285a..c027a14 100755 --- a/lib/generate_functions.py +++ b/lib/generate_functions.py @@ -367,6 +367,8 @@ def parse_header(header_name: str, output_file: str, ext_file: str, prefix: str, "DrawSplineBezierQuadratic", "DrawSplineBezierCubic", "ImageKernelConvolution", + "GuiSetStyle", + "GuiGetStyle" ] if func_name in manual or "FromMemory" in func_name: diff --git a/lib/preludes/raygui-prelude.zig b/lib/preludes/raygui-prelude.zig index 1c8d189..9b527bb 100644 --- a/lib/preludes/raygui-prelude.zig +++ b/lib/preludes/raygui-prelude.zig @@ -418,6 +418,40 @@ pub const GuiIconName = enum(c_int) { icon_255 = 255, }; +/// Set one style property +pub fn guiSetStyle(control: GuiControl, comptime property: anytype, value: i32) void { + comptime var property_int: c_int = undefined; + + comptime { + if (@TypeOf(property) == GuiControlProperty) { + property_int = @intCast(@intFromEnum(property)); + } else if (@TypeOf(property) == GuiDefaultProperty) { // comparison can't be chained :( + property_int = @intCast(@intFromEnum(property)); + } else { + @compileError("Invalid property type for guiSetStyle"); + } + } + + cdef.GuiSetStyle(control, property_int, @as(c_int, value)); +} + +/// Get one style property +pub fn guiGetStyle(control: GuiControl, comptime property: anytype) i32 { + comptime var property_int: c_int = undefined; + + comptime { + if (@TypeOf(property) == GuiControlProperty) { + property_int = @intCast(@intFromEnum(property)); + } else if (@TypeOf(property) == GuiDefaultProperty) { // comparison can't be chained :( + property_int = @intCast(@intFromEnum(property)); + } else { + @compileError("Invalid property type for guiGetStyle"); + } + } + + return @as(i32, cdef.GuiGetStyle(control, property_int)); +} + /// Get raygui icons data pointer pub fn guiGetIcons() RayguiError![]u32 { var res: []u32 = undefined; diff --git a/lib/raygui.zig b/lib/raygui.zig index 3bea717..bc5b657 100644 --- a/lib/raygui.zig +++ b/lib/raygui.zig @@ -418,6 +418,40 @@ pub const GuiIconName = enum(c_int) { icon_255 = 255, }; +/// Set one style property +pub fn guiSetStyle(control: GuiControl, comptime property: anytype, value: i32) void { + comptime var property_int: c_int = undefined; + + comptime { + if (@TypeOf(property) == GuiControlProperty) { + property_int = @intCast(@intFromEnum(property)); + } else if (@TypeOf(property) == GuiDefaultProperty) { // comparison can't be chained :( + property_int = @intCast(@intFromEnum(property)); + } else { + @compileError("Invalid property type for guiSetStyle"); + } + } + + cdef.GuiSetStyle(control, property_int, @as(c_int, value)); +} + +/// Get one style property +pub fn guiGetStyle(control: GuiControl, comptime property: anytype) i32 { + comptime var property_int: c_int = undefined; + + comptime { + if (@TypeOf(property) == GuiControlProperty) { + property_int = @intCast(@intFromEnum(property)); + } else if (@TypeOf(property) == GuiDefaultProperty) { // comparison can't be chained :( + property_int = @intCast(@intFromEnum(property)); + } else { + @compileError("Invalid property type for guiGetStyle"); + } + } + + return @as(i32, cdef.GuiGetStyle(control, property_int)); +} + /// Get raygui icons data pointer pub fn guiGetIcons() RayguiError![]u32 { var res: []u32 = undefined; @@ -514,16 +548,6 @@ pub fn guiGetFont() Font { return cdef.GuiGetFont(); } -/// Set one style property -pub fn guiSetStyle(control: GuiControl, property: i32, value: i32) void { - cdef.GuiSetStyle(control, @as(c_int, property), @as(c_int, value)); -} - -/// Get one style property -pub fn guiGetStyle(control: GuiControl, property: i32) i32 { - return @as(i32, cdef.GuiGetStyle(control, @as(c_int, property))); -} - /// Load style file over global style variable (.rgs) pub fn guiLoadStyle(fileName: [*:0]const u8) void { cdef.GuiLoadStyle(@as([*c]const u8, @ptrCast(fileName)));