[raygui] Allow GuiControlProperty and GuiDefaultProperty as types for property in GuiGetStyle/GuiSetStyle (#131)

This commit is contained in:
Not-Nik 2025-01-04 00:24:09 +01:00
parent 16a388c9c2
commit 57041e707c
No known key found for this signature in database
GPG Key ID: E95F679E3CDD9784
3 changed files with 70 additions and 10 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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)));