Raygui
Awesome links
Getting Started
Including raygui in Your Project
To use raygui, you need to include the raygui.h
header file in your project.
Initializing and Closing
Initializing raylib and raygui
// Initialize the window
InitWindow(screenWidth, screenHeight, "Window Title");
// Set the target FPS
SetTargetFPS(60);
Closing raylib and raygui
Creating a GUI
Buttons
Labels
Checkboxes
bool checked = false;
checked = GuiCheckBox((Rectangle){ x, y, width, height }, "Checkbox Text", checked);
Textboxes
char text[64] = "Default Text";
GuiTextBox((Rectangle){ x, y, width, height }, text, sizeof(text), true);
Sliders
float value = 50.0f;
value = GuiSlider((Rectangle){ x, y, width, height }, "Min", "Max", value, 0, 100);
Dropdown Boxes
int active = 0;
active = GuiDropdownBox((Rectangle){ x, y, width, height }, "Option1;Option2;Option3", &active, true);
Spinners
Scrollbars
Styling the GUI
Setting a Style
Loading a Custom Style
Resetting to Default Style
Example
Complete Example Program
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
int main(void)
{
// Initialization
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raygui example - basic window");
SetTargetFPS(60);
bool checked = false;
float sliderValue = 50.0f;
char textBox[64] = "Edit me";
// Main game loop
while (!WindowShouldClose())
{
// Update
// Draw
BeginDrawing();
ClearBackground(RAYWHITE);
if (GuiButton((Rectangle){ 10, 10, 100, 30 }, "Button"))
{
// Button was clicked
}
GuiLabel((Rectangle){ 10, 50, 100, 30 }, "Label");
checked = GuiCheckBox((Rectangle){ 10, 90, 20, 20 }, "Checkbox", checked);
GuiTextBox((Rectangle){ 10, 130, 200, 30 }, textBox, sizeof(textBox), true);
sliderValue = GuiSlider((Rectangle){ 10, 170, 200, 20 }, "Min", "Max", sliderValue, 0, 100);
EndDrawing();
}
// De-Initialization
CloseWindow();
return 0;
}