mirror of
https://github.com/raylib-zig/raylib-zig.git
synced 2025-12-06 06:13:08 +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 rl = @import("raylib");
|
||||||
const rg = @import("raygui");
|
const rg = @import("raygui");
|
||||||
|
|
||||||
// `rl.getColor` only accepts a `u32`. Performing `@intCast` on the return value
|
/// `rl.getColor` only accepts a `u32`. Performing `@intCast` on the return value
|
||||||
// of `rg.getStyle` invokes checked undefined behavior from Zig when passed to
|
/// of `rg.getStyle` invokes checked undefined behavior from Zig when passed to
|
||||||
// `rl.getColor`, hence the custom implementation here...
|
/// `rl.getColor`, hence the custom implementation here...
|
||||||
fn getColor(hex: i32) rl.Color {
|
fn getColor(hex: i32) rl.Color {
|
||||||
var color: rl.Color = .black;
|
var color: rl.Color = .black;
|
||||||
// zig fmt: off
|
// zig fmt: off
|
||||||
@ -43,7 +43,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
rl.clearBackground(getColor(color_int));
|
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;
|
show_message_box = true;
|
||||||
|
|
||||||
if (show_message_box) {
|
if (show_message_box) {
|
||||||
|
|||||||
@ -98,6 +98,10 @@ MANUAL = [
|
|||||||
"GuiListViewEx",
|
"GuiListViewEx",
|
||||||
"GuiPanel",
|
"GuiPanel",
|
||||||
"GuiScrollPanel",
|
"GuiScrollPanel",
|
||||||
|
"GuiButton",
|
||||||
|
"GuiLabelButton",
|
||||||
|
"GuiCheckBox",
|
||||||
|
"GuiTextBox",
|
||||||
"DrawSplineLinear",
|
"DrawSplineLinear",
|
||||||
"DrawSplineBasis",
|
"DrawSplineBasis",
|
||||||
"DrawSplineCatmullRom",
|
"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))));
|
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))));
|
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)
|
/// Enable gui controls (global state)
|
||||||
pub fn enable() void {
|
pub fn enable() void {
|
||||||
cdef.GuiEnable();
|
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))));
|
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
|
/// Toggle Button control
|
||||||
pub fn toggle(bounds: Rectangle, text: [:0]const u8, active: *bool) i32 {
|
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))));
|
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))));
|
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
|
/// Combo Box control
|
||||||
pub fn comboBox(bounds: Rectangle, text: [:0]const u8, active: *i32) i32 {
|
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))));
|
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));
|
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
|
/// Slider control
|
||||||
pub fn slider(bounds: Rectangle, textLeft: [:0]const u8, textRight: [:0]const u8, value: *f32, minValue: f32, maxValue: f32) i32 {
|
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));
|
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