mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-08 19:47:28 +00:00
fix(raygui): make some funcs return bool
instead of i32
This commit is contained in:
parent
67fd5af55a
commit
0de5f8aed0
@ -13,9 +13,9 @@ 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...
|
||||
/// `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
|
||||
@ -43,7 +43,7 @@ pub fn main() !void {
|
||||
|
||||
rl.clearBackground(getColor(color_int));
|
||||
|
||||
if (rg.button(.init(24, 24, 120, 30), "#191#Show Message") > 0)
|
||||
if (rg.button(.init(24, 24, 120, 30), "#191#Show Message"))
|
||||
show_message_box = true;
|
||||
|
||||
if (show_message_box) {
|
||||
|
@ -98,6 +98,10 @@ MANUAL = [
|
||||
"GuiListViewEx",
|
||||
"GuiPanel",
|
||||
"GuiScrollPanel",
|
||||
"GuiButton",
|
||||
"GuiLabelButton",
|
||||
"GuiCheckBox",
|
||||
"GuiTextBox",
|
||||
"DrawSplineLinear",
|
||||
"DrawSplineBasis",
|
||||
"DrawSplineCatmullRom",
|
||||
|
@ -487,3 +487,25 @@ pub fn scrollPanel(bounds: Rectangle, text: ?[*:0]const u8, content: Rectangle,
|
||||
}
|
||||
return @as(i32, cdef.GuiScrollPanel(bounds, textFinal, content, @as([*c]Vector2, @ptrCast(scroll)), @as([*c]Rectangle, @ptrCast(view))));
|
||||
}
|
||||
|
||||
/// Button control, returns true when clicked
|
||||
pub fn button(bounds: Rectangle, text: [:0]const u8) bool {
|
||||
return @as(i32, cdef.GuiButton(bounds, @as([*c]const u8, @ptrCast(text)))) > 0;
|
||||
}
|
||||
|
||||
/// Label button control, returns true when clicked
|
||||
pub fn labelButton(bounds: Rectangle, text: [:0]const u8) i32 {
|
||||
return @as(i32, cdef.GuiLabelButton(bounds, @as([*c]const u8, @ptrCast(text)))) > 0;
|
||||
}
|
||||
|
||||
/// Check Box control, returns true when active
|
||||
pub fn checkBox(bounds: Rectangle, text: [:0]const u8, checked: *bool) bool {
|
||||
return @as(i32, cdef.GuiCheckBox(bounds, @as([*c]const u8, @ptrCast(text)), @as([*c]bool, @ptrCast(checked)))) > 0;
|
||||
}
|
||||
|
||||
/// Text Box control, updates input text
|
||||
/// Returns true on ENTER pressed (useful for data validation)
|
||||
pub fn textBox(bounds: Rectangle, text: [:0]u8, textSize: i32, editMode: bool) bool {
|
||||
return @as(i32, cdef.GuiTextBox(bounds, @as([*c]u8, @ptrCast(text)), @as(c_int, textSize), editMode)) > 0;
|
||||
}
|
||||
|
||||
|
@ -488,6 +488,28 @@ pub fn scrollPanel(bounds: Rectangle, text: ?[*:0]const u8, content: Rectangle,
|
||||
return @as(i32, cdef.GuiScrollPanel(bounds, textFinal, content, @as([*c]Vector2, @ptrCast(scroll)), @as([*c]Rectangle, @ptrCast(view))));
|
||||
}
|
||||
|
||||
/// Button control, returns true when clicked
|
||||
pub fn button(bounds: Rectangle, text: [:0]const u8) bool {
|
||||
return @as(i32, cdef.GuiButton(bounds, @as([*c]const u8, @ptrCast(text)))) > 0;
|
||||
}
|
||||
|
||||
/// Label button control, returns true when clicked
|
||||
pub fn labelButton(bounds: Rectangle, text: [:0]const u8) i32 {
|
||||
return @as(i32, cdef.GuiLabelButton(bounds, @as([*c]const u8, @ptrCast(text)))) > 0;
|
||||
}
|
||||
|
||||
/// Check Box control, returns true when active
|
||||
pub fn checkBox(bounds: Rectangle, text: [:0]const u8, checked: *bool) bool {
|
||||
return @as(i32, cdef.GuiCheckBox(bounds, @as([*c]const u8, @ptrCast(text)), @as([*c]bool, @ptrCast(checked)))) > 0;
|
||||
}
|
||||
|
||||
/// Text Box control, updates input text
|
||||
/// Returns true on ENTER pressed (useful for data validation)
|
||||
pub fn textBox(bounds: Rectangle, text: [:0]u8, textSize: i32, editMode: bool) bool {
|
||||
return @as(i32, cdef.GuiTextBox(bounds, @as([*c]u8, @ptrCast(text)), @as(c_int, textSize), editMode)) > 0;
|
||||
}
|
||||
|
||||
|
||||
/// Enable gui controls (global state)
|
||||
pub fn enable() void {
|
||||
cdef.GuiEnable();
|
||||
@ -598,16 +620,6 @@ pub fn label(bounds: Rectangle, text: [:0]const u8) i32 {
|
||||
return @as(i32, cdef.GuiLabel(bounds, @as([*c]const u8, @ptrCast(text))));
|
||||
}
|
||||
|
||||
/// Button control, returns true when clicked
|
||||
pub fn button(bounds: Rectangle, text: [:0]const u8) i32 {
|
||||
return @as(i32, cdef.GuiButton(bounds, @as([*c]const u8, @ptrCast(text))));
|
||||
}
|
||||
|
||||
/// Label button control, returns true when clicked
|
||||
pub fn labelButton(bounds: Rectangle, text: [:0]const u8) i32 {
|
||||
return @as(i32, cdef.GuiLabelButton(bounds, @as([*c]const u8, @ptrCast(text))));
|
||||
}
|
||||
|
||||
/// Toggle Button control
|
||||
pub fn toggle(bounds: Rectangle, text: [:0]const u8, active: *bool) i32 {
|
||||
return @as(i32, cdef.GuiToggle(bounds, @as([*c]const u8, @ptrCast(text)), @as([*c]bool, @ptrCast(active))));
|
||||
@ -623,11 +635,6 @@ pub fn toggleSlider(bounds: Rectangle, text: [:0]const u8, active: *i32) i32 {
|
||||
return @as(i32, cdef.GuiToggleSlider(bounds, @as([*c]const u8, @ptrCast(text)), @as([*c]c_int, @ptrCast(active))));
|
||||
}
|
||||
|
||||
/// Check Box control, returns true when active
|
||||
pub fn checkBox(bounds: Rectangle, text: [:0]const u8, checked: *bool) i32 {
|
||||
return @as(i32, cdef.GuiCheckBox(bounds, @as([*c]const u8, @ptrCast(text)), @as([*c]bool, @ptrCast(checked))));
|
||||
}
|
||||
|
||||
/// Combo Box control
|
||||
pub fn comboBox(bounds: Rectangle, text: [:0]const u8, active: *i32) i32 {
|
||||
return @as(i32, cdef.GuiComboBox(bounds, @as([*c]const u8, @ptrCast(text)), @as([*c]c_int, @ptrCast(active))));
|
||||
@ -653,11 +660,6 @@ pub fn valueBoxFloat(bounds: Rectangle, text: [:0]const u8, textValue: [:0]u8, v
|
||||
return @as(i32, cdef.GuiValueBoxFloat(bounds, @as([*c]const u8, @ptrCast(text)), @as([*c]u8, @ptrCast(textValue)), @as([*c]f32, @ptrCast(value)), editMode));
|
||||
}
|
||||
|
||||
/// Text Box control, updates input text
|
||||
pub fn textBox(bounds: Rectangle, text: [:0]u8, textSize: i32, editMode: bool) i32 {
|
||||
return @as(i32, cdef.GuiTextBox(bounds, @as([*c]u8, @ptrCast(text)), @as(c_int, textSize), editMode));
|
||||
}
|
||||
|
||||
/// Slider control
|
||||
pub fn slider(bounds: Rectangle, textLeft: [:0]const u8, textRight: [:0]const u8, value: *f32, minValue: f32, maxValue: f32) i32 {
|
||||
return @as(i32, cdef.GuiSlider(bounds, @as([*c]const u8, @ptrCast(textLeft)), @as([*c]const u8, @ptrCast(textRight)), @as([*c]f32, @ptrCast(value)), minValue, maxValue));
|
||||
|
Loading…
x
Reference in New Issue
Block a user