zraygui is an attempt of transforming the well-known raygui library, which currently implements an immediate mode GUI (ImGUI) using the raylib framework, into a retained mode GUI. This transition from immediate mode to retained mode brings about a significant shift in how user interfaces are managed and drawn.
- raylib is a popular and lightweight C library designed for making 2D and 3D games. It provides a wealth of features for graphics, audio, and input handling while keeping things simple and accessible.
- raygui is a companion library for raylib, focusing on creating graphical user interfaces (GUIs). It employs an immediate mode GUI paradigm, where each frame, GUI elements are drawn and handled individually. This approach is efficient and straightforward for simple interfaces but can become complex for larger projects.
zraygui takes the fundamental concept of raygui and evolves it into a retained mode GUI based of Layouts/Panels and Widgets. In retained mode, GUI elements persist beyond the frame they were created in. This approach allows for a more structured and organized GUI construction, particularly for complex applications.
- Implement almost every Gui control of raygui.
- Implement Radio Buttons.
- Implement Menu bar with sub menus.
- Dynamic Content: Retained mode accommodates dynamic content changes seamlessly. Adding, removing, or altering elements during runtime is more natural and less error-prone.
- Widget Listeners: This retained mode brings the benefit of having different kind of listeners such as OnClick or OnHover.
- Menu Bar: One of the motivation of this project was to bring an easy way to create a Menu Bar with multiples indented Sub Menus.
- Radio Buttons: With an immediate GUI it is impossible (with out saving data in the API source) to implement Radio Buttons. Since zraygui is based on layouts/panels and widgets, we can implement this easily!
To begin using zraygui in your raylib-based project, follow these steps:
- Copy the zraygui.h file from the src folder and paste it in your project workspace.
- Define the ZRAYGUI_IMPLEMENTATION and include the header file in your sources.
- Start creating your beautiful Raylib GUI applications with zraygui!
#define ZRAYGUI_IMPLEMENTATION
#include "../src/zraygui.h"
Layout* root;
Widget *button, *label;
void my_callback(Vector2 mousePos) {
SetWidgetVisible(label, true);
}
int main(void) {
int w = 250;
int h = 100;
InitWindow(w,h,"Hello World - zraygui");
root = CreateLayout(NULL, L_NONE, WHITE);
button = CreateButton("Press me!");
label = CreateLabel("Hello world from zraygui!");
SetWidgetPos(button, (Vector2){(w - GetWidgetWidth(button)) / 2, (h - GetWidgetHeight(button)) / 4});
SetWidgetPos(label, (Vector2){(w - GetWidgetWidth(label)) / 2, ((h - GetWidgetHeight(label)) / 2) + 15});
SetWidgetVisible(label, false);
AddWidget(root, button);
AddWidget(root, label);
SetWidgetOnClick(button, my_callback);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(WHITE);
RenderWindow(root);
EndDrawing();
}
return 0;
}
zraygui is an open-source project that welcomes contributions from the community. Whether you're interested in improving documentation, adding new features, or fixing bugs, your efforts are valued.