From c419e8237ae82b2af700923b15e3e5145425cf7f Mon Sep 17 00:00:00 2001 From: Nikolas Mavropoulos Date: Sun, 31 Mar 2024 14:20:28 +0300 Subject: [PATCH 1/5] updated to latest raygui --- bindings.json | 43 ++++--- build.zig | 6 +- raygui | 2 +- raygui.json | 126 +++++++++++---------- raygui.zig | 283 ++++++++++++++++++++++++----------------------- raygui_marshal.h | 28 ++--- type_mapping.zig | 34 ++++-- 7 files changed, 275 insertions(+), 247 deletions(-) diff --git a/bindings.json b/bindings.json index 615db63..4d82da1 100644 --- a/bindings.json +++ b/bindings.json @@ -374,7 +374,7 @@ } ], "returnType": "i32", - "description": "Label control, shows text", + "description": "Label control", "custom": false }, { @@ -406,7 +406,7 @@ } ], "returnType": "i32", - "description": "Label button control, show true when clicked", + "description": "Label button control, returns true when clicked", "custom": false }, { @@ -426,7 +426,7 @@ } ], "returnType": "i32", - "description": "Toggle Button control, returns true when active", + "description": "Toggle Button control", "custom": false }, { @@ -446,7 +446,7 @@ } ], "returnType": "i32", - "description": "Toggle Group control, returns active toggle index", + "description": "Toggle Group control", "custom": false }, { @@ -466,7 +466,7 @@ } ], "returnType": "i32", - "description": "Toggle Slider control, returns true when clicked", + "description": "Toggle Slider control", "custom": false }, { @@ -506,7 +506,7 @@ } ], "returnType": "i32", - "description": "Combo Box control, returns selected item index", + "description": "Combo Box control", "custom": false }, { @@ -530,7 +530,7 @@ } ], "returnType": "i32", - "description": "Dropdown Box control, returns selected item", + "description": "Dropdown Box control", "custom": false }, { @@ -562,7 +562,7 @@ } ], "returnType": "i32", - "description": "Spinner control, returns selected value", + "description": "Spinner control", "custom": false }, { @@ -650,7 +650,7 @@ } ], "returnType": "i32", - "description": "Slider control, returns selected value", + "description": "Slider control", "custom": false }, { @@ -682,7 +682,7 @@ } ], "returnType": "i32", - "description": "Slider Bar control, returns selected value", + "description": "Slider Bar control", "custom": false }, { @@ -714,7 +714,7 @@ } ], "returnType": "i32", - "description": "Progress Bar control, shows current progress value", + "description": "Progress Bar control", "custom": false }, { @@ -774,7 +774,7 @@ } ], "returnType": "i32", - "description": "Grid control, returns mouse cell position", + "description": "Grid control", "custom": false }, { @@ -798,7 +798,7 @@ } ], "returnType": "i32", - "description": "List View control, returns selected list item index", + "description": "List View control", "custom": false }, { @@ -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 } ], @@ -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": "" }, @@ -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", @@ -3369,7 +3376,7 @@ { "name": "RAYGUI_GRID_ALPHA", "typ": "f32", - "value": "0.15", + "value": "1.5e-1", "description": "", "custom": false }, diff --git a/build.zig b/build.zig index c830f66..feb0695 100644 --- a/build.zig +++ b/build.zig @@ -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, }); @@ -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); @@ -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} }); diff --git a/raygui b/raygui index 45e7f96..176ab3d 160000 --- a/raygui +++ b/raygui @@ -1 +1 @@ -Subproject commit 45e7f967e62088b9fec02ac38c07d4b67d6466b0 +Subproject commit 176ab3db60e1c61fb33bc5e0cbba98adf054cd5e diff --git a/raygui.json b/raygui.json index 32f83e0..6f45b22 100644 --- a/raygui.json +++ b/raygui.json @@ -9,19 +9,19 @@ { "name": "RAYGUI_VERSION_MAJOR", "type": "INT", - "value": "4", + "value": 4, "description": "" }, { "name": "RAYGUI_VERSION_MINOR", "type": "INT", - "value": "0", + "value": 0, "description": "" }, { "name": "RAYGUI_VERSION_PATCH", "type": "INT", - "value": "0", + "value": 0, "description": "" }, { @@ -69,13 +69,13 @@ { "name": "SCROLLBAR_LEFT_SIDE", "type": "INT", - "value": "0", + "value": 0, "description": "" }, { "name": "SCROLLBAR_RIGHT_SIDE", "type": "INT", - "value": "1", + "value": 1, "description": "" }, { @@ -93,19 +93,19 @@ { "name": "RAYGUI_ICON_SIZE", "type": "INT", - "value": "16", + "value": 16, "description": "Size of icons in pixels (squared)" }, { "name": "RAYGUI_ICON_MAX_ICONS", "type": "INT", - "value": "256", + "value": 256, "description": "Maximum number of icons" }, { "name": "RAYGUI_ICON_MAX_NAME_LENGTH", "type": "INT", - "value": "32", + "value": 32, "description": "Maximum length of icon name id" }, { @@ -117,181 +117,187 @@ { "name": "RAYGUI_MAX_CONTROLS", "type": "INT", - "value": "16", + "value": 16, "description": "Maximum number of controls" }, { "name": "RAYGUI_MAX_PROPS_BASE", "type": "INT", - "value": "16", + "value": 16, "description": "Maximum number of base properties" }, { "name": "RAYGUI_MAX_PROPS_EXTENDED", "type": "INT", - "value": "8", + "value": 8, "description": "Maximum number of extended properties" }, { "name": "KEY_RIGHT", "type": "INT", - "value": "262", + "value": 262, "description": "" }, { "name": "KEY_LEFT", "type": "INT", - "value": "263", + "value": 263, "description": "" }, { "name": "KEY_DOWN", "type": "INT", - "value": "264", + "value": 264, "description": "" }, { "name": "KEY_UP", "type": "INT", - "value": "265", + "value": 265, "description": "" }, { "name": "KEY_BACKSPACE", "type": "INT", - "value": "259", + "value": 259, "description": "" }, { "name": "KEY_ENTER", "type": "INT", - "value": "257", + "value": 257, "description": "" }, { "name": "MOUSE_LEFT_BUTTON", "type": "INT", - "value": "0", + "value": 0, "description": "" }, { "name": "RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT", "type": "INT", - "value": "24", + "value": 24, "description": "" }, { "name": "RAYGUI_GROUPBOX_LINE_THICK", "type": "INT", - "value": "1", + "value": 1, "description": "" }, { "name": "RAYGUI_LINE_MARGIN_TEXT", "type": "INT", - "value": "12", + "value": 12, "description": "" }, { "name": "RAYGUI_LINE_TEXT_PADDING", "type": "INT", - "value": "4", + "value": 4, "description": "" }, { "name": "RAYGUI_PANEL_BORDER_WIDTH", "type": "INT", - "value": "1", + "value": 1, "description": "" }, { "name": "RAYGUI_TABBAR_ITEM_WIDTH", "type": "INT", - "value": "160", + "value": 160, "description": "" }, { "name": "RAYGUI_MIN_SCROLLBAR_WIDTH", "type": "INT", - "value": "40", + "value": 40, "description": "" }, { "name": "RAYGUI_MIN_SCROLLBAR_HEIGHT", "type": "INT", - "value": "40", + "value": 40, + "description": "" + }, + { + "name": "RAYGUI_MIN_MOUSE_WHEEL_SPEED", + "type": "INT", + "value": 20, "description": "" }, { "name": "RAYGUI_TOGGLEGROUP_MAX_ITEMS", "type": "INT", - "value": "32", + "value": 32, "description": "" }, { "name": "RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN", "type": "INT", - "value": "40", + "value": 40, "description": "Frames to wait for autocursor movement" }, { "name": "RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY", "type": "INT", - "value": "1", + "value": 1, "description": "Frames delay for autocursor movement" }, { "name": "RAYGUI_VALUEBOX_MAX_CHARS", "type": "INT", - "value": "32", + "value": 32, "description": "" }, { "name": "RAYGUI_COLORBARALPHA_CHECKED_SIZE", "type": "INT", - "value": "10", + "value": 10, "description": "" }, { "name": "RAYGUI_MESSAGEBOX_BUTTON_HEIGHT", "type": "INT", - "value": "24", + "value": 24, "description": "" }, { "name": "RAYGUI_MESSAGEBOX_BUTTON_PADDING", "type": "INT", - "value": "12", + "value": 12, "description": "" }, { "name": "RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT", "type": "INT", - "value": "24", + "value": 24, "description": "" }, { "name": "RAYGUI_TEXTINPUTBOX_BUTTON_PADDING", "type": "INT", - "value": "12", + "value": 12, "description": "" }, { "name": "RAYGUI_TEXTINPUTBOX_HEIGHT", "type": "INT", - "value": "26", + "value": 26, "description": "" }, { "name": "RAYGUI_GRID_ALPHA", "type": "FLOAT", - "value": "0.15", + "value": 0.15, "description": "" }, { "name": "MAX_LINE_BUFFER_SIZE", "type": "INT", - "value": "256", + "value": 256, "description": "" }, { @@ -303,13 +309,13 @@ { "name": "ICON_TEXT_PADDING", "type": "INT", - "value": "4", + "value": 4, "description": "" }, { "name": "RAYGUI_MAX_TEXT_LINES", "type": "INT", - "value": "128", + "value": 128, "description": "" }, { @@ -321,19 +327,19 @@ { "name": "RAYGUI_TEXTSPLIT_MAX_ITEMS", "type": "INT", - "value": "128", + "value": 128, "description": "" }, { "name": "RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE", "type": "INT", - "value": "1024", + "value": 1024, "description": "" }, { "name": "RAYGUI_TEXTFORMAT_MAX_SIZE", "type": "INT", - "value": "256", + "value": 256, "description": "" } ], @@ -2220,17 +2226,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": "" }, @@ -2729,7 +2735,7 @@ }, { "name": "GuiLabel", - "description": "Label control, shows text", + "description": "Label control", "returnType": "int", "params": [ { @@ -2759,7 +2765,7 @@ }, { "name": "GuiLabelButton", - "description": "Label button control, show true when clicked", + "description": "Label button control, returns true when clicked", "returnType": "int", "params": [ { @@ -2774,7 +2780,7 @@ }, { "name": "GuiToggle", - "description": "Toggle Button control, returns true when active", + "description": "Toggle Button control", "returnType": "int", "params": [ { @@ -2793,7 +2799,7 @@ }, { "name": "GuiToggleGroup", - "description": "Toggle Group control, returns active toggle index", + "description": "Toggle Group control", "returnType": "int", "params": [ { @@ -2812,7 +2818,7 @@ }, { "name": "GuiToggleSlider", - "description": "Toggle Slider control, returns true when clicked", + "description": "Toggle Slider control", "returnType": "int", "params": [ { @@ -2850,7 +2856,7 @@ }, { "name": "GuiComboBox", - "description": "Combo Box control, returns selected item index", + "description": "Combo Box control", "returnType": "int", "params": [ { @@ -2869,7 +2875,7 @@ }, { "name": "GuiDropdownBox", - "description": "Dropdown Box control, returns selected item", + "description": "Dropdown Box control", "returnType": "int", "params": [ { @@ -2892,7 +2898,7 @@ }, { "name": "GuiSpinner", - "description": "Spinner control, returns selected value", + "description": "Spinner control", "returnType": "int", "params": [ { @@ -2977,7 +2983,7 @@ }, { "name": "GuiSlider", - "description": "Slider control, returns selected value", + "description": "Slider control", "returnType": "int", "params": [ { @@ -3008,7 +3014,7 @@ }, { "name": "GuiSliderBar", - "description": "Slider Bar control, returns selected value", + "description": "Slider Bar control", "returnType": "int", "params": [ { @@ -3039,7 +3045,7 @@ }, { "name": "GuiProgressBar", - "description": "Progress Bar control, shows current progress value", + "description": "Progress Bar control", "returnType": "int", "params": [ { @@ -3100,7 +3106,7 @@ }, { "name": "GuiGrid", - "description": "Grid control, returns mouse cell position", + "description": "Grid control", "returnType": "int", "params": [ { @@ -3127,7 +3133,7 @@ }, { "name": "GuiListView", - "description": "List View control, returns selected list item index", + "description": "List View control", "returnType": "int", "params": [ { @@ -3334,7 +3340,7 @@ }, { "name": "GuiColorPanelHSV", - "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()", "returnType": "int", "params": [ { diff --git a/raygui.zig b/raygui.zig index 0363212..a558502 100644 --- a/raygui.zig +++ b/raygui.zig @@ -1,9 +1,9 @@ const std = @import("std"); +const raylib = @import("raylib"); const raygui = @cImport({ @cInclude("raygui.h"); @cInclude("raygui_marshal.h"); }); -const raylib = @import("raylib"); pub const Rectangle = raylib.Rectangle; pub const Vector2 = raylib.Vector2; @@ -104,7 +104,7 @@ pub fn GuiSetState( state: GuiState, ) void { raygui.mGuiSetState( - @intFromEnum(state), + @enumToInt(state), ); } @@ -112,7 +112,7 @@ pub fn GuiSetState( pub fn GuiGetState() GuiState { var out: GuiState = undefined; raygui.mGuiGetState( - @as([*c]GuiState, @ptrCast(&out)), + @ptrCast([*c]GuiState, &out), ); return out; } @@ -122,7 +122,7 @@ pub fn GuiSetFont( font: Font, ) void { raygui.mGuiSetFont( - @as([*c]raygui.Font, @ptrFromInt(@intFromPtr(&font))), + @intToPtr([*c]raygui.Font, @ptrToInt(&font)), ); } @@ -130,7 +130,7 @@ pub fn GuiSetFont( pub fn GuiGetFont() Font { var out: Font = undefined; raygui.mGuiGetFont( - @as([*c]raygui.Font, @ptrCast(&out)), + @ptrCast([*c]raygui.Font, &out), ); return out; } @@ -154,7 +154,7 @@ pub fn GuiGetStyle( property: i32, ) i32 { return raygui.mGuiGetStyle( - @intFromEnum(control), + @enumToInt(control), property, ); } @@ -164,7 +164,7 @@ pub fn GuiLoadStyle( fileName: [*:0]const u8, ) void { raygui.mGuiLoadStyle( - @as([*c]const u8, @ptrFromInt(@intFromPtr(fileName))), + @intToPtr([*c]const u8, @ptrToInt(fileName)), ); } @@ -188,7 +188,7 @@ pub fn GuiSetTooltip( tooltip: [*:0]const u8, ) void { raygui.mGuiSetTooltip( - @as([*c]const u8, @ptrFromInt(@intFromPtr(tooltip))), + @intToPtr([*c]const u8, @ptrToInt(tooltip)), ); } @@ -197,12 +197,12 @@ pub fn GuiIconText( iconId: i32, text: [*:0]const u8, ) [*:0]const u8 { - return @as( + return @ptrCast( [*:0]const u8, - @ptrCast(raygui.mGuiIconText( + raygui.mGuiIconText( iconId, - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - )), + @intToPtr([*c]const u8, @ptrToInt(text)), + ), ); } @@ -217,9 +217,9 @@ pub fn GuiSetIconScale( /// Get raygui icons data pointer pub fn GuiGetIcons() *u32 { - return @as( + return @ptrCast( *u32, - @ptrCast(raygui.mGuiGetIcons()), + raygui.mGuiGetIcons(), ); } @@ -228,12 +228,12 @@ pub fn GuiLoadIcons( fileName: [*:0]const u8, loadIconsName: bool, ) [*][*:0]u8 { - return @as( + return @ptrCast( [*][*:0]u8, - @ptrCast(raygui.mGuiLoadIcons( - @as([*c]const u8, @ptrFromInt(@intFromPtr(fileName))), + raygui.mGuiLoadIcons( + @intToPtr([*c]const u8, @ptrToInt(fileName)), loadIconsName, - )), + ), ); } @@ -243,8 +243,8 @@ pub fn GuiWindowBox( title: [*:0]const u8, ) i32 { return raygui.mGuiWindowBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(title)), ); } @@ -254,8 +254,8 @@ pub fn GuiGroupBox( text: [*:0]const u8, ) i32 { return raygui.mGuiGroupBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), ); } @@ -265,8 +265,8 @@ pub fn GuiLine( text: [*:0]const u8, ) i32 { return raygui.mGuiLine( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), ); } @@ -276,8 +276,8 @@ pub fn GuiPanel( text: [*:0]const u8, ) i32 { return raygui.mGuiPanel( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), ); } @@ -289,10 +289,10 @@ pub fn GuiTabBar( active: *i32, ) i32 { return raygui.mGuiTabBar( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const [*:0]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const [*:0]const u8, @ptrToInt(text)), count, - @as([*c]i32, @ptrCast(active)), + @ptrCast([*c]i32, active), ); } @@ -305,22 +305,22 @@ pub fn GuiScrollPanel( view: *Rectangle, ) i32 { return raygui.mGuiScrollPanel( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&content))), - @as([*c]raygui.Vector2, @ptrFromInt(@intFromPtr(scroll))), - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(view))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&content)), + @intToPtr([*c]raygui.Vector2, @ptrToInt(scroll)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(view)), ); } -/// Label control, shows text +/// Label control pub fn GuiLabel( bounds: Rectangle, text: [*:0]const u8, ) i32 { return raygui.mGuiLabel( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), ); } @@ -330,58 +330,58 @@ pub fn GuiButton( text: [*:0]const u8, ) i32 { return raygui.mGuiButton( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), ); } -/// Label button control, show true when clicked +/// Label button control, returns true when clicked pub fn GuiLabelButton( bounds: Rectangle, text: [*:0]const u8, ) i32 { return raygui.mGuiLabelButton( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), ); } -/// Toggle Button control, returns true when active +/// Toggle Button control pub fn GuiToggle( bounds: Rectangle, text: [*:0]const u8, active: *bool, ) i32 { return raygui.mGuiToggle( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]bool, @ptrCast(active)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]bool, active), ); } -/// Toggle Group control, returns active toggle index +/// Toggle Group control pub fn GuiToggleGroup( bounds: Rectangle, text: [*:0]const u8, active: *i32, ) i32 { return raygui.mGuiToggleGroup( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]i32, @ptrCast(active)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]i32, active), ); } -/// Toggle Slider control, returns true when clicked +/// Toggle Slider control pub fn GuiToggleSlider( bounds: Rectangle, text: [*:0]const u8, active: *i32, ) i32 { return raygui.mGuiToggleSlider( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]i32, @ptrCast(active)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]i32, active), ); } @@ -392,26 +392,26 @@ pub fn GuiCheckBox( checked: *bool, ) i32 { return raygui.mGuiCheckBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]bool, @ptrCast(checked)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]bool, checked), ); } -/// Combo Box control, returns selected item index +/// Combo Box control pub fn GuiComboBox( bounds: Rectangle, text: [*:0]const u8, active: *i32, ) i32 { return raygui.mGuiComboBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]i32, @ptrCast(active)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]i32, active), ); } -/// Dropdown Box control, returns selected item +/// Dropdown Box control pub fn GuiDropdownBox( bounds: Rectangle, text: [*:0]const u8, @@ -419,14 +419,14 @@ pub fn GuiDropdownBox( editMode: bool, ) i32 { return raygui.mGuiDropdownBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]i32, @ptrCast(active)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]i32, active), editMode, ); } -/// Spinner control, returns selected value +/// Spinner control pub fn GuiSpinner( bounds: Rectangle, text: [*:0]const u8, @@ -436,9 +436,9 @@ pub fn GuiSpinner( editMode: bool, ) i32 { return raygui.mGuiSpinner( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]i32, @ptrCast(value)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]i32, value), minValue, maxValue, editMode, @@ -455,9 +455,9 @@ pub fn GuiValueBox( editMode: bool, ) i32 { return raygui.mGuiValueBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]i32, @ptrCast(value)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]i32, value), minValue, maxValue, editMode, @@ -472,14 +472,14 @@ pub fn GuiTextBox( editMode: bool, ) i32 { return raygui.mGuiTextBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]u8, @ptrCast(text)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @ptrCast([*c]u8, text), textSize, editMode, ); } -/// Slider control, returns selected value +/// Slider control pub fn GuiSlider( bounds: Rectangle, textLeft: [*:0]const u8, @@ -489,16 +489,16 @@ pub fn GuiSlider( maxValue: f32, ) i32 { return raygui.mGuiSlider( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), - @as([*c]f32, @ptrCast(value)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(textLeft)), + @intToPtr([*c]const u8, @ptrToInt(textRight)), + @ptrCast([*c]f32, value), minValue, maxValue, ); } -/// Slider Bar control, returns selected value +/// Slider Bar control pub fn GuiSliderBar( bounds: Rectangle, textLeft: [*:0]const u8, @@ -508,16 +508,16 @@ pub fn GuiSliderBar( maxValue: f32, ) i32 { return raygui.mGuiSliderBar( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), - @as([*c]f32, @ptrCast(value)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(textLeft)), + @intToPtr([*c]const u8, @ptrToInt(textRight)), + @ptrCast([*c]f32, value), minValue, maxValue, ); } -/// Progress Bar control, shows current progress value +/// Progress Bar control pub fn GuiProgressBar( bounds: Rectangle, textLeft: [*:0]const u8, @@ -527,10 +527,10 @@ pub fn GuiProgressBar( maxValue: f32, ) i32 { return raygui.mGuiProgressBar( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), - @as([*c]f32, @ptrCast(value)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(textLeft)), + @intToPtr([*c]const u8, @ptrToInt(textRight)), + @ptrCast([*c]f32, value), minValue, maxValue, ); @@ -542,8 +542,8 @@ pub fn GuiStatusBar( text: [*:0]const u8, ) i32 { return raygui.mGuiStatusBar( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), ); } @@ -553,12 +553,12 @@ pub fn GuiDummyRec( text: [*:0]const u8, ) i32 { return raygui.mGuiDummyRec( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), ); } -/// Grid control, returns mouse cell position +/// Grid control pub fn GuiGrid( bounds: Rectangle, text: [*:0]const u8, @@ -567,15 +567,15 @@ pub fn GuiGrid( mouseCell: *Vector2, ) i32 { return raygui.mGuiGrid( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), spacing, subdivs, - @as([*c]raygui.Vector2, @ptrFromInt(@intFromPtr(mouseCell))), + @intToPtr([*c]raygui.Vector2, @ptrToInt(mouseCell)), ); } -/// List View control, returns selected list item index +/// List View control pub fn GuiListView( bounds: Rectangle, text: [*:0]const u8, @@ -583,10 +583,10 @@ pub fn GuiListView( active: *i32, ) i32 { return raygui.mGuiListView( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]i32, @ptrCast(scrollIndex)), - @as([*c]i32, @ptrCast(active)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]i32, scrollIndex), + @ptrCast([*c]i32, active), ); } @@ -600,12 +600,12 @@ pub fn GuiListViewEx( focus: *i32, ) i32 { return raygui.mGuiListViewEx( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const [*:0]const u8, @ptrFromInt(@intFromPtr(text))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const [*:0]const u8, @ptrToInt(text)), count, - @as([*c]i32, @ptrCast(scrollIndex)), - @as([*c]i32, @ptrCast(active)), - @as([*c]i32, @ptrCast(focus)), + @ptrCast([*c]i32, scrollIndex), + @ptrCast([*c]i32, active), + @ptrCast([*c]i32, focus), ); } @@ -617,10 +617,10 @@ pub fn GuiMessageBox( buttons: [*:0]const u8, ) i32 { return raygui.mGuiMessageBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(message))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(buttons))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(title)), + @intToPtr([*c]const u8, @ptrToInt(message)), + @intToPtr([*c]const u8, @ptrToInt(buttons)), ); } @@ -635,13 +635,13 @@ pub fn GuiTextInputBox( secretViewActive: *bool, ) i32 { return raygui.mGuiTextInputBox( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(message))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(buttons))), - @as([*c]u8, @ptrCast(text)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(title)), + @intToPtr([*c]const u8, @ptrToInt(message)), + @intToPtr([*c]const u8, @ptrToInt(buttons)), + @ptrCast([*c]u8, text), textMaxSize, - @as([*c]bool, @ptrCast(secretViewActive)), + @ptrCast([*c]bool, secretViewActive), ); } @@ -652,9 +652,9 @@ pub fn GuiColorPicker( color: *Color, ) i32 { return raygui.mGuiColorPicker( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]raygui.Color, @ptrFromInt(@intFromPtr(color))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @intToPtr([*c]raygui.Color, @ptrToInt(color)), ); } @@ -665,9 +665,9 @@ pub fn GuiColorPanel( color: *Color, ) i32 { return raygui.mGuiColorPanel( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]raygui.Color, @ptrFromInt(@intFromPtr(color))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @intToPtr([*c]raygui.Color, @ptrToInt(color)), ); } @@ -678,9 +678,9 @@ pub fn GuiColorBarAlpha( alpha: *f32, ) i32 { return raygui.mGuiColorBarAlpha( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]f32, @ptrCast(alpha)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]f32, alpha), ); } @@ -691,9 +691,9 @@ pub fn GuiColorBarHue( value: *f32, ) i32 { return raygui.mGuiColorBarHue( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]f32, @ptrCast(value)), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @ptrCast([*c]f32, value), ); } @@ -704,22 +704,22 @@ pub fn GuiColorPickerHSV( colorHsv: *Vector3, ) i32 { return raygui.mGuiColorPickerHSV( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]raygui.Vector3, @ptrFromInt(@intFromPtr(colorHsv))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @intToPtr([*c]raygui.Vector3, @ptrToInt(colorHsv)), ); } -/// Color Panel control that returns HSV color value, used by GuiColorPickerHSV() +/// Color Panel control that updates Hue-Saturation-Value color value, used by GuiColorPickerHSV() pub fn GuiColorPanelHSV( bounds: Rectangle, text: [*:0]const u8, colorHsv: *Vector3, ) i32 { return raygui.mGuiColorPanelHSV( - @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), - @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), - @as([*c]raygui.Vector3, @ptrFromInt(@intFromPtr(colorHsv))), + @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), + @intToPtr([*c]const u8, @ptrToInt(text)), + @intToPtr([*c]raygui.Vector3, @ptrToInt(colorHsv)), ); } @@ -1488,11 +1488,11 @@ pub const GuiIconName = enum(i32) { /// ICON_SAND_TIMER = 219, /// - ICON_220 = 220, + ICON_WARNING = 220, /// - ICON_221 = 221, + ICON_HELP_BOX = 221, /// - ICON_222 = 222, + ICON_INFO_BOX = 222, /// ICON_223 = 223, /// @@ -1642,6 +1642,9 @@ pub const RAYGUI_MIN_SCROLLBAR_WIDTH: i32 = 40; /// pub const RAYGUI_MIN_SCROLLBAR_HEIGHT: i32 = 40; +/// +pub const RAYGUI_MIN_MOUSE_WHEEL_SPEED: i32 = 20; + /// pub const RAYGUI_TOGGLEGROUP_MAX_ITEMS: i32 = 32; @@ -1673,7 +1676,7 @@ pub const RAYGUI_TEXTINPUTBOX_BUTTON_PADDING: i32 = 12; pub const RAYGUI_TEXTINPUTBOX_HEIGHT: i32 = 26; /// -pub const RAYGUI_GRID_ALPHA: f32 = 0.15; +pub const RAYGUI_GRID_ALPHA: f32 = 1.5e-1; /// pub const MAX_LINE_BUFFER_SIZE: i32 = 256; diff --git a/raygui_marshal.h b/raygui_marshal.h index f4cfd77..05caf9a 100644 --- a/raygui_marshal.h +++ b/raygui_marshal.h @@ -81,34 +81,34 @@ int mGuiTabBar(Rectangle *bounds, const char ** text, int count, int * active); // Scroll Panel control int mGuiScrollPanel(Rectangle *bounds, const char * text, Rectangle *content, Vector2 * scroll, Rectangle * view); -// Label control, shows text +// Label control int mGuiLabel(Rectangle *bounds, const char * text); // Button control, returns true when clicked int mGuiButton(Rectangle *bounds, const char * text); -// Label button control, show true when clicked +// Label button control, returns true when clicked int mGuiLabelButton(Rectangle *bounds, const char * text); -// Toggle Button control, returns true when active +// Toggle Button control int mGuiToggle(Rectangle *bounds, const char * text, bool * active); -// Toggle Group control, returns active toggle index +// Toggle Group control int mGuiToggleGroup(Rectangle *bounds, const char * text, int * active); -// Toggle Slider control, returns true when clicked +// Toggle Slider control int mGuiToggleSlider(Rectangle *bounds, const char * text, int * active); // Check Box control, returns true when active int mGuiCheckBox(Rectangle *bounds, const char * text, bool * checked); -// Combo Box control, returns selected item index +// Combo Box control int mGuiComboBox(Rectangle *bounds, const char * text, int * active); -// Dropdown Box control, returns selected item +// Dropdown Box control int mGuiDropdownBox(Rectangle *bounds, const char * text, int * active, bool editMode); -// Spinner control, returns selected value +// Spinner control int mGuiSpinner(Rectangle *bounds, const char * text, int * value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers @@ -117,13 +117,13 @@ int mGuiValueBox(Rectangle *bounds, const char * text, int * value, int minValue // Text Box control, updates input text int mGuiTextBox(Rectangle *bounds, char * text, int textSize, bool editMode); -// Slider control, returns selected value +// Slider control int mGuiSlider(Rectangle *bounds, const char * textLeft, const char * textRight, float * value, float minValue, float maxValue); -// Slider Bar control, returns selected value +// Slider Bar control int mGuiSliderBar(Rectangle *bounds, const char * textLeft, const char * textRight, float * value, float minValue, float maxValue); -// Progress Bar control, shows current progress value +// Progress Bar control int mGuiProgressBar(Rectangle *bounds, const char * textLeft, const char * textRight, float * value, float minValue, float maxValue); // Status Bar control, shows info text @@ -132,10 +132,10 @@ int mGuiStatusBar(Rectangle *bounds, const char * text); // Dummy control for placeholders int mGuiDummyRec(Rectangle *bounds, const char * text); -// Grid control, returns mouse cell position +// Grid control int mGuiGrid(Rectangle *bounds, const char * text, float spacing, int subdivs, Vector2 * mouseCell); -// List View control, returns selected list item index +// List View control int mGuiListView(Rectangle *bounds, const char * text, int * scrollIndex, int * active); // List View with extended parameters @@ -162,6 +162,6 @@ int mGuiColorBarHue(Rectangle *bounds, const char * text, float * value); // Color Picker control that avoids conversion to RGB on each call (multiple color controls) int mGuiColorPickerHSV(Rectangle *bounds, const char * text, Vector3 * colorHsv); -// Color Panel control that returns HSV color value, used by GuiColorPickerHSV() +// Color Panel control that updates Hue-Saturation-Value color value, used by GuiColorPickerHSV() int mGuiColorPanelHSV(Rectangle *bounds, const char * text, Vector3 * colorHsv); diff --git a/type_mapping.zig b/type_mapping.zig index f53f7c9..ff3c1ef 100644 --- a/type_mapping.zig +++ b/type_mapping.zig @@ -85,7 +85,7 @@ pub const Intermediate = struct { continue :outer; } } - const define = parseRaylibDefine(allocator, d) orelse continue :outer; + const define = try parseRaylibDefine(allocator, d) orelse continue :outer; if (i < defines.items.len) { try defines.insert(i, define); @@ -248,31 +248,38 @@ pub const Define = struct { custom: bool = false, }; -pub fn parseRaylibDefine(allocator: Allocator, s: RaylibDefine) ?Define { +pub fn parseRaylibDefine(allocator: Allocator, s: RaylibDefine) !?Define { var typ: []const u8 = undefined; var value: []const u8 = undefined; + const strValue = try jsonStringify(allocator, s.value); + defer allocator.free(strValue); if (eql("INT", s.type)) { typ = "i32"; - value = std.fmt.allocPrint(allocator, "{s}", .{s.value}) catch return null; + std.debug.print("i32: {s}", .{strValue}); + value = std.fmt.allocPrint(allocator, "{s}", .{strValue}) catch return null; } else if (eql("LONG", s.type)) { typ = "i64"; - value = std.fmt.allocPrint(allocator, "{s}", .{s.value}) catch return null; + std.debug.print("i64: {s}", .{strValue}); + value = std.fmt.allocPrint(allocator, "{s}", .{strValue}) catch return null; } else if (eql("FLOAT", s.type)) { typ = "f32"; - value = std.fmt.allocPrint(allocator, "{s}", .{s.value}) catch return null; + std.debug.print("f32: {s}", .{strValue}); + value = std.fmt.allocPrint(allocator, "{s}", .{strValue}) catch return null; } else if (eql("DOUBLE", s.type)) { typ = "f64"; - value = std.fmt.allocPrint(allocator, "{s}", .{s.value}) catch return null; + std.debug.print("f64: {s}", .{strValue}); + value = std.fmt.allocPrint(allocator, "{s}", .{strValue}) catch return null; } else if (eql("STRING", s.type)) { typ = "[]const u8"; - value = std.fmt.allocPrint(allocator, "\"{s}\"", .{s.value}) catch return null; + std.debug.print("[]const u8: {s}", .{strValue}); + value = std.fmt.allocPrint(allocator, "\"{s}\"", .{strValue}) catch return null; } else if (eql("COLOR", s.type)) { typ = "Color"; - std.debug.assert(startsWith(s.value, "CLITERAL(Color){")); - std.debug.assert(endsWith(s.value, "}")); + std.debug.assert(startsWith(strValue, "CLITERAL(Color){")); + std.debug.assert(endsWith(strValue, "}")); - const componentString = s.value["CLITERAL(Color){".len .. s.value.len - 1]; + const componentString = strValue["CLITERAL(Color){".len .. strValue.len - 1]; var spliterator = std.mem.split(u8, componentString, ","); var r = spliterator.next() orelse return null; r = std.mem.trim(u8, r, " \t\r\n"); @@ -654,7 +661,7 @@ pub const RaylibFunctionParam = struct { pub const RaylibDefine = struct { name: []const u8, type: []const u8, - value: []const u8, + value: std.json.Value, description: ?[]const u8 = null, }; @@ -692,3 +699,8 @@ fn startsWith(haystack: []const u8, needle: []const u8) bool { fn endsWith(haystack: []const u8, needle: []const u8) bool { return std.mem.endsWith(u8, haystack, needle); } + +fn jsonStringify(allocator: Allocator, value: std.json.Value) ![]const u8 { + const jsonString = try json.stringifyAlloc(allocator, value, .{}); + return std.mem.trim(u8, jsonString, "\""); +} From a6ac909d003883eb54583a702eca98d94cd127d2 Mon Sep 17 00:00:00 2001 From: Nikolas Mavropoulos Date: Sun, 31 Mar 2024 14:37:39 +0300 Subject: [PATCH 2/5] fix bindings --- generate.zig | 24 ++-- raygui.zig | 351 +++++++++++++++++++++++++-------------------------- 2 files changed, 187 insertions(+), 188 deletions(-) diff --git a/generate.zig b/generate.zig index fa044f0..987175f 100644 --- a/generate.zig +++ b/generate.zig @@ -177,19 +177,19 @@ 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) { try file.writeAll(try allocPrint(allocator, "var out: {s} = undefined;\n", .{func.returnType})); } - try file.writeAll(try allocPrint(allocator, "raygui.m{s}(\n", .{func.name})); + try file.writeAll(try allocPrint(allocator, "raylib.m{s}(\n", .{func.name})); 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]raylib.{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})); } } @@ -197,16 +197,18 @@ fn writeFunctions( 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})); @@ -214,7 +216,7 @@ fn writeFunctions( } if (isPointer(func.returnType)) { - try file.writeAll("),\n);\n"); + try file.writeAll("),\n));\n"); } else { try file.writeAll(");\n"); } diff --git a/raygui.zig b/raygui.zig index a558502..a8ccbaf 100644 --- a/raygui.zig +++ b/raygui.zig @@ -67,34 +67,34 @@ pub fn GuiDrawIconButton(bounds: raylib.Rectangle, icon: GuiIconName, iconTint: /// Enable gui controls (global state) pub fn GuiEnable() void { - raygui.mGuiEnable(); + raylib.mGuiEnable(); } /// Disable gui controls (global state) pub fn GuiDisable() void { - raygui.mGuiDisable(); + raylib.mGuiDisable(); } /// Lock gui controls (global state) pub fn GuiLock() void { - raygui.mGuiLock(); + raylib.mGuiLock(); } /// Unlock gui controls (global state) pub fn GuiUnlock() void { - raygui.mGuiUnlock(); + raylib.mGuiUnlock(); } /// Check if gui is locked (global state) pub fn GuiIsLocked() bool { - return raygui.mGuiIsLocked(); + return raylib.mGuiIsLocked(); } /// Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f pub fn GuiSetAlpha( alpha: f32, ) void { - raygui.mGuiSetAlpha( + raylib.mGuiSetAlpha( alpha, ); } @@ -103,16 +103,16 @@ pub fn GuiSetAlpha( pub fn GuiSetState( state: GuiState, ) void { - raygui.mGuiSetState( - @enumToInt(state), + raylib.mGuiSetState( + @intFromEnum(state), ); } /// Get gui state (global state) pub fn GuiGetState() GuiState { var out: GuiState = undefined; - raygui.mGuiGetState( - @ptrCast([*c]GuiState, &out), + raylib.mGuiGetState( + @as([*c]GuiState, @ptrCast(&out)), ); return out; } @@ -121,16 +121,16 @@ pub fn GuiGetState() GuiState { pub fn GuiSetFont( font: Font, ) void { - raygui.mGuiSetFont( - @intToPtr([*c]raygui.Font, @ptrToInt(&font)), + raylib.mGuiSetFont( + @as([*c]raygui.Font, @ptrFromInt(@intFromPtr(&font))), ); } /// Get gui custom font (global state) pub fn GuiGetFont() Font { var out: Font = undefined; - raygui.mGuiGetFont( - @ptrCast([*c]raygui.Font, &out), + raylib.mGuiGetFont( + @as([*c]raylib.Font, @ptrCast(&out)), ); return out; } @@ -141,7 +141,7 @@ pub fn GuiSetStyle( property: i32, value: i32, ) void { - raygui.mGuiSetStyle( + raylib.mGuiSetStyle( control, property, value, @@ -153,8 +153,8 @@ pub fn GuiGetStyle( control: GuiControl, property: i32, ) i32 { - return raygui.mGuiGetStyle( - @enumToInt(control), + return raylib.mGuiGetStyle( + @intFromEnum(control), property, ); } @@ -163,32 +163,32 @@ pub fn GuiGetStyle( pub fn GuiLoadStyle( fileName: [*:0]const u8, ) void { - raygui.mGuiLoadStyle( - @intToPtr([*c]const u8, @ptrToInt(fileName)), + raylib.mGuiLoadStyle( + @as([*c]const u8, @ptrFromInt(@intFromPtr(fileName))), ); } /// Load style default over global style pub fn GuiLoadStyleDefault() void { - raygui.mGuiLoadStyleDefault(); + raylib.mGuiLoadStyleDefault(); } /// Enable gui tooltips (global state) pub fn GuiEnableTooltip() void { - raygui.mGuiEnableTooltip(); + raylib.mGuiEnableTooltip(); } /// Disable gui tooltips (global state) pub fn GuiDisableTooltip() void { - raygui.mGuiDisableTooltip(); + raylib.mGuiDisableTooltip(); } /// Set tooltip string pub fn GuiSetTooltip( tooltip: [*:0]const u8, ) void { - raygui.mGuiSetTooltip( - @intToPtr([*c]const u8, @ptrToInt(tooltip)), + raylib.mGuiSetTooltip( + @as([*c]const u8, @ptrFromInt(@intFromPtr(tooltip))), ); } @@ -197,30 +197,28 @@ pub fn GuiIconText( iconId: i32, text: [*:0]const u8, ) [*:0]const u8 { - return @ptrCast( - [*:0]const u8, - raygui.mGuiIconText( + return @as([*:0]const u8, @ptrCast( + raylib.mGuiIconText( iconId, - @intToPtr([*c]const u8, @ptrToInt(text)), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ), - ); + )); } /// Set default icon drawing size pub fn GuiSetIconScale( scale: i32, ) void { - raygui.mGuiSetIconScale( + raylib.mGuiSetIconScale( scale, ); } /// Get raygui icons data pointer pub fn GuiGetIcons() *u32 { - return @ptrCast( - *u32, - raygui.mGuiGetIcons(), - ); + return @as(*u32, @ptrCast( + raylib.mGuiGetIcons(), + )); } /// Load raygui icons file (.rgi) into internal icons data @@ -228,13 +226,12 @@ pub fn GuiLoadIcons( fileName: [*:0]const u8, loadIconsName: bool, ) [*][*:0]u8 { - return @ptrCast( - [*][*:0]u8, - raygui.mGuiLoadIcons( - @intToPtr([*c]const u8, @ptrToInt(fileName)), + return @as([*][*:0]u8, @ptrCast( + raylib.mGuiLoadIcons( + @as([*c]const u8, @ptrFromInt(@intFromPtr(fileName))), loadIconsName, ), - ); + )); } /// Window Box control, shows a window that can be closed @@ -242,9 +239,9 @@ pub fn GuiWindowBox( bounds: Rectangle, title: [*:0]const u8, ) i32 { - return raygui.mGuiWindowBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(title)), + return raylib.mGuiWindowBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), ); } @@ -253,9 +250,9 @@ pub fn GuiGroupBox( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raygui.mGuiGroupBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiGroupBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); } @@ -264,9 +261,9 @@ pub fn GuiLine( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raygui.mGuiLine( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiLine( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); } @@ -275,9 +272,9 @@ pub fn GuiPanel( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raygui.mGuiPanel( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiPanel( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); } @@ -288,11 +285,11 @@ pub fn GuiTabBar( count: i32, active: *i32, ) i32 { - return raygui.mGuiTabBar( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const [*:0]const u8, @ptrToInt(text)), + return raylib.mGuiTabBar( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const [*:0]const u8, @ptrFromInt(@intFromPtr(text))), count, - @ptrCast([*c]i32, active), + @as([*c]i32, @ptrCast(active)), ); } @@ -304,12 +301,12 @@ pub fn GuiScrollPanel( scroll: *Vector2, view: *Rectangle, ) i32 { - return raygui.mGuiScrollPanel( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&content)), - @intToPtr([*c]raygui.Vector2, @ptrToInt(scroll)), - @intToPtr([*c]raygui.Rectangle, @ptrToInt(view)), + return raylib.mGuiScrollPanel( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&content))), + @as([*c]raygui.Vector2, @ptrFromInt(@intFromPtr(scroll))), + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(view))), ); } @@ -318,9 +315,9 @@ pub fn GuiLabel( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raygui.mGuiLabel( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiLabel( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); } @@ -329,9 +326,9 @@ pub fn GuiButton( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raygui.mGuiButton( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiButton( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); } @@ -340,9 +337,9 @@ pub fn GuiLabelButton( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raygui.mGuiLabelButton( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiLabelButton( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); } @@ -352,10 +349,10 @@ pub fn GuiToggle( text: [*:0]const u8, active: *bool, ) i32 { - return raygui.mGuiToggle( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]bool, active), + return raylib.mGuiToggle( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]bool, @ptrCast(active)), ); } @@ -365,10 +362,10 @@ pub fn GuiToggleGroup( text: [*:0]const u8, active: *i32, ) i32 { - return raygui.mGuiToggleGroup( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]i32, active), + return raylib.mGuiToggleGroup( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]i32, @ptrCast(active)), ); } @@ -378,10 +375,10 @@ pub fn GuiToggleSlider( text: [*:0]const u8, active: *i32, ) i32 { - return raygui.mGuiToggleSlider( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]i32, active), + return raylib.mGuiToggleSlider( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]i32, @ptrCast(active)), ); } @@ -391,10 +388,10 @@ pub fn GuiCheckBox( text: [*:0]const u8, checked: *bool, ) i32 { - return raygui.mGuiCheckBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]bool, checked), + return raylib.mGuiCheckBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]bool, @ptrCast(checked)), ); } @@ -404,10 +401,10 @@ pub fn GuiComboBox( text: [*:0]const u8, active: *i32, ) i32 { - return raygui.mGuiComboBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]i32, active), + return raylib.mGuiComboBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]i32, @ptrCast(active)), ); } @@ -418,10 +415,10 @@ pub fn GuiDropdownBox( active: *i32, editMode: bool, ) i32 { - return raygui.mGuiDropdownBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]i32, active), + return raylib.mGuiDropdownBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]i32, @ptrCast(active)), editMode, ); } @@ -435,10 +432,10 @@ pub fn GuiSpinner( maxValue: i32, editMode: bool, ) i32 { - return raygui.mGuiSpinner( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]i32, value), + return raylib.mGuiSpinner( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]i32, @ptrCast(value)), minValue, maxValue, editMode, @@ -454,10 +451,10 @@ pub fn GuiValueBox( maxValue: i32, editMode: bool, ) i32 { - return raygui.mGuiValueBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]i32, value), + return raylib.mGuiValueBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]i32, @ptrCast(value)), minValue, maxValue, editMode, @@ -471,9 +468,9 @@ pub fn GuiTextBox( textSize: i32, editMode: bool, ) i32 { - return raygui.mGuiTextBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @ptrCast([*c]u8, text), + return raylib.mGuiTextBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]u8, @ptrCast(text)), textSize, editMode, ); @@ -488,11 +485,11 @@ pub fn GuiSlider( minValue: f32, maxValue: f32, ) i32 { - return raygui.mGuiSlider( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(textLeft)), - @intToPtr([*c]const u8, @ptrToInt(textRight)), - @ptrCast([*c]f32, value), + return raylib.mGuiSlider( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), + @as([*c]f32, @ptrCast(value)), minValue, maxValue, ); @@ -507,11 +504,11 @@ pub fn GuiSliderBar( minValue: f32, maxValue: f32, ) i32 { - return raygui.mGuiSliderBar( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(textLeft)), - @intToPtr([*c]const u8, @ptrToInt(textRight)), - @ptrCast([*c]f32, value), + return raylib.mGuiSliderBar( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), + @as([*c]f32, @ptrCast(value)), minValue, maxValue, ); @@ -526,11 +523,11 @@ pub fn GuiProgressBar( minValue: f32, maxValue: f32, ) i32 { - return raygui.mGuiProgressBar( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(textLeft)), - @intToPtr([*c]const u8, @ptrToInt(textRight)), - @ptrCast([*c]f32, value), + return raylib.mGuiProgressBar( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), + @as([*c]f32, @ptrCast(value)), minValue, maxValue, ); @@ -541,9 +538,9 @@ pub fn GuiStatusBar( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raygui.mGuiStatusBar( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiStatusBar( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); } @@ -552,9 +549,9 @@ pub fn GuiDummyRec( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raygui.mGuiDummyRec( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiDummyRec( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); } @@ -566,12 +563,12 @@ pub fn GuiGrid( subdivs: i32, mouseCell: *Vector2, ) i32 { - return raygui.mGuiGrid( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), + return raylib.mGuiGrid( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), spacing, subdivs, - @intToPtr([*c]raygui.Vector2, @ptrToInt(mouseCell)), + @as([*c]raygui.Vector2, @ptrFromInt(@intFromPtr(mouseCell))), ); } @@ -582,11 +579,11 @@ pub fn GuiListView( scrollIndex: *i32, active: *i32, ) i32 { - return raygui.mGuiListView( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]i32, scrollIndex), - @ptrCast([*c]i32, active), + return raylib.mGuiListView( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]i32, @ptrCast(scrollIndex)), + @as([*c]i32, @ptrCast(active)), ); } @@ -599,13 +596,13 @@ pub fn GuiListViewEx( active: *i32, focus: *i32, ) i32 { - return raygui.mGuiListViewEx( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const [*:0]const u8, @ptrToInt(text)), + return raylib.mGuiListViewEx( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const [*:0]const u8, @ptrFromInt(@intFromPtr(text))), count, - @ptrCast([*c]i32, scrollIndex), - @ptrCast([*c]i32, active), - @ptrCast([*c]i32, focus), + @as([*c]i32, @ptrCast(scrollIndex)), + @as([*c]i32, @ptrCast(active)), + @as([*c]i32, @ptrCast(focus)), ); } @@ -616,11 +613,11 @@ pub fn GuiMessageBox( message: [*:0]const u8, buttons: [*:0]const u8, ) i32 { - return raygui.mGuiMessageBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(title)), - @intToPtr([*c]const u8, @ptrToInt(message)), - @intToPtr([*c]const u8, @ptrToInt(buttons)), + return raylib.mGuiMessageBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(message))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(buttons))), ); } @@ -634,14 +631,14 @@ pub fn GuiTextInputBox( textMaxSize: i32, secretViewActive: *bool, ) i32 { - return raygui.mGuiTextInputBox( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(title)), - @intToPtr([*c]const u8, @ptrToInt(message)), - @intToPtr([*c]const u8, @ptrToInt(buttons)), - @ptrCast([*c]u8, text), + return raylib.mGuiTextInputBox( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(message))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(buttons))), + @as([*c]u8, @ptrCast(text)), textMaxSize, - @ptrCast([*c]bool, secretViewActive), + @as([*c]bool, @ptrCast(secretViewActive)), ); } @@ -651,10 +648,10 @@ pub fn GuiColorPicker( text: [*:0]const u8, color: *Color, ) i32 { - return raygui.mGuiColorPicker( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @intToPtr([*c]raygui.Color, @ptrToInt(color)), + return raylib.mGuiColorPicker( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]raygui.Color, @ptrFromInt(@intFromPtr(color))), ); } @@ -664,10 +661,10 @@ pub fn GuiColorPanel( text: [*:0]const u8, color: *Color, ) i32 { - return raygui.mGuiColorPanel( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @intToPtr([*c]raygui.Color, @ptrToInt(color)), + return raylib.mGuiColorPanel( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]raygui.Color, @ptrFromInt(@intFromPtr(color))), ); } @@ -677,10 +674,10 @@ pub fn GuiColorBarAlpha( text: [*:0]const u8, alpha: *f32, ) i32 { - return raygui.mGuiColorBarAlpha( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]f32, alpha), + return raylib.mGuiColorBarAlpha( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]f32, @ptrCast(alpha)), ); } @@ -690,10 +687,10 @@ pub fn GuiColorBarHue( text: [*:0]const u8, value: *f32, ) i32 { - return raygui.mGuiColorBarHue( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @ptrCast([*c]f32, value), + return raylib.mGuiColorBarHue( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]f32, @ptrCast(value)), ); } @@ -703,10 +700,10 @@ pub fn GuiColorPickerHSV( text: [*:0]const u8, colorHsv: *Vector3, ) i32 { - return raygui.mGuiColorPickerHSV( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @intToPtr([*c]raygui.Vector3, @ptrToInt(colorHsv)), + return raylib.mGuiColorPickerHSV( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]raygui.Vector3, @ptrFromInt(@intFromPtr(colorHsv))), ); } @@ -716,10 +713,10 @@ pub fn GuiColorPanelHSV( text: [*:0]const u8, colorHsv: *Vector3, ) i32 { - return raygui.mGuiColorPanelHSV( - @intToPtr([*c]raygui.Rectangle, @ptrToInt(&bounds)), - @intToPtr([*c]const u8, @ptrToInt(text)), - @intToPtr([*c]raygui.Vector3, @ptrToInt(colorHsv)), + return raylib.mGuiColorPanelHSV( + @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), + @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), + @as([*c]raygui.Vector3, @ptrFromInt(@intFromPtr(colorHsv))), ); } From eb76574d6181c0acc3d3777862b193f7e9cb3af9 Mon Sep 17 00:00:00 2001 From: Nikolas Mavropoulos Date: Sun, 31 Mar 2024 15:22:46 +0300 Subject: [PATCH 3/5] fix bindings --- generate.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generate.zig b/generate.zig index 987175f..ca4bd3e 100644 --- a/generate.zig +++ b/generate.zig @@ -183,11 +183,11 @@ fn writeFunctions( } else if (!returnTypeIsVoid) { try file.writeAll(try allocPrint(allocator, "var out: {s} = undefined;\n", .{func.returnType})); } - try file.writeAll(try allocPrint(allocator, "raylib.m{s}(\n", .{func.name})); + try file.writeAll(try allocPrint(allocator, "raygui.m{s}(\n", .{func.name})); if (!isPrimitiveOrPointer(func.returnType)) { if (bindings.containsStruct(stripType(func.returnType))) { - try file.writeAll(try allocPrint(allocator, "@as([*c]raylib.{s}, @ptrCast(&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, "@as([*c]{s}, @ptrCast(&out)),\n", .{func.returnType})); } From 8e85b28f7165e22d9e6e1044a45ca1c904fc0c9c Mon Sep 17 00:00:00 2001 From: Nikolas Mavropoulos Date: Sun, 31 Mar 2024 15:23:20 +0300 Subject: [PATCH 4/5] fix bindings --- raygui.zig | 112 ++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/raygui.zig b/raygui.zig index a8ccbaf..27d8066 100644 --- a/raygui.zig +++ b/raygui.zig @@ -67,34 +67,34 @@ pub fn GuiDrawIconButton(bounds: raylib.Rectangle, icon: GuiIconName, iconTint: /// Enable gui controls (global state) pub fn GuiEnable() void { - raylib.mGuiEnable(); + raygui.mGuiEnable(); } /// Disable gui controls (global state) pub fn GuiDisable() void { - raylib.mGuiDisable(); + raygui.mGuiDisable(); } /// Lock gui controls (global state) pub fn GuiLock() void { - raylib.mGuiLock(); + raygui.mGuiLock(); } /// Unlock gui controls (global state) pub fn GuiUnlock() void { - raylib.mGuiUnlock(); + raygui.mGuiUnlock(); } /// Check if gui is locked (global state) pub fn GuiIsLocked() bool { - return raylib.mGuiIsLocked(); + return raygui.mGuiIsLocked(); } /// Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f pub fn GuiSetAlpha( alpha: f32, ) void { - raylib.mGuiSetAlpha( + raygui.mGuiSetAlpha( alpha, ); } @@ -103,7 +103,7 @@ pub fn GuiSetAlpha( pub fn GuiSetState( state: GuiState, ) void { - raylib.mGuiSetState( + raygui.mGuiSetState( @intFromEnum(state), ); } @@ -111,7 +111,7 @@ pub fn GuiSetState( /// Get gui state (global state) pub fn GuiGetState() GuiState { var out: GuiState = undefined; - raylib.mGuiGetState( + raygui.mGuiGetState( @as([*c]GuiState, @ptrCast(&out)), ); return out; @@ -121,7 +121,7 @@ pub fn GuiGetState() GuiState { pub fn GuiSetFont( font: Font, ) void { - raylib.mGuiSetFont( + raygui.mGuiSetFont( @as([*c]raygui.Font, @ptrFromInt(@intFromPtr(&font))), ); } @@ -129,8 +129,8 @@ pub fn GuiSetFont( /// Get gui custom font (global state) pub fn GuiGetFont() Font { var out: Font = undefined; - raylib.mGuiGetFont( - @as([*c]raylib.Font, @ptrCast(&out)), + raygui.mGuiGetFont( + @as([*c]raygui.Font, @ptrCast(&out)), ); return out; } @@ -141,7 +141,7 @@ pub fn GuiSetStyle( property: i32, value: i32, ) void { - raylib.mGuiSetStyle( + raygui.mGuiSetStyle( control, property, value, @@ -153,7 +153,7 @@ pub fn GuiGetStyle( control: GuiControl, property: i32, ) i32 { - return raylib.mGuiGetStyle( + return raygui.mGuiGetStyle( @intFromEnum(control), property, ); @@ -163,31 +163,31 @@ pub fn GuiGetStyle( pub fn GuiLoadStyle( fileName: [*:0]const u8, ) void { - raylib.mGuiLoadStyle( + raygui.mGuiLoadStyle( @as([*c]const u8, @ptrFromInt(@intFromPtr(fileName))), ); } /// Load style default over global style pub fn GuiLoadStyleDefault() void { - raylib.mGuiLoadStyleDefault(); + raygui.mGuiLoadStyleDefault(); } /// Enable gui tooltips (global state) pub fn GuiEnableTooltip() void { - raylib.mGuiEnableTooltip(); + raygui.mGuiEnableTooltip(); } /// Disable gui tooltips (global state) pub fn GuiDisableTooltip() void { - raylib.mGuiDisableTooltip(); + raygui.mGuiDisableTooltip(); } /// Set tooltip string pub fn GuiSetTooltip( tooltip: [*:0]const u8, ) void { - raylib.mGuiSetTooltip( + raygui.mGuiSetTooltip( @as([*c]const u8, @ptrFromInt(@intFromPtr(tooltip))), ); } @@ -198,7 +198,7 @@ pub fn GuiIconText( text: [*:0]const u8, ) [*:0]const u8 { return @as([*:0]const u8, @ptrCast( - raylib.mGuiIconText( + raygui.mGuiIconText( iconId, @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ), @@ -209,7 +209,7 @@ pub fn GuiIconText( pub fn GuiSetIconScale( scale: i32, ) void { - raylib.mGuiSetIconScale( + raygui.mGuiSetIconScale( scale, ); } @@ -217,7 +217,7 @@ pub fn GuiSetIconScale( /// Get raygui icons data pointer pub fn GuiGetIcons() *u32 { return @as(*u32, @ptrCast( - raylib.mGuiGetIcons(), + raygui.mGuiGetIcons(), )); } @@ -227,7 +227,7 @@ pub fn GuiLoadIcons( loadIconsName: bool, ) [*][*:0]u8 { return @as([*][*:0]u8, @ptrCast( - raylib.mGuiLoadIcons( + raygui.mGuiLoadIcons( @as([*c]const u8, @ptrFromInt(@intFromPtr(fileName))), loadIconsName, ), @@ -239,7 +239,7 @@ pub fn GuiWindowBox( bounds: Rectangle, title: [*:0]const u8, ) i32 { - return raylib.mGuiWindowBox( + return raygui.mGuiWindowBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), ); @@ -250,7 +250,7 @@ pub fn GuiGroupBox( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raylib.mGuiGroupBox( + return raygui.mGuiGroupBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); @@ -261,7 +261,7 @@ pub fn GuiLine( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raylib.mGuiLine( + return raygui.mGuiLine( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); @@ -272,7 +272,7 @@ pub fn GuiPanel( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raylib.mGuiPanel( + return raygui.mGuiPanel( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); @@ -285,7 +285,7 @@ pub fn GuiTabBar( count: i32, active: *i32, ) i32 { - return raylib.mGuiTabBar( + return raygui.mGuiTabBar( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const [*:0]const u8, @ptrFromInt(@intFromPtr(text))), count, @@ -301,7 +301,7 @@ pub fn GuiScrollPanel( scroll: *Vector2, view: *Rectangle, ) i32 { - return raylib.mGuiScrollPanel( + return raygui.mGuiScrollPanel( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&content))), @@ -315,7 +315,7 @@ pub fn GuiLabel( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raylib.mGuiLabel( + return raygui.mGuiLabel( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); @@ -326,7 +326,7 @@ pub fn GuiButton( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raylib.mGuiButton( + return raygui.mGuiButton( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); @@ -337,7 +337,7 @@ pub fn GuiLabelButton( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raylib.mGuiLabelButton( + return raygui.mGuiLabelButton( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); @@ -349,7 +349,7 @@ pub fn GuiToggle( text: [*:0]const u8, active: *bool, ) i32 { - return raylib.mGuiToggle( + return raygui.mGuiToggle( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]bool, @ptrCast(active)), @@ -362,7 +362,7 @@ pub fn GuiToggleGroup( text: [*:0]const u8, active: *i32, ) i32 { - return raylib.mGuiToggleGroup( + return raygui.mGuiToggleGroup( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]i32, @ptrCast(active)), @@ -375,7 +375,7 @@ pub fn GuiToggleSlider( text: [*:0]const u8, active: *i32, ) i32 { - return raylib.mGuiToggleSlider( + return raygui.mGuiToggleSlider( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]i32, @ptrCast(active)), @@ -388,7 +388,7 @@ pub fn GuiCheckBox( text: [*:0]const u8, checked: *bool, ) i32 { - return raylib.mGuiCheckBox( + return raygui.mGuiCheckBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]bool, @ptrCast(checked)), @@ -401,7 +401,7 @@ pub fn GuiComboBox( text: [*:0]const u8, active: *i32, ) i32 { - return raylib.mGuiComboBox( + return raygui.mGuiComboBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]i32, @ptrCast(active)), @@ -415,7 +415,7 @@ pub fn GuiDropdownBox( active: *i32, editMode: bool, ) i32 { - return raylib.mGuiDropdownBox( + return raygui.mGuiDropdownBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]i32, @ptrCast(active)), @@ -432,7 +432,7 @@ pub fn GuiSpinner( maxValue: i32, editMode: bool, ) i32 { - return raylib.mGuiSpinner( + return raygui.mGuiSpinner( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]i32, @ptrCast(value)), @@ -451,7 +451,7 @@ pub fn GuiValueBox( maxValue: i32, editMode: bool, ) i32 { - return raylib.mGuiValueBox( + return raygui.mGuiValueBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]i32, @ptrCast(value)), @@ -468,7 +468,7 @@ pub fn GuiTextBox( textSize: i32, editMode: bool, ) i32 { - return raylib.mGuiTextBox( + return raygui.mGuiTextBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]u8, @ptrCast(text)), textSize, @@ -485,7 +485,7 @@ pub fn GuiSlider( minValue: f32, maxValue: f32, ) i32 { - return raylib.mGuiSlider( + return raygui.mGuiSlider( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), @@ -504,7 +504,7 @@ pub fn GuiSliderBar( minValue: f32, maxValue: f32, ) i32 { - return raylib.mGuiSliderBar( + return raygui.mGuiSliderBar( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), @@ -523,7 +523,7 @@ pub fn GuiProgressBar( minValue: f32, maxValue: f32, ) i32 { - return raylib.mGuiProgressBar( + return raygui.mGuiProgressBar( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(textLeft))), @as([*c]const u8, @ptrFromInt(@intFromPtr(textRight))), @@ -538,7 +538,7 @@ pub fn GuiStatusBar( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raylib.mGuiStatusBar( + return raygui.mGuiStatusBar( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); @@ -549,7 +549,7 @@ pub fn GuiDummyRec( bounds: Rectangle, text: [*:0]const u8, ) i32 { - return raylib.mGuiDummyRec( + return raygui.mGuiDummyRec( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), ); @@ -563,7 +563,7 @@ pub fn GuiGrid( subdivs: i32, mouseCell: *Vector2, ) i32 { - return raylib.mGuiGrid( + return raygui.mGuiGrid( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), spacing, @@ -579,7 +579,7 @@ pub fn GuiListView( scrollIndex: *i32, active: *i32, ) i32 { - return raylib.mGuiListView( + return raygui.mGuiListView( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]i32, @ptrCast(scrollIndex)), @@ -596,7 +596,7 @@ pub fn GuiListViewEx( active: *i32, focus: *i32, ) i32 { - return raylib.mGuiListViewEx( + return raygui.mGuiListViewEx( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const [*:0]const u8, @ptrFromInt(@intFromPtr(text))), count, @@ -613,7 +613,7 @@ pub fn GuiMessageBox( message: [*:0]const u8, buttons: [*:0]const u8, ) i32 { - return raylib.mGuiMessageBox( + return raygui.mGuiMessageBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), @as([*c]const u8, @ptrFromInt(@intFromPtr(message))), @@ -631,7 +631,7 @@ pub fn GuiTextInputBox( textMaxSize: i32, secretViewActive: *bool, ) i32 { - return raylib.mGuiTextInputBox( + return raygui.mGuiTextInputBox( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(title))), @as([*c]const u8, @ptrFromInt(@intFromPtr(message))), @@ -648,7 +648,7 @@ pub fn GuiColorPicker( text: [*:0]const u8, color: *Color, ) i32 { - return raylib.mGuiColorPicker( + return raygui.mGuiColorPicker( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]raygui.Color, @ptrFromInt(@intFromPtr(color))), @@ -661,7 +661,7 @@ pub fn GuiColorPanel( text: [*:0]const u8, color: *Color, ) i32 { - return raylib.mGuiColorPanel( + return raygui.mGuiColorPanel( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]raygui.Color, @ptrFromInt(@intFromPtr(color))), @@ -674,7 +674,7 @@ pub fn GuiColorBarAlpha( text: [*:0]const u8, alpha: *f32, ) i32 { - return raylib.mGuiColorBarAlpha( + return raygui.mGuiColorBarAlpha( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]f32, @ptrCast(alpha)), @@ -687,7 +687,7 @@ pub fn GuiColorBarHue( text: [*:0]const u8, value: *f32, ) i32 { - return raylib.mGuiColorBarHue( + return raygui.mGuiColorBarHue( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]f32, @ptrCast(value)), @@ -700,7 +700,7 @@ pub fn GuiColorPickerHSV( text: [*:0]const u8, colorHsv: *Vector3, ) i32 { - return raylib.mGuiColorPickerHSV( + return raygui.mGuiColorPickerHSV( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]raygui.Vector3, @ptrFromInt(@intFromPtr(colorHsv))), @@ -713,7 +713,7 @@ pub fn GuiColorPanelHSV( text: [*:0]const u8, colorHsv: *Vector3, ) i32 { - return raylib.mGuiColorPanelHSV( + return raygui.mGuiColorPanelHSV( @as([*c]raygui.Rectangle, @ptrFromInt(@intFromPtr(&bounds))), @as([*c]const u8, @ptrFromInt(@intFromPtr(text))), @as([*c]raygui.Vector3, @ptrFromInt(@intFromPtr(colorHsv))), From f51c12783a3ac7feecf81ee2f597a5be9577925a Mon Sep 17 00:00:00 2001 From: Nikolas Mavropoulos Date: Sun, 31 Mar 2024 18:55:45 +0300 Subject: [PATCH 5/5] fixed build --- build.zig | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/build.zig b/build.zig index feb0695..e1962c3 100644 --- a/build.zig +++ b/build.zig @@ -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", .{}); }