Convert Figma logo to code with AI

raysan5 logoraygui

A simple and easy-to-use immediate-mode gui library

3,379
291
3,379
15

Top Related Projects

59,344

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

9,077

A single-header ANSI C immediate mode cross-platform GUI library

13,679

A single-header ANSI C gui library

10,698

Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

3,408

A tiny immediate-mode UI library

Quick Overview

raygui is a simple and easy-to-use immediate-mode GUI library for raylib. It provides a set of functions to create GUI controls like buttons, sliders, and text boxes, allowing developers to quickly build user interfaces for their raylib-based applications. The library is designed to be lightweight and compatible with raylib's philosophy of simplicity.

Pros

  • Easy integration with raylib projects
  • Lightweight and minimal dependencies
  • Customizable appearance through styles
  • Cross-platform compatibility

Cons

  • Limited advanced GUI features compared to more comprehensive libraries
  • Immediate-mode GUI can be less efficient for complex layouts
  • Documentation could be more extensive

Code Examples

  1. Creating a button:
if (GuiButton((Rectangle){ 100, 100, 120, 40 }, "Click me!")) {
    // Button clicked action
}
  1. Creating a slider:
static float value = 50.0f;
GuiSlider((Rectangle){ 100, 200, 120, 20 }, "Slider", TextFormat("%2.1f", value), &value, 0, 100);
  1. Creating a checkbox:
static bool checked = false;
GuiCheckBox((Rectangle){ 100, 300, 20, 20 }, "Check me", &checked);

Getting Started

  1. Include raygui in your project:

    #define RAYGUI_IMPLEMENTATION
    #include "raygui.h"
    
  2. Initialize raylib and create a window:

    InitWindow(800, 450, "raygui example");
    
  3. Use raygui functions in your main loop:

    while (!WindowShouldClose()) {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            // Your raygui controls here
        EndDrawing();
    }
    
  4. Close the window when done:

    CloseWindow();
    

Competitor Comparisons

59,344

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Pros of ImGui

  • More feature-rich and mature, with extensive documentation and examples
  • Highly customizable and flexible, supporting various rendering backends
  • Large and active community, resulting in frequent updates and third-party extensions

Cons of ImGui

  • Steeper learning curve due to its extensive feature set
  • Requires more setup and integration work compared to raygui's simplicity
  • Higher memory footprint and potential performance overhead for complex UIs

Code Comparison

ImGui:

ImGui::Begin("My Window");
ImGui::Text("Hello, world!");
if (ImGui::Button("Click me!"))
    doSomething();
ImGui::End();

raygui:

GuiWindowBox((Rectangle){ 10, 10, 200, 100 }, "My Window");
GuiLabel((Rectangle){ 20, 40, 180, 20 }, "Hello, world!");
if (GuiButton((Rectangle){ 20, 70, 180, 20 }, "Click me!"))
    doSomething();

Key Differences

  • ImGui uses a more immediate-mode approach, while raygui is closer to retained-mode GUI
  • raygui is designed specifically for Raylib integration, while ImGui is more versatile
  • ImGui offers more advanced features like docking and multi-viewport support
  • raygui has a simpler API and is easier to get started with for beginners
9,077

A single-header ANSI C immediate mode cross-platform GUI library

Pros of Nuklear

  • More extensive widget set and customization options
  • Better cross-platform support, including game consoles
  • Smaller memory footprint and faster performance

Cons of Nuklear

  • Steeper learning curve due to more complex API
  • Less beginner-friendly documentation
  • Requires more manual setup and configuration

Code Comparison

Nuklear:

struct nk_context ctx;
nk_init_default(&ctx, 0);
if (nk_begin(&ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
    nk_layout_row_dynamic(&ctx, 30, 1);
    if (nk_button_label(&ctx, "Button")) {
        // Button pressed
    }
}
nk_end(&ctx);

raygui:

if (GuiButton((Rectangle){ 50, 50, 200, 30 }, "Button"))
{
    // Button pressed
}

The code comparison shows that Nuklear requires more setup and configuration, while raygui offers a simpler, more straightforward API for basic UI elements. Nuklear provides more control over window properties and layout, but at the cost of increased complexity.

13,679

A single-header ANSI C gui library

Pros of Nuklear

  • More comprehensive feature set, including advanced widgets and layout options
  • Highly customizable and flexible, allowing for deeper integration with existing codebases
  • Better cross-platform support, including mobile devices

Cons of Nuklear

  • Steeper learning curve due to its more complex API
  • Larger codebase and potentially higher memory footprint
  • Less beginner-friendly documentation compared to raygui

Code Comparison

Nuklear example:

struct nk_context ctx;
nk_init_default(&ctx, 0);
if (nk_begin(&ctx, "Demo", nk_rect(50, 50, 200, 200),
    NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
    NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
    nk_layout_row_dynamic(&ctx, 30, 1);
    if (nk_button_label(&ctx, "Button")) {
        // Button pressed
    }
}
nk_end(&ctx);

raygui example:

if (GuiButton((Rectangle){ 50, 50, 100, 30 }, "Button")) {
    // Button pressed
}

The code comparison shows that Nuklear requires more setup and has a more verbose API, while raygui offers a simpler, more straightforward approach for basic UI elements. Nuklear's example demonstrates its flexibility with window creation and styling options, which are not as readily available in raygui's simpler API.

10,698

Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

Pros of libui

  • Cross-platform native UI toolkit for C
  • Supports multiple programming languages through bindings
  • Provides a more comprehensive set of UI controls and layouts

Cons of libui

  • Less active development and maintenance
  • Steeper learning curve for beginners
  • Larger codebase and more complex architecture

Code Comparison

libui:

uiInit(NULL);
uiWindow *window = uiNewWindow("Hello", 300, 200, 0);
uiButton *button = uiNewButton("Click Me");
uiWindowSetChild(window, uiControl(button));
uiControlShow(uiControl(window));
uiMain();

raygui:

InitWindow(300, 200, "Hello");
while (!WindowShouldClose()) {
    BeginDrawing();
    if (GuiButton((Rectangle){100, 80, 100, 40}, "Click Me")) {
        // Handle click
    }
    EndDrawing();
}

Summary

While libui offers a more comprehensive native UI toolkit with cross-platform support and language bindings, raygui provides a simpler, more lightweight solution that integrates seamlessly with raylib. libui may be better suited for complex applications requiring native look and feel, while raygui excels in rapid prototyping and game development scenarios.

3,408

A tiny immediate-mode UI library

Pros of microui

  • Extremely lightweight and minimalistic (single-file implementation)
  • Easy to integrate into existing projects due to its simplicity
  • No external dependencies, making it highly portable

Cons of microui

  • Limited set of UI elements compared to raygui's more comprehensive offering
  • Less actively maintained, with fewer recent updates
  • Lacks some advanced features and customization options present in raygui

Code Comparison

microui:

mu_begin(ctx);
if (mu_button(ctx, "Hello")) {
  printf("Hello\n");
}
mu_end(ctx);

raygui:

GuiSetStyle(DEFAULT, TEXT_SIZE, 20);
if (GuiButton((Rectangle){ 50, 50, 100, 30 }, "Hello")) {
    printf("Hello\n");
}

Summary

microui is a minimalist immediate mode GUI library, ideal for simple projects or those requiring a lightweight solution. raygui offers a more feature-rich and actively maintained alternative, suitable for more complex applications with diverse UI needs. While microui excels in simplicity and ease of integration, raygui provides a broader range of UI elements and customization options.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

raygui is a simple and easy-to-use immediate-mode-gui library.

raygui was originally inspired by Unity IMGUI (immediate mode GUI API).

raygui was designed as an auxiliary module for raylib to create simple GUI interfaces using raylib graphic style (simple colors, plain rectangular shapes, wide borders...) but it can be adapted to other engines/frameworks.

raygui is intended for tools development; it has already been used to develop multiple published tools.


WARNING: Latest raygui from master branch is always aligned with latest raylib from master branch. Make sure to use the appropiate versions.

WARNING: Latest raygui 4.0 is an API-BREAKING redesign from previous versions (3.x), now all functions are more consistent and coherent, you can read the details about this breaking change in issue 283

NOTE: raygui is a single-file header-only library (despite its internal dependency on raylib), so, functions definition AND implementation reside in the same file raygui.h, when including raygui.h in a module, RAYGUI_IMPLEMENTATION must be previously defined to include the implementation part of raygui.h BUT only in one compilation unit, other modules could also include raygui.h but RAYGUI_IMPLEMENTATION must not be defined again.

features

  • Immediate-mode gui, no retained data
  • +25 controls provided (basic and advanced)
  • Powerful styling system for colors, font and metrics
  • Standalone usage mode supported (for other graphic libs)
  • Icons support, embedding a complete 1-bit icons pack
  • Multiple tools provided for raygui development

code sample

#include "raylib.h"

#define RAYGUI_IMPLEMENTATION
#include "raygui.h"

int main()
{
    InitWindow(400, 200, "raygui - controls test suite");
    SetTargetFPS(60);

    bool showMessageBox = false;

    while (!WindowShouldClose())
    {
        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();
            ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));

            if (GuiButton((Rectangle){ 24, 24, 120, 30 }, "#191#Show Message")) showMessageBox = true;

            if (showMessageBox)
            {
                int result = GuiMessageBox((Rectangle){ 85, 70, 250, 100 },
                    "#191#Message Box", "Hi! This is a message!", "Nice;Cool");

                if (result >= 0) showMessageBox = false;
            }

        EndDrawing();
    }

    CloseWindow();
    return 0;
}

screenshot000

raygui controls

basic controls

Label       |  Button      |  LabelButton |  Toggle      |  ToggleGroup  |  ToggleSlider
CheckBox    |  ComboBox    |  DropdownBox |  TextBox     |  ValueBox     |  Spinner
Slider      |  SliderBar   |  ProgressBar |  StatusBar   |  DummyRec     |  Grid

container/separator controls

WindowBox   |  GroupBox    |  Line        |  Panel       |  ScrollPanel  | TabBar

advanced controls

ListView    |  ColorPicker |  MessageBox  |  TextInputBox

raygui styles

raygui comes with a default style automatically loaded at runtime:

raygui default style

Some additional styles are also provided for convenience, just check styles directory for details:

raygui additional styles

Custom styles can also be created very easily using rGuiStyler tool.

Styles can be loaded at runtime using raygui GuiLoadStyle() function. Simple and easy-to-use.

raygui icons

raygui supports custom icons, by default, a predefined set of icons is provided inside raygui as an array of binary data; it contains 256 possible icons defined as 16x16 pixels each; each pixel is codified using 1-bit. The total size of the array is 2048 bytes.

To use any of those icons just prefix the #iconId# number to any text written within raygui controls:

if (GuiButton(rec, "#05#Open Image")) { /* ACTION */ }

It's also possible to use the provided GuiIconText() function to prefix it automatically, using a clearer identifier (defined in raygui.h).

if (GuiButton(rec, GuiIconText(RICON_FILE_OPEN, "Open Image"))) { /* ACTION */ }

Provided set of icons can be reviewed and customized using rGuiIcons tool.

raygui support tools

  • rGuiStyler - A simple and easy-to-use raygui styles editor.

    rGuiStyler v3.1

  • rGuiIcons - A simple and easy-to-use raygui icons editor.

    rGuiIcons v1.0

  • rGuiLayout - A simple and easy-to-use raygui layouts editor.

    rGuiLayout v2.2

building

raygui is intended to be used as a portable single-file header-only library, to be directly integrated into any C/C++ codebase but some users could require a shared/dynamic version of the library, for example, to create bindings:

  • Windows (MinGW, GCC)
copy src/raygui.h src/raygui.c
gcc -o src/raygui.dll src/raygui.c -shared -DRAYGUI_IMPLEMENTATION -DBUILD_LIBTYPE_SHARED -static-libgcc -lopengl32 -lgdi32 -lwinmm -Wl,--out-implib,src/librayguidll.a
  • Windows (MSVC)
copy src\raygui.h src\raygui.c
cl /O2 /I../raylib/src/ /D_USRDLL /D_WINDLL /DRAYGUI_IMPLEMENTATION /DBUILD_LIBTYPE_SHARED src/raygui.c /LD /Feraygui.dll /link /LIBPATH ../raylib/build/raylib/Release/raylib.lib /subsystem:windows /machine:x64
  • Linux (GCC)
mv src/raygui.h src/raygui.c
gcc -o raygui.so src/raygui.c -shared -fpic -DRAYGUI_IMPLEMENTATION -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
mv src/raygui.c src/raygui.h
  • Mac (clang, homebrew installed raylib)
cp src/raygui.h src/raygui.c
brew install raylib
gcc -o raygui.dynlib src/raygui.c -shared -fpic -DRAYGUI_IMPLEMENTATION -framework OpenGL -lm -lpthread -ldl $(pkg-config --libs --cflags raylib)

license

raygui is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.