Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions examples/gui/controls_test_suite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type state = {
list_view_ex_focus : int;
list_view_ex_scroll_index : int;
toggle_group_active : int;
multi_text_box_text : string;
mutable multi_text_box_edit_mode : bool;
(* multi_text_box_text : string; *)
(* mutable multi_text_box_edit_mode : bool; *)
color_picker_val : Raylib.Color.t;
slider_val : float;
slider_bar_val : float;
Expand Down Expand Up @@ -54,8 +54,8 @@ let setup () =
list_view_ex_focus = 0;
list_view_ex_scroll_index = 0;
toggle_group_active = 0;
multi_text_box_text = "Multi text box";
multi_text_box_edit_mode = false;
(* multi_text_box_text = "Multi text box"; *)
(* multi_text_box_edit_mode = false; *)
color_picker_val = Raylib.Color.raywhite;
slider_val = 0.0;
slider_bar_val = 50.0;
Expand Down Expand Up @@ -127,18 +127,18 @@ let rec loop s =
Raygui.group_box (Rectangle.create 25.0 310.0 125.0 150.0) "STATES";
Raygui.lock ();
Raygui.(
set_state ControlState.Normal;
set_state State.Normal;
ignore (button (Rectangle.create 30.0 320.0 115.0 30.0) "NORMAL"));
Raygui.(
set_state ControlState.Focused;
set_state State.Focused;
ignore (button (Rectangle.create 30.0 355.0 115.0 30.0) "FOCUSED"));
Raygui.(
set_state ControlState.Pressed;
set_state State.Pressed;
ignore (button (Rectangle.create 30.0 390.0 115.0 30.0) "#15#PRESSED"));
Raygui.(
set_state ControlState.Disabled;
set_state State.Disabled;
ignore (button (Rectangle.create 30.0 425.0 115.0 30.0) "DISABLED"));
Raygui.set_state Raygui.ControlState.Normal;
Raygui.set_state Raygui.State.Normal;
if not s.show_text_input_box then Raygui.unlock ();

let rect = Rectangle.create 25.0 470.0 125.0 30.0 in
Expand Down Expand Up @@ -206,7 +206,7 @@ let rec loop s =
in

(* third column *)
let rect = Rectangle.create 320.0 25.0 225.0 140.0 in
(*let rect = Rectangle.create 320.0 25.0 225.0 140.0 in
let multi_text_box_text =
match
Raygui.text_box_multi rect s.multi_text_box_text
Expand All @@ -216,10 +216,10 @@ let rec loop s =
s.multi_text_box_edit_mode <- not s.multi_text_box_edit_mode;
vl
| vl, false -> vl
in
in*)

let rect = Rectangle.create 320.0 185.0 196.0 192.0 in
let color_picker_val = Raygui.color_picker rect s.color_picker_val in
let color_picker_val = Raygui.color_picker rect "Color picker" s.color_picker_val in

let rect = Rectangle.create 355.0 400.0 165.0 20.0 in
let slider_val =
Expand All @@ -246,14 +246,15 @@ let rec loop s =
draw_rectangle 0 0 (get_screen_width ()) (get_screen_height ())
(fade Color.raywhite 0.8);

let text_input_text, res =
let text_input_text, _, res =
Raygui.text_input_box
(Rectangle.create
((float_of_int (get_screen_width ()) /. 2.0) -. 120.0)
((float_of_int (get_screen_height ()) /. 2.0) -. 60.0)
240.0 140.0)
"Save file as..." "Introduce a save file name" "Ok;Cancel"
s.text_input_text
100 0
in
if res = 0 || res = 1 || res = 2 then (text_input_text, false)
else (text_input_text, show_text_input_box))
Expand Down Expand Up @@ -281,7 +282,7 @@ let rec loop s =
list_view_ex_focus;
list_view_ex_scroll_index;
toggle_group_active;
multi_text_box_text;
(* multi_text_box_text; *)
color_picker_val;
slider_val;
slider_bar_val;
Expand Down
16 changes: 16 additions & 0 deletions src/c/dune
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
(= %{system} elf)))
(deps
(source_tree vendor/raylib)
(source_tree vendor/raygui)
enable_formats.patch
gui_scrollbar.patch
(:discover apply_patch.exe))
(action
(no-infer
(progn
(run chmod +w vendor/raylib/src/config.h)
(run ./apply_patch.exe enable_formats.patch)
(run chmod +w vendor/raygui/src/raygui.h)
(run ./apply_patch.exe gui_scrollbar.patch)
(run make -C vendor/raylib/src RAYLIB_LIBTYPE=STATIC -j 8)
(copy vendor/raylib/src/libraylib.a libraylib.a)
(run make -C vendor/raylib/src clean)
Expand All @@ -42,13 +46,17 @@
(= %{system} macosx))
(deps
(source_tree vendor/raylib)
(source_tree vendor/raygui)
enable_formats.patch
gui_scrollbar.patch
(:discover apply_patch.exe))
(action
(no-infer
(progn
(run chmod +w vendor/raylib/src/config.h)
(run ./apply_patch.exe enable_formats.patch)
(run chmod +w vendor/raygui/src/raygui.h)
(run ./apply_patch.exe gui_scrollbar.patch)
(run make -C vendor/raylib/src RAYLIB_LIBTYPE=STATIC -j 8)
(copy vendor/raylib/src/libraylib.a libraylib.a)
(run make -C vendor/raylib/src clean)
Expand All @@ -62,14 +70,18 @@
(= %{system} mingw64))
(deps
(source_tree vendor/raylib)
(source_tree vendor/raygui)
enable_formats.patch
gui_scrollbar.patch
mingw64.patch
(:discover apply_patch.exe))
(action
(no-infer
(progn
(run chmod +w vendor/raylib/src/config.h)
(run ./apply_patch.exe enable_formats.patch)
(run chmod +w vendor/raygui/src/raygui.h)
(run ./apply_patch.exe gui_scrollbar.patch)
(run chmod +w vendor/raylib/src/Makefile)
(run ./apply_patch.exe mingw64.patch)
(run make -C vendor/raylib/src RAYLIB_LIBTYPE=STATIC -j 8)
Expand All @@ -90,14 +102,18 @@
(= %{system} bsd_elf)))
(deps
(source_tree vendor/raylib)
(source_tree vendor/raygui)
enable_formats.patch
gui_scrollbar.patch
freebsd.patch
(:discover apply_patch.exe))
(action
(no-infer
(progn
(run chmod +w vendor/raylib/src/config.h)
(run ./apply_patch.exe enable_formats.patch)
(run chmod +w vendor/raygui/src/raygui.h)
(run ./apply_patch.exe gui_scrollbar.patch)
(run chmod +w vendor/raylib/src/Makefile)
(run ./apply_patch.exe freebsd.patch)
(run gmake -C vendor/raylib/src RAYLIB_LIBTYPE=STATIC -j 8)
Expand Down
28 changes: 28 additions & 0 deletions src/c/gui_scrollbar.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/vendor/raygui/src/raygui.h b/vendor/raygui/src/raygui.h
--- a/vendor/raygui/src/raygui.h
+++ b/vendor/raygui/src/raygui.h
@@ -591,6 +591,7 @@ RAYGUIAPI float GuiSliderBar(Rectangle bounds, const char *textLeft, const char
RAYGUIAPI float GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float value, float minValue, float maxValue); // Progress Bar control, shows current progress value
RAYGUIAPI void GuiStatusBar(Rectangle bounds, const char *text); // Status Bar control, shows info text
RAYGUIAPI void GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders
+RAYGUIAPI int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); // Scroll bar control, used by GuiScrollPanel()
RAYGUIAPI Vector2 GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs); // Grid control, returns mouse cell position

// Advance controls set
@@ -1340,7 +1341,6 @@ static const char **GuiTextSplit(const char *text, char delimiter, int *count, i
static Vector3 ConvertHSVtoRGB(Vector3 hsv); // Convert color data from HSV to RGB
static Vector3 ConvertRGBtoHSV(Vector3 rgb); // Convert color data from RGB to HSV

-static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); // Scroll bar control, used by GuiScrollPanel()
static void GuiTooltip(Rectangle controlRec); // Draw tooltip using control rec position


@@ -4439,7 +4439,7 @@ static Vector3 ConvertHSVtoRGB(Vector3 hsv)
}

// Scroll bar control (used by GuiScrollPanel())
-static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
+int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
{
GuiState state = guiState;

11 changes: 2 additions & 9 deletions src/c/raygui/fixed_types.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Raygui_types_generated

module ControlState = struct
include ControlState
module State = struct
include State

let to_int x = Unsigned.UInt32.to_int Ctypes.(coerce t uint32_t x)
let of_int i = Ctypes.(coerce uint32_t t (Unsigned.UInt32.of_int i))
Expand Down Expand Up @@ -98,13 +98,6 @@ module ScrollBarProperty = struct
let of_int i = Ctypes.(coerce uint32_t t (Unsigned.UInt32.of_int i))
end

module ScrollBarSide = struct
include ScrollBarSide

let to_int x = Unsigned.UInt32.to_int Ctypes.(coerce t uint32_t x)
let of_int i = Ctypes.(coerce uint32_t t (Unsigned.UInt32.of_int i))
end

module ListViewProperty = struct
include ListViewProperty

Expand Down
54 changes: 39 additions & 15 deletions src/c/raygui/functions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ module Functions (F : Ctypes.FOREIGN) = struct
(* Unlock gui controls (global state) *)
let unlock = foreign "GuiUnlock" (void @-> returning void)

(* Get gui is locked (global state) *)
let is_locked = foreign "GuiIsLocked" (void @-> returning bool)

(* Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f *)
let fade = foreign "GuiFade" (float @-> returning void)

(* Set gui state (global state) *)
let set_state =
foreign "GuiSetState" (Constants.ControlState.t @-> returning void)
foreign "GuiSetState" (Constants.State.t @-> returning void)

(* Get gui state (global state) *)
let get_state =
foreign "GuiGetState" (void @-> returning Constants.ControlState.t)
foreign "GuiGetState" (void @-> returning Constants.State.t)

(* Font set/get functions *)
(* Set gui custom font (global state) *)
Expand Down Expand Up @@ -58,12 +61,15 @@ module Functions (F : Ctypes.FOREIGN) = struct
foreign "GuiLine" (Raylib.Rectangle.t @-> string @-> returning void)

(* Panel control, useful to group controls *)
let _panel = foreign "GuiPanel" (Raylib.Rectangle.t @-> returning void)
let _panel = foreign "GuiPanel" (Raylib.Rectangle.t @-> string @-> returning void)

(* Tab bar control *)
let _tab_bar = foreign "GuiTabBar" (Raylib.Rectangle.t @-> ptr string @-> int @-> ptr int @-> returning int)

(* Scroll Panel control *)
let _scroll_panel =
foreign "GuiScrollPanel"
(Raylib.Rectangle.t @-> Raylib.Rectangle.t @-> ptr Raylib.Vector2.t
(Raylib.Rectangle.t @-> string @-> Raylib.Rectangle.t @-> ptr Raylib.Vector2.t
@-> returning Raylib.Rectangle.t)

(* Basic controls set *)
Expand Down Expand Up @@ -121,11 +127,6 @@ module Functions (F : Ctypes.FOREIGN) = struct
foreign "GuiTextBox"
(Raylib.Rectangle.t @-> ptr char @-> int @-> bool @-> returning bool)

(* Text Box control with multiple lines *)
let _text_box_multi =
foreign "GuiTextBoxMulti"
(Raylib.Rectangle.t @-> ptr char @-> int @-> bool @-> returning bool)

(* Slider control, returns selected value *)
let _slider =
foreign "GuiSlider"
Expand Down Expand Up @@ -160,7 +161,7 @@ module Functions (F : Ctypes.FOREIGN) = struct
(* Grid control *)
let _grid =
foreign "GuiGrid"
(Raylib.Rectangle.t @-> float @-> int @-> returning Raylib.Vector2.t)
(Raylib.Rectangle.t @-> string @-> float @-> int @-> returning Raylib.Vector2.t)

(* Advance controls set *)
(* List View control, returns selected list item index *)
Expand All @@ -182,26 +183,26 @@ module Functions (F : Ctypes.FOREIGN) = struct
(* Text Input Box control, ask for text *)
let _text_input_box =
foreign "GuiTextInputBox"
(Raylib.Rectangle.t @-> string @-> string @-> string @-> ptr char
(Raylib.Rectangle.t @-> string @-> string @-> string @-> ptr char @-> int @-> ptr int
@-> returning int)

(* Color Picker control (multiple color controls) *)
let _color_picker =
foreign "GuiColorPicker"
(Raylib.Rectangle.t @-> Raylib.Color.t @-> returning Raylib.Color.t)
(Raylib.Rectangle.t @-> string @-> Raylib.Color.t @-> returning Raylib.Color.t)

(* Color Panel control *)
let _color_panel =
foreign "GuiColorPanel"
(Raylib.Rectangle.t @-> Raylib.Color.t @-> returning Raylib.Color.t)
(Raylib.Rectangle.t @-> string @-> Raylib.Color.t @-> returning Raylib.Color.t)

(* Color Bar Alpha control *)
let _color_bar_alpha =
foreign "GuiColorBarAlpha" (Raylib.Rectangle.t @-> float @-> returning float)
foreign "GuiColorBarAlpha" (Raylib.Rectangle.t @-> string @-> float @-> returning float)

(* Color Bar Hue control *)
let _color_bar_hue =
foreign "GuiColorBarHue" (Raylib.Rectangle.t @-> float @-> returning float)
foreign "GuiColorBarHue" (Raylib.Rectangle.t @-> string @-> float @-> returning float)

(* Styles loading functions *)
(* Load style file (.rgs) *)
Expand All @@ -210,4 +211,27 @@ module Functions (F : Ctypes.FOREIGN) = struct
(* Load style default over global style *)
let load_style_default =
foreign "GuiLoadStyleDefault" (void @-> returning void)

(* Tooltips management functions *)
(* Enable tooltip (global state) *)
let enable_tooltip = foreign "GuiEnableTooltip" (void @-> returning void)

(* Disable tooltip (global state) *)
let disable_tooltip = foreign "GuiDisableTooltip" (void @-> returning void)

(* Set tooltip (global state) *)
let set_tooltip = foreign "GuiSetTooltip" (string @-> returning void)

(* Icons functionality *)
let icon_text = foreign "GuiIconText" (int @-> string @-> returning string)

(* Set icon scale (global state) *)
let set_icon_scale = foreign "GuiSetIconScale" (int @-> returning void)

(* let _get_icons = foreign "GuiGetIcons" (void @-> returning (ptr uint)) *)

(* let _load_icons = foreign "GuiLoadIcons" (string @-> bool @-> returning (ptr @@ ptr char)) *)

let _draw_icon = foreign "GuiDrawIcon" (int @-> int @-> int @-> int @-> Raylib.Color.t @-> returning void)

end
Loading
Loading