feat(raygui): get message box example working

This commit is contained in:
Daniel Hill 2025-04-19 14:33:51 -04:00 committed by Nikolas
parent d6c77762cb
commit f4b69764db
6 changed files with 616 additions and 577 deletions

View File

@ -167,6 +167,11 @@ pub fn build(b: *std.Build) !void {
.path = "examples/core/window_flags.zig",
.desc = "Demonstrates various flags used during and after window creation",
},
.{
.name = "gui_message_box",
.path = "examples/gui/message_box.zig",
.desc = "Demonstrates showing and hiding a message box",
},
.{
.name = "raymarching",
.path = "examples/shaders/raymarching.zig",

View File

@ -0,0 +1,55 @@
//! # raylib-zig [gui] example - message box
//!
//! Example originally created with raylib-zig 5.6-dev, last time updated with
//! raylib-zig 5.6-dev
//!
//! Example licensed under an unmodified zlib/libpng license, which is an
//! OSI-certified, BSD-like license that allows static linking with closed
//! source software
//!
//! Copyright (c) Nikolas Wipper 2025
const std = @import("std");
const rl = @import("raylib");
const rg = @import("raygui");
// `rl.getColor` only accepts a `u32`. Performing `@intCast` on the return value
// of `rg.getStyle` invokes checked undefined behavior from Zig when passed to
// `rl.getColor`, hence the custom implementation here...
fn getColor(hex: i32) rl.Color {
var color: rl.Color = .black;
// zig fmt: off
color.r = @intCast((hex >> 24) & 0xFF);
color.g = @intCast((hex >> 16) & 0xFF);
color.b = @intCast((hex >> 8) & 0xFF);
color.a = @intCast((hex >> 0) & 0xFF);
// zig fmt: on
return color;
}
pub fn main() !void {
rl.initWindow(400, 200, "raygui - controls test suite");
defer rl.closeWindow();
rl.setTargetFPS(60);
var show_message_box = false;
const color_int = rg.getStyle(.default, .{ .default = .background_color });
while (!rl.windowShouldClose()) {
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(getColor(color_int));
if (rg.guiButton(.init(24, 24, 120, 30), "#191#Show Message") > 0) show_message_box = true;
if (show_message_box) {
const result = rg.guiMessageBox(.init(85, 70, 250, 100), "#191#Message Box", "Hi! This is a message", "Nice;Cool");
if (result >= 0) show_message_box = false;
}
}
}

View File

@ -192,7 +192,8 @@ def add_namespace_to_type(t: str) -> str:
pre += "const "
if t.startswith("Gui"):
t = "rgui." + t
# Strip "Gui" prefix to match types in prelude
t = "rgui." + t[3:]
elif t[0].isupper():
t = "rl." + t
elif t in ["float3", "float16"]:
@ -258,8 +259,8 @@ _fix_enums_data = [
("button", "GamepadButton", r".*GamepadButton.*"),
("axis", "GamepadAxis", r".*GamepadAxis.*"),
("button", "MouseButton", r".*MouseButton.*"),
("control", "GuiControl", r"Gui.etStyle"),
# ("property", "GuiControlProperty", r"Gui.etStyle"),
("control", "GuiControl", r"Gui.etStyle"), # "Gui" prefix needed here for type parsing later
# ("property", "GuiControlProperty", r"Gui.etStyle"), # "Gui" prefix needed here for type parsing later
]
def fix_enums(arg_name, arg_type, func_name):
if func_name.startswith("rl"):

View File

@ -15,38 +15,38 @@ const Color = rl.Color;
const Rectangle = rl.Rectangle;
const Font = rl.Font;
pub const GuiStyleProp = extern struct {
pub const StyleProp = extern struct {
controlId: c_ushort,
propertyId: c_ushort,
propertyValue: c_int,
};
pub const GuiState = enum(c_int) {
state_normal = 0,
state_focused,
state_pressed,
state_disabled,
pub const State = enum(c_int) {
normal = 0,
focused,
pressed,
disabled,
};
pub const GuiTextAlignment = enum(c_int) {
text_align_left = 0,
text_align_center,
text_align_right,
pub const TextAlignment = enum(c_int) {
left = 0,
center,
right,
};
pub const GuiTextAlignmentVertical = enum(c_int) {
text_align_top = 0,
text_align_middle,
text_align_bottom,
pub const TextAlignmentVertical = enum(c_int) {
top = 0,
middle,
bottom,
};
pub const GuiTextWrapMode = enum(c_int) {
text_wrap_none = 0,
text_wrap_char,
text_wrap_word,
pub const TextWrapMode = enum(c_int) {
none = 0,
char,
word,
};
pub const GuiControl = enum(c_int) {
pub const Control = enum(c_int) {
default = 0,
label,
button,
@ -65,7 +65,7 @@ pub const GuiControl = enum(c_int) {
statusbar,
};
pub const GuiControlProperty = enum(c_int) {
pub const ControlProperty = enum(c_int) {
border_color_normal = 0,
base_color_normal,
text_color_normal,
@ -83,7 +83,7 @@ pub const GuiControlProperty = enum(c_int) {
text_alignment,
};
pub const GuiDefaultProperty = enum(c_int) {
pub const DefaultProperty = enum(c_int) {
text_size = 16,
text_spacing,
line_color,
@ -93,20 +93,25 @@ pub const GuiDefaultProperty = enum(c_int) {
text_wrap_mode,
};
pub const GuiToggleProperty = enum(c_int) {
pub const ControlOrDefaultProperty = union(enum) {
control: ControlProperty,
default: DefaultProperty,
};
pub const ToggleProperty = enum(c_int) {
group_padding = 16,
};
pub const GuiSliderProperty = enum(c_int) {
pub const SliderProperty = enum(c_int) {
slider_width = 16,
slider_padding,
};
pub const GuiProgressBarProperty = enum(c_int) {
pub const ProgressBarProperty = enum(c_int) {
progress_padding = 16,
};
pub const GuiScrollBarProperty = enum(c_int) {
pub const ScrollBarProperty = enum(c_int) {
arrows_size = 16,
arrows_visible,
scroll_slider_padding,
@ -115,32 +120,32 @@ pub const GuiScrollBarProperty = enum(c_int) {
scroll_speed,
};
pub const GuiCheckBoxProperty = enum(c_int) {
pub const CheckBoxProperty = enum(c_int) {
check_padding = 16,
};
pub const GuiComboBoxProperty = enum(c_int) {
pub const ComboBoxProperty = enum(c_int) {
combo_button_width = 16,
combo_button_spacing,
};
pub const GuiDropdownBoxProperty = enum(c_int) {
pub const DropdownBoxProperty = enum(c_int) {
arrow_padding = 16,
dropdown_items_spacing,
dropdown_arrow_hidden,
dropdown_roll_up,
};
pub const GuiTextBoxProperty = enum(c_int) {
pub const TextBoxProperty = enum(c_int) {
text_readonly = 16,
};
pub const GuiValueBoxProperty = enum(c_int) {
pub const ValueBoxProperty = enum(c_int) {
spin_button_width = 16,
spin_button_spacing,
};
pub const GuiListViewProperty = enum(c_int) {
pub const ListViewProperty = enum(c_int) {
list_items_height = 16,
list_items_spacing,
scrollbar_width,
@ -149,7 +154,7 @@ pub const GuiListViewProperty = enum(c_int) {
list_items_border_width,
};
pub const GuiColorPickerProperty = enum(c_int) {
pub const ColorPickerProperty = enum(c_int) {
color_selector_size = 16,
huebar_width,
huebar_padding,
@ -160,230 +165,230 @@ pub const GuiColorPickerProperty = enum(c_int) {
pub const scrollbar_left_side: c_int = 0;
pub const scrollbar_right_side: c_int = 1;
pub const GuiIconName = enum(c_int) {
icon_none = 0,
icon_folder_file_open = 1,
icon_file_save_classic = 2,
icon_folder_open = 3,
icon_folder_save = 4,
icon_file_open = 5,
icon_file_save = 6,
icon_file_export = 7,
icon_file_add = 8,
icon_file_delete = 9,
icon_filetype_text = 10,
icon_filetype_audio = 11,
icon_filetype_image = 12,
icon_filetype_play = 13,
icon_filetype_video = 14,
icon_filetype_info = 15,
icon_file_copy = 16,
icon_file_cut = 17,
icon_file_paste = 18,
icon_cursor_hand = 19,
icon_cursor_pointer = 20,
icon_cursor_classic = 21,
icon_pencil = 22,
icon_pencil_big = 23,
icon_brush_classic = 24,
icon_brush_painter = 25,
icon_water_drop = 26,
icon_color_picker = 27,
icon_rubber = 28,
icon_color_bucket = 29,
icon_text_t = 30,
icon_text_a = 31,
icon_scale = 32,
icon_resize = 33,
icon_filter_point = 34,
icon_filter_bilinear = 35,
icon_crop = 36,
icon_crop_alpha = 37,
icon_square_toggle = 38,
icon_symmetry = 39,
icon_symmetry_horizontal = 40,
icon_symmetry_vertical = 41,
icon_lens = 42,
icon_lens_big = 43,
icon_eye_on = 44,
icon_eye_off = 45,
icon_filter_top = 46,
icon_filter = 47,
icon_target_point = 48,
icon_target_small = 49,
icon_target_big = 50,
icon_target_move = 51,
icon_cursor_move = 52,
icon_cursor_scale = 53,
icon_cursor_scale_right = 54,
icon_cursor_scale_left = 55,
icon_undo = 56,
icon_redo = 57,
icon_reredo = 58,
icon_mutate = 59,
icon_rotate = 60,
icon_repeat = 61,
icon_shuffle = 62,
icon_emptybox = 63,
icon_target = 64,
icon_target_small_fill = 65,
icon_target_big_fill = 66,
icon_target_move_fill = 67,
icon_cursor_move_fill = 68,
icon_cursor_scale_fill = 69,
icon_cursor_scale_right_fill = 70,
icon_cursor_scale_left_fill = 71,
icon_undo_fill = 72,
icon_redo_fill = 73,
icon_reredo_fill = 74,
icon_mutate_fill = 75,
icon_rotate_fill = 76,
icon_repeat_fill = 77,
icon_shuffle_fill = 78,
icon_emptybox_small = 79,
icon_box = 80,
icon_box_top = 81,
icon_box_top_right = 82,
icon_box_right = 83,
icon_box_bottom_right = 84,
icon_box_bottom = 85,
icon_box_bottom_left = 86,
icon_box_left = 87,
icon_box_top_left = 88,
icon_box_center = 89,
icon_box_circle_mask = 90,
icon_pot = 91,
icon_alpha_multiply = 92,
icon_alpha_clear = 93,
icon_dithering = 94,
icon_mipmaps = 95,
icon_box_grid = 96,
icon_grid = 97,
icon_box_corners_small = 98,
icon_box_corners_big = 99,
icon_four_boxes = 100,
icon_grid_fill = 101,
icon_box_multisize = 102,
icon_zoom_small = 103,
icon_zoom_medium = 104,
icon_zoom_big = 105,
icon_zoom_all = 106,
icon_zoom_center = 107,
icon_box_dots_small = 108,
icon_box_dots_big = 109,
icon_box_concentric = 110,
icon_box_grid_big = 111,
icon_ok_tick = 112,
icon_cross = 113,
icon_arrow_left = 114,
icon_arrow_right = 115,
icon_arrow_down = 116,
icon_arrow_up = 117,
icon_arrow_left_fill = 118,
icon_arrow_right_fill = 119,
icon_arrow_down_fill = 120,
icon_arrow_up_fill = 121,
icon_audio = 122,
icon_fx = 123,
icon_wave = 124,
icon_wave_sinus = 125,
icon_wave_square = 126,
icon_wave_triangular = 127,
icon_cross_small = 128,
icon_player_previous = 129,
icon_player_play_back = 130,
icon_player_play = 131,
icon_player_pause = 132,
icon_player_stop = 133,
icon_player_next = 134,
icon_player_record = 135,
icon_magnet = 136,
icon_lock_close = 137,
icon_lock_open = 138,
icon_clock = 139,
icon_tools = 140,
icon_gear = 141,
icon_gear_big = 142,
icon_bin = 143,
icon_hand_pointer = 144,
icon_laser = 145,
icon_coin = 146,
icon_explosion = 147,
icon_1up = 148,
icon_player = 149,
icon_player_jump = 150,
icon_key = 151,
icon_demon = 152,
icon_text_popup = 153,
icon_gear_ex = 154,
icon_crack = 155,
icon_crack_points = 156,
icon_star = 157,
icon_door = 158,
icon_exit = 159,
icon_mode_2d = 160,
icon_mode_3d = 161,
icon_cube = 162,
icon_cube_face_top = 163,
icon_cube_face_left = 164,
icon_cube_face_front = 165,
icon_cube_face_bottom = 166,
icon_cube_face_right = 167,
icon_cube_face_back = 168,
icon_camera = 169,
icon_special = 170,
icon_link_net = 171,
icon_link_boxes = 172,
icon_link_multi = 173,
icon_link = 174,
icon_link_broke = 175,
icon_text_notes = 176,
icon_notebook = 177,
icon_suitcase = 178,
icon_suitcase_zip = 179,
icon_mailbox = 180,
icon_monitor = 181,
icon_printer = 182,
icon_photo_camera = 183,
icon_photo_camera_flash = 184,
icon_house = 185,
icon_heart = 186,
icon_corner = 187,
icon_vertical_bars = 188,
icon_vertical_bars_fill = 189,
icon_life_bars = 190,
icon_info = 191,
icon_crossline = 192,
icon_help = 193,
icon_filetype_alpha = 194,
icon_filetype_home = 195,
icon_layers_visible = 196,
icon_layers = 197,
icon_window = 198,
icon_hidpi = 199,
icon_filetype_binary = 200,
icon_hex = 201,
icon_shield = 202,
icon_file_new = 203,
icon_folder_add = 204,
icon_alarm = 205,
icon_cpu = 206,
icon_rom = 207,
icon_step_over = 208,
icon_step_into = 209,
icon_step_out = 210,
icon_restart = 211,
icon_breakpoint_on = 212,
icon_breakpoint_off = 213,
icon_burger_menu = 214,
icon_case_sensitive = 215,
icon_reg_exp = 216,
icon_folder = 217,
icon_file = 218,
icon_sand_timer = 219,
icon_warning = 220,
icon_help_box = 221,
icon_info_box = 222,
pub const IconName = enum(c_int) {
none = 0,
folder_file_open = 1,
file_save_classic = 2,
folder_open = 3,
folder_save = 4,
file_open = 5,
file_save = 6,
file_export = 7,
file_add = 8,
file_delete = 9,
filetype_text = 10,
filetype_audio = 11,
filetype_image = 12,
filetype_play = 13,
filetype_video = 14,
filetype_info = 15,
file_copy = 16,
file_cut = 17,
file_paste = 18,
cursor_hand = 19,
cursor_pointer = 20,
cursor_classic = 21,
pencil = 22,
pencil_big = 23,
brush_classic = 24,
brush_painter = 25,
water_drop = 26,
color_picker = 27,
rubber = 28,
color_bucket = 29,
text_t = 30,
text_a = 31,
scale = 32,
resize = 33,
filter_point = 34,
filter_bilinear = 35,
crop = 36,
crop_alpha = 37,
square_toggle = 38,
symmetry = 39,
symmetry_horizontal = 40,
symmetry_vertical = 41,
lens = 42,
lens_big = 43,
eye_on = 44,
eye_off = 45,
filter_top = 46,
filter = 47,
target_point = 48,
target_small = 49,
target_big = 50,
target_move = 51,
cursor_move = 52,
cursor_scale = 53,
cursor_scale_right = 54,
cursor_scale_left = 55,
undo = 56,
redo = 57,
reredo = 58,
mutate = 59,
rotate = 60,
repeat = 61,
shuffle = 62,
emptybox = 63,
target = 64,
target_small_fill = 65,
target_big_fill = 66,
target_move_fill = 67,
cursor_move_fill = 68,
cursor_scale_fill = 69,
cursor_scale_right_fill = 70,
cursor_scale_left_fill = 71,
undo_fill = 72,
redo_fill = 73,
reredo_fill = 74,
mutate_fill = 75,
rotate_fill = 76,
repeat_fill = 77,
shuffle_fill = 78,
emptybox_small = 79,
box = 80,
box_top = 81,
box_top_right = 82,
box_right = 83,
box_bottom_right = 84,
box_bottom = 85,
box_bottom_left = 86,
box_left = 87,
box_top_left = 88,
box_center = 89,
box_circle_mask = 90,
pot = 91,
alpha_multiply = 92,
alpha_clear = 93,
dithering = 94,
mipmaps = 95,
box_grid = 96,
grid = 97,
box_corners_small = 98,
box_corners_big = 99,
four_boxes = 100,
grid_fill = 101,
box_multisize = 102,
zoom_small = 103,
zoom_medium = 104,
zoom_big = 105,
zoom_all = 106,
zoom_center = 107,
box_dots_small = 108,
box_dots_big = 109,
box_concentric = 110,
box_grid_big = 111,
ok_tick = 112,
cross = 113,
arrow_left = 114,
arrow_right = 115,
arrow_down = 116,
arrow_up = 117,
arrow_left_fill = 118,
arrow_right_fill = 119,
arrow_down_fill = 120,
arrow_up_fill = 121,
audio = 122,
fx = 123,
wave = 124,
wave_sinus = 125,
wave_square = 126,
wave_triangular = 127,
cross_small = 128,
player_previous = 129,
player_play_back = 130,
player_play = 131,
player_pause = 132,
player_stop = 133,
player_next = 134,
player_record = 135,
magnet = 136,
lock_close = 137,
lock_open = 138,
clock = 139,
tools = 140,
gear = 141,
gear_big = 142,
bin = 143,
hand_pointer = 144,
laser = 145,
coin = 146,
explosion = 147,
@"1up" = 148,
player = 149,
player_jump = 150,
key = 151,
demon = 152,
text_popup = 153,
gear_ex = 154,
crack = 155,
crack_points = 156,
star = 157,
door = 158,
exit = 159,
mode_2d = 160,
mode_3d = 161,
cube = 162,
cube_face_top = 163,
cube_face_left = 164,
cube_face_front = 165,
cube_face_bottom = 166,
cube_face_right = 167,
cube_face_back = 168,
camera = 169,
special = 170,
link_net = 171,
link_boxes = 172,
link_multi = 173,
link = 174,
link_broke = 175,
text_notes = 176,
notebook = 177,
suitcase = 178,
suitcase_zip = 179,
mailbox = 180,
monitor = 181,
printer = 182,
photo_camera = 183,
photo_camera_flash = 184,
house = 185,
heart = 186,
corner = 187,
vertical_bars = 188,
vertical_bars_fill = 189,
life_bars = 190,
info = 191,
crossline = 192,
help = 193,
filetype_alpha = 194,
filetype_home = 195,
layers_visible = 196,
layers = 197,
window = 198,
hidpi = 199,
filetype_binary = 200,
hex = 201,
shield = 202,
file_new = 203,
folder_add = 204,
alarm = 205,
cpu = 206,
rom = 207,
step_over = 208,
step_into = 209,
step_out = 210,
restart = 211,
breakpoint_on = 212,
breakpoint_off = 213,
burger_menu = 214,
case_sensitive = 215,
reg_exp = 216,
folder = 217,
file = 218,
sand_timer = 219,
warning = 220,
help_box = 221,
info_box = 222,
icon_223 = 223,
icon_224 = 224,
icon_225 = 225,
@ -420,41 +425,25 @@ pub const GuiIconName = enum(c_int) {
};
/// 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");
}
}
pub fn setStyle(control: Control, comptime property: ControlOrDefaultProperty, value: i32) void {
const property_int: c_int = switch (property) {
inline else => |val| @intCast(@intFromEnum(val))
};
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");
}
}
pub fn getStyle(control: Control, comptime property: ControlOrDefaultProperty) i32 {
const property_int: c_int = switch (property) {
inline else => |val| @intCast(@intFromEnum(val))
};
return @as(i32, cdef.GuiGetStyle(control, property_int));
}
/// Get raygui icons data pointer
pub fn guiGetIcons() RayguiError![]u32 {
pub fn getIcons() RayguiError![]u32 {
var res: []u32 = undefined;
const ptr = cdef.GuiGetIcons();
@ -467,22 +456,22 @@ pub fn guiGetIcons() RayguiError![]u32 {
// If you REALLY need the return value of the function, you'll know what to do with it and its size yourself
/// Load raygui icons file (.rgi) into internal icons data
pub fn guiLoadIcons(fileName: [*c]const u8, loadIconsName: bool) [*c][*c]u8 {
pub fn loadIcons(fileName: [*c]const u8, loadIconsName: bool) [*c][*c]u8 {
return cdef.GuiLoadIcons(fileName, loadIconsName);
}
/// Tab Bar control, returns TAB to be closed or -1
pub fn guiTabBar(bounds: Rectangle, text: [][*:0]const u8, active: *i32) i32 {
pub fn tabBar(bounds: Rectangle, text: [][*:0]const u8, active: *i32) i32 {
return @as(i32, cdef.GuiTabBar(bounds, @as([*c][*c]const u8, @ptrCast(text)), @as(c_int, @intCast(text.len)), @as([*c]c_int, @ptrCast(active))));
}
/// List View with extended parameters
pub fn guiListViewEx(bounds: Rectangle, text: [][*:0]const u8, scrollIndex: *i32, active: *i32, focus: *i32) i32 {
pub fn listViewEx(bounds: Rectangle, text: [][*:0]const u8, scrollIndex: *i32, active: *i32, focus: *i32) i32 {
return @as(i32, cdef.GuiListViewEx(bounds, @as([*c][*c]const u8, @ptrCast(text)), @as(c_int, @intCast(text.len)), @as([*c]c_int, @ptrCast(scrollIndex)), @as([*c]c_int, @ptrCast(active)), @as([*c]c_int, @ptrCast(focus))));
}
/// Panel control, useful to group controls
pub fn guiPanel(bounds: Rectangle, text: ?[*:0]const u8) i32 {
pub fn panel(bounds: Rectangle, text: ?[*:0]const u8) i32 {
var textFinal = @as([*c]const u8, 0);
if (text) |textSure| {
textFinal = @as([*c]const u8, @ptrCast(textSure));
@ -491,7 +480,7 @@ pub fn guiPanel(bounds: Rectangle, text: ?[*:0]const u8) i32 {
}
/// Scroll Panel control
pub fn guiScrollPanel(bounds: Rectangle, text: ?[*:0]const u8, content: Rectangle, scroll: *Vector2, view: *Rectangle) i32 {
pub fn scrollPanel(bounds: Rectangle, text: ?[*:0]const u8, content: Rectangle, scroll: *Vector2, view: *Rectangle) i32 {
var textFinal = @as([*c]const u8, 0);
if (text) |textSure| {
textFinal = @as([*c]const u8, @ptrCast(textSure));

View File

@ -13,8 +13,8 @@ pub extern "c" fn GuiSetState(state: c_int) void;
pub extern "c" fn GuiGetState() c_int;
pub extern "c" fn GuiSetFont(font: rl.Font) void;
pub extern "c" fn GuiGetFont() rl.Font;
pub extern "c" fn GuiSetStyle(control: rgui.GuiControl, property: c_int, value: c_int) void;
pub extern "c" fn GuiGetStyle(control: rgui.GuiControl, property: c_int) c_int;
pub extern "c" fn GuiSetStyle(control: rgui.Control, property: c_int, value: c_int) void;
pub extern "c" fn GuiGetStyle(control: rgui.Control, property: c_int) c_int;
pub extern "c" fn GuiLoadStyle(fileName: [*c]const u8) void;
pub extern "c" fn GuiLoadStyleDefault() void;
pub extern "c" fn GuiEnableTooltip() void;

View File

@ -15,38 +15,38 @@ const Color = rl.Color;
const Rectangle = rl.Rectangle;
const Font = rl.Font;
pub const GuiStyleProp = extern struct {
pub const StyleProp = extern struct {
controlId: c_ushort,
propertyId: c_ushort,
propertyValue: c_int,
};
pub const GuiState = enum(c_int) {
state_normal = 0,
state_focused,
state_pressed,
state_disabled,
pub const State = enum(c_int) {
normal = 0,
focused,
pressed,
disabled,
};
pub const GuiTextAlignment = enum(c_int) {
text_align_left = 0,
text_align_center,
text_align_right,
pub const TextAlignment = enum(c_int) {
left = 0,
center,
right,
};
pub const GuiTextAlignmentVertical = enum(c_int) {
text_align_top = 0,
text_align_middle,
text_align_bottom,
pub const TextAlignmentVertical = enum(c_int) {
top = 0,
middle,
bottom,
};
pub const GuiTextWrapMode = enum(c_int) {
text_wrap_none = 0,
text_wrap_char,
text_wrap_word,
pub const TextWrapMode = enum(c_int) {
none = 0,
char,
word,
};
pub const GuiControl = enum(c_int) {
pub const Control = enum(c_int) {
default = 0,
label,
button,
@ -65,7 +65,7 @@ pub const GuiControl = enum(c_int) {
statusbar,
};
pub const GuiControlProperty = enum(c_int) {
pub const ControlProperty = enum(c_int) {
border_color_normal = 0,
base_color_normal,
text_color_normal,
@ -83,7 +83,7 @@ pub const GuiControlProperty = enum(c_int) {
text_alignment,
};
pub const GuiDefaultProperty = enum(c_int) {
pub const DefaultProperty = enum(c_int) {
text_size = 16,
text_spacing,
line_color,
@ -93,20 +93,25 @@ pub const GuiDefaultProperty = enum(c_int) {
text_wrap_mode,
};
pub const GuiToggleProperty = enum(c_int) {
pub const ControlOrDefaultProperty = union(enum) {
control: ControlProperty,
default: DefaultProperty,
};
pub const ToggleProperty = enum(c_int) {
group_padding = 16,
};
pub const GuiSliderProperty = enum(c_int) {
pub const SliderProperty = enum(c_int) {
slider_width = 16,
slider_padding,
};
pub const GuiProgressBarProperty = enum(c_int) {
pub const ProgressBarProperty = enum(c_int) {
progress_padding = 16,
};
pub const GuiScrollBarProperty = enum(c_int) {
pub const ScrollBarProperty = enum(c_int) {
arrows_size = 16,
arrows_visible,
scroll_slider_padding,
@ -115,32 +120,32 @@ pub const GuiScrollBarProperty = enum(c_int) {
scroll_speed,
};
pub const GuiCheckBoxProperty = enum(c_int) {
pub const CheckBoxProperty = enum(c_int) {
check_padding = 16,
};
pub const GuiComboBoxProperty = enum(c_int) {
pub const ComboBoxProperty = enum(c_int) {
combo_button_width = 16,
combo_button_spacing,
};
pub const GuiDropdownBoxProperty = enum(c_int) {
pub const DropdownBoxProperty = enum(c_int) {
arrow_padding = 16,
dropdown_items_spacing,
dropdown_arrow_hidden,
dropdown_roll_up,
};
pub const GuiTextBoxProperty = enum(c_int) {
pub const TextBoxProperty = enum(c_int) {
text_readonly = 16,
};
pub const GuiValueBoxProperty = enum(c_int) {
pub const ValueBoxProperty = enum(c_int) {
spin_button_width = 16,
spin_button_spacing,
};
pub const GuiListViewProperty = enum(c_int) {
pub const ListViewProperty = enum(c_int) {
list_items_height = 16,
list_items_spacing,
scrollbar_width,
@ -149,7 +154,7 @@ pub const GuiListViewProperty = enum(c_int) {
list_items_border_width,
};
pub const GuiColorPickerProperty = enum(c_int) {
pub const ColorPickerProperty = enum(c_int) {
color_selector_size = 16,
huebar_width,
huebar_padding,
@ -160,230 +165,230 @@ pub const GuiColorPickerProperty = enum(c_int) {
pub const scrollbar_left_side: c_int = 0;
pub const scrollbar_right_side: c_int = 1;
pub const GuiIconName = enum(c_int) {
icon_none = 0,
icon_folder_file_open = 1,
icon_file_save_classic = 2,
icon_folder_open = 3,
icon_folder_save = 4,
icon_file_open = 5,
icon_file_save = 6,
icon_file_export = 7,
icon_file_add = 8,
icon_file_delete = 9,
icon_filetype_text = 10,
icon_filetype_audio = 11,
icon_filetype_image = 12,
icon_filetype_play = 13,
icon_filetype_video = 14,
icon_filetype_info = 15,
icon_file_copy = 16,
icon_file_cut = 17,
icon_file_paste = 18,
icon_cursor_hand = 19,
icon_cursor_pointer = 20,
icon_cursor_classic = 21,
icon_pencil = 22,
icon_pencil_big = 23,
icon_brush_classic = 24,
icon_brush_painter = 25,
icon_water_drop = 26,
icon_color_picker = 27,
icon_rubber = 28,
icon_color_bucket = 29,
icon_text_t = 30,
icon_text_a = 31,
icon_scale = 32,
icon_resize = 33,
icon_filter_point = 34,
icon_filter_bilinear = 35,
icon_crop = 36,
icon_crop_alpha = 37,
icon_square_toggle = 38,
icon_symmetry = 39,
icon_symmetry_horizontal = 40,
icon_symmetry_vertical = 41,
icon_lens = 42,
icon_lens_big = 43,
icon_eye_on = 44,
icon_eye_off = 45,
icon_filter_top = 46,
icon_filter = 47,
icon_target_point = 48,
icon_target_small = 49,
icon_target_big = 50,
icon_target_move = 51,
icon_cursor_move = 52,
icon_cursor_scale = 53,
icon_cursor_scale_right = 54,
icon_cursor_scale_left = 55,
icon_undo = 56,
icon_redo = 57,
icon_reredo = 58,
icon_mutate = 59,
icon_rotate = 60,
icon_repeat = 61,
icon_shuffle = 62,
icon_emptybox = 63,
icon_target = 64,
icon_target_small_fill = 65,
icon_target_big_fill = 66,
icon_target_move_fill = 67,
icon_cursor_move_fill = 68,
icon_cursor_scale_fill = 69,
icon_cursor_scale_right_fill = 70,
icon_cursor_scale_left_fill = 71,
icon_undo_fill = 72,
icon_redo_fill = 73,
icon_reredo_fill = 74,
icon_mutate_fill = 75,
icon_rotate_fill = 76,
icon_repeat_fill = 77,
icon_shuffle_fill = 78,
icon_emptybox_small = 79,
icon_box = 80,
icon_box_top = 81,
icon_box_top_right = 82,
icon_box_right = 83,
icon_box_bottom_right = 84,
icon_box_bottom = 85,
icon_box_bottom_left = 86,
icon_box_left = 87,
icon_box_top_left = 88,
icon_box_center = 89,
icon_box_circle_mask = 90,
icon_pot = 91,
icon_alpha_multiply = 92,
icon_alpha_clear = 93,
icon_dithering = 94,
icon_mipmaps = 95,
icon_box_grid = 96,
icon_grid = 97,
icon_box_corners_small = 98,
icon_box_corners_big = 99,
icon_four_boxes = 100,
icon_grid_fill = 101,
icon_box_multisize = 102,
icon_zoom_small = 103,
icon_zoom_medium = 104,
icon_zoom_big = 105,
icon_zoom_all = 106,
icon_zoom_center = 107,
icon_box_dots_small = 108,
icon_box_dots_big = 109,
icon_box_concentric = 110,
icon_box_grid_big = 111,
icon_ok_tick = 112,
icon_cross = 113,
icon_arrow_left = 114,
icon_arrow_right = 115,
icon_arrow_down = 116,
icon_arrow_up = 117,
icon_arrow_left_fill = 118,
icon_arrow_right_fill = 119,
icon_arrow_down_fill = 120,
icon_arrow_up_fill = 121,
icon_audio = 122,
icon_fx = 123,
icon_wave = 124,
icon_wave_sinus = 125,
icon_wave_square = 126,
icon_wave_triangular = 127,
icon_cross_small = 128,
icon_player_previous = 129,
icon_player_play_back = 130,
icon_player_play = 131,
icon_player_pause = 132,
icon_player_stop = 133,
icon_player_next = 134,
icon_player_record = 135,
icon_magnet = 136,
icon_lock_close = 137,
icon_lock_open = 138,
icon_clock = 139,
icon_tools = 140,
icon_gear = 141,
icon_gear_big = 142,
icon_bin = 143,
icon_hand_pointer = 144,
icon_laser = 145,
icon_coin = 146,
icon_explosion = 147,
icon_1up = 148,
icon_player = 149,
icon_player_jump = 150,
icon_key = 151,
icon_demon = 152,
icon_text_popup = 153,
icon_gear_ex = 154,
icon_crack = 155,
icon_crack_points = 156,
icon_star = 157,
icon_door = 158,
icon_exit = 159,
icon_mode_2d = 160,
icon_mode_3d = 161,
icon_cube = 162,
icon_cube_face_top = 163,
icon_cube_face_left = 164,
icon_cube_face_front = 165,
icon_cube_face_bottom = 166,
icon_cube_face_right = 167,
icon_cube_face_back = 168,
icon_camera = 169,
icon_special = 170,
icon_link_net = 171,
icon_link_boxes = 172,
icon_link_multi = 173,
icon_link = 174,
icon_link_broke = 175,
icon_text_notes = 176,
icon_notebook = 177,
icon_suitcase = 178,
icon_suitcase_zip = 179,
icon_mailbox = 180,
icon_monitor = 181,
icon_printer = 182,
icon_photo_camera = 183,
icon_photo_camera_flash = 184,
icon_house = 185,
icon_heart = 186,
icon_corner = 187,
icon_vertical_bars = 188,
icon_vertical_bars_fill = 189,
icon_life_bars = 190,
icon_info = 191,
icon_crossline = 192,
icon_help = 193,
icon_filetype_alpha = 194,
icon_filetype_home = 195,
icon_layers_visible = 196,
icon_layers = 197,
icon_window = 198,
icon_hidpi = 199,
icon_filetype_binary = 200,
icon_hex = 201,
icon_shield = 202,
icon_file_new = 203,
icon_folder_add = 204,
icon_alarm = 205,
icon_cpu = 206,
icon_rom = 207,
icon_step_over = 208,
icon_step_into = 209,
icon_step_out = 210,
icon_restart = 211,
icon_breakpoint_on = 212,
icon_breakpoint_off = 213,
icon_burger_menu = 214,
icon_case_sensitive = 215,
icon_reg_exp = 216,
icon_folder = 217,
icon_file = 218,
icon_sand_timer = 219,
icon_warning = 220,
icon_help_box = 221,
icon_info_box = 222,
pub const IconName = enum(c_int) {
none = 0,
folder_file_open = 1,
file_save_classic = 2,
folder_open = 3,
folder_save = 4,
file_open = 5,
file_save = 6,
file_export = 7,
file_add = 8,
file_delete = 9,
filetype_text = 10,
filetype_audio = 11,
filetype_image = 12,
filetype_play = 13,
filetype_video = 14,
filetype_info = 15,
file_copy = 16,
file_cut = 17,
file_paste = 18,
cursor_hand = 19,
cursor_pointer = 20,
cursor_classic = 21,
pencil = 22,
pencil_big = 23,
brush_classic = 24,
brush_painter = 25,
water_drop = 26,
color_picker = 27,
rubber = 28,
color_bucket = 29,
text_t = 30,
text_a = 31,
scale = 32,
resize = 33,
filter_point = 34,
filter_bilinear = 35,
crop = 36,
crop_alpha = 37,
square_toggle = 38,
symmetry = 39,
symmetry_horizontal = 40,
symmetry_vertical = 41,
lens = 42,
lens_big = 43,
eye_on = 44,
eye_off = 45,
filter_top = 46,
filter = 47,
target_point = 48,
target_small = 49,
target_big = 50,
target_move = 51,
cursor_move = 52,
cursor_scale = 53,
cursor_scale_right = 54,
cursor_scale_left = 55,
undo = 56,
redo = 57,
reredo = 58,
mutate = 59,
rotate = 60,
repeat = 61,
shuffle = 62,
emptybox = 63,
target = 64,
target_small_fill = 65,
target_big_fill = 66,
target_move_fill = 67,
cursor_move_fill = 68,
cursor_scale_fill = 69,
cursor_scale_right_fill = 70,
cursor_scale_left_fill = 71,
undo_fill = 72,
redo_fill = 73,
reredo_fill = 74,
mutate_fill = 75,
rotate_fill = 76,
repeat_fill = 77,
shuffle_fill = 78,
emptybox_small = 79,
box = 80,
box_top = 81,
box_top_right = 82,
box_right = 83,
box_bottom_right = 84,
box_bottom = 85,
box_bottom_left = 86,
box_left = 87,
box_top_left = 88,
box_center = 89,
box_circle_mask = 90,
pot = 91,
alpha_multiply = 92,
alpha_clear = 93,
dithering = 94,
mipmaps = 95,
box_grid = 96,
grid = 97,
box_corners_small = 98,
box_corners_big = 99,
four_boxes = 100,
grid_fill = 101,
box_multisize = 102,
zoom_small = 103,
zoom_medium = 104,
zoom_big = 105,
zoom_all = 106,
zoom_center = 107,
box_dots_small = 108,
box_dots_big = 109,
box_concentric = 110,
box_grid_big = 111,
ok_tick = 112,
cross = 113,
arrow_left = 114,
arrow_right = 115,
arrow_down = 116,
arrow_up = 117,
arrow_left_fill = 118,
arrow_right_fill = 119,
arrow_down_fill = 120,
arrow_up_fill = 121,
audio = 122,
fx = 123,
wave = 124,
wave_sinus = 125,
wave_square = 126,
wave_triangular = 127,
cross_small = 128,
player_previous = 129,
player_play_back = 130,
player_play = 131,
player_pause = 132,
player_stop = 133,
player_next = 134,
player_record = 135,
magnet = 136,
lock_close = 137,
lock_open = 138,
clock = 139,
tools = 140,
gear = 141,
gear_big = 142,
bin = 143,
hand_pointer = 144,
laser = 145,
coin = 146,
explosion = 147,
@"1up" = 148,
player = 149,
player_jump = 150,
key = 151,
demon = 152,
text_popup = 153,
gear_ex = 154,
crack = 155,
crack_points = 156,
star = 157,
door = 158,
exit = 159,
mode_2d = 160,
mode_3d = 161,
cube = 162,
cube_face_top = 163,
cube_face_left = 164,
cube_face_front = 165,
cube_face_bottom = 166,
cube_face_right = 167,
cube_face_back = 168,
camera = 169,
special = 170,
link_net = 171,
link_boxes = 172,
link_multi = 173,
link = 174,
link_broke = 175,
text_notes = 176,
notebook = 177,
suitcase = 178,
suitcase_zip = 179,
mailbox = 180,
monitor = 181,
printer = 182,
photo_camera = 183,
photo_camera_flash = 184,
house = 185,
heart = 186,
corner = 187,
vertical_bars = 188,
vertical_bars_fill = 189,
life_bars = 190,
info = 191,
crossline = 192,
help = 193,
filetype_alpha = 194,
filetype_home = 195,
layers_visible = 196,
layers = 197,
window = 198,
hidpi = 199,
filetype_binary = 200,
hex = 201,
shield = 202,
file_new = 203,
folder_add = 204,
alarm = 205,
cpu = 206,
rom = 207,
step_over = 208,
step_into = 209,
step_out = 210,
restart = 211,
breakpoint_on = 212,
breakpoint_off = 213,
burger_menu = 214,
case_sensitive = 215,
reg_exp = 216,
folder = 217,
file = 218,
sand_timer = 219,
warning = 220,
help_box = 221,
info_box = 222,
icon_223 = 223,
icon_224 = 224,
icon_225 = 225,
@ -420,41 +425,25 @@ pub const GuiIconName = enum(c_int) {
};
/// 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");
}
}
pub fn setStyle(control: Control, comptime property: ControlOrDefaultProperty, value: i32) void {
const property_int: c_int = switch (property) {
inline else => |val| @intCast(@intFromEnum(val))
};
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");
}
}
pub fn getStyle(control: Control, comptime property: ControlOrDefaultProperty) i32 {
const property_int: c_int = switch (property) {
inline else => |val| @intCast(@intFromEnum(val))
};
return @as(i32, cdef.GuiGetStyle(control, property_int));
}
/// Get raygui icons data pointer
pub fn guiGetIcons() RayguiError![]u32 {
pub fn getIcons() RayguiError![]u32 {
var res: []u32 = undefined;
const ptr = cdef.GuiGetIcons();
@ -467,22 +456,22 @@ pub fn guiGetIcons() RayguiError![]u32 {
// If you REALLY need the return value of the function, you'll know what to do with it and its size yourself
/// Load raygui icons file (.rgi) into internal icons data
pub fn guiLoadIcons(fileName: [*c]const u8, loadIconsName: bool) [*c][*c]u8 {
pub fn loadIcons(fileName: [*c]const u8, loadIconsName: bool) [*c][*c]u8 {
return cdef.GuiLoadIcons(fileName, loadIconsName);
}
/// Tab Bar control, returns TAB to be closed or -1
pub fn guiTabBar(bounds: Rectangle, text: [][*:0]const u8, active: *i32) i32 {
pub fn tabBar(bounds: Rectangle, text: [][*:0]const u8, active: *i32) i32 {
return @as(i32, cdef.GuiTabBar(bounds, @as([*c][*c]const u8, @ptrCast(text)), @as(c_int, @intCast(text.len)), @as([*c]c_int, @ptrCast(active))));
}
/// List View with extended parameters
pub fn guiListViewEx(bounds: Rectangle, text: [][*:0]const u8, scrollIndex: *i32, active: *i32, focus: *i32) i32 {
pub fn listViewEx(bounds: Rectangle, text: [][*:0]const u8, scrollIndex: *i32, active: *i32, focus: *i32) i32 {
return @as(i32, cdef.GuiListViewEx(bounds, @as([*c][*c]const u8, @ptrCast(text)), @as(c_int, @intCast(text.len)), @as([*c]c_int, @ptrCast(scrollIndex)), @as([*c]c_int, @ptrCast(active)), @as([*c]c_int, @ptrCast(focus))));
}
/// Panel control, useful to group controls
pub fn guiPanel(bounds: Rectangle, text: ?[*:0]const u8) i32 {
pub fn panel(bounds: Rectangle, text: ?[*:0]const u8) i32 {
var textFinal = @as([*c]const u8, 0);
if (text) |textSure| {
textFinal = @as([*c]const u8, @ptrCast(textSure));
@ -491,7 +480,7 @@ pub fn guiPanel(bounds: Rectangle, text: ?[*:0]const u8) i32 {
}
/// Scroll Panel control
pub fn guiScrollPanel(bounds: Rectangle, text: ?[*:0]const u8, content: Rectangle, scroll: *Vector2, view: *Rectangle) i32 {
pub fn scrollPanel(bounds: Rectangle, text: ?[*:0]const u8, content: Rectangle, scroll: *Vector2, view: *Rectangle) i32 {
var textFinal = @as([*c]const u8, 0);
if (text) |textSure| {
textFinal = @as([*c]const u8, @ptrCast(textSure));