Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

raygui

raygui is an immediate-mode GUI toolkit bundled with raylib. raylib-rs 6.0 exposes all 57 RAYGUIAPI functions at parity with raygui 6.0. Controls are grouped into sub-traits (RaylibGuiControls, RaylibGuiContainers, RaylibGuiState, RaylibGuiAdvanced, RaylibGuiIcons) and blanket-implemented for every draw handle — just use raylib::prelude::* and the methods are available inside a begin_drawing frame.

String parameters accept impl AsRef<str> (pass &str, String, or any type that derefs to a string slice) — conversion goes through a thread-local scratch buffer so there are no per-frame heap allocations.

Feature gate. raygui is behind the raygui Cargo feature. Add features = ["raygui"] (or "full") to your Cargo.toml dependency.

API surface

Example

raygui controls require an active drawing frame and a GPU context. The example below is marked ignore because the software_renderer feature is mutually exclusive with the default OpenGL build used by the book’s CI. The WS9 showcase will provide a runnable raygui demo once the web gallery is deployed.

extern crate raylib;
use raylib::prelude::*;

fn main() {
    let (mut rl, thread) = raylib::init()
        .size(400, 300)
        .title("raygui demo")
        .build();

    let mut slider_val: f32 = 0.5;

    while !rl.window_should_close() {
        let mut d = rl.begin_drawing(&thread);
        d.clear_background(Color::RAYWHITE);

        // Label
        d.gui_label(
            Rectangle::new(20.0, 20.0, 200.0, 30.0),
            "Hello, raygui!",
        );

        // Button — returns true on click
        if d.gui_button(Rectangle::new(20.0, 60.0, 120.0, 30.0), "Click me") {
            println!("button clicked");
        }

        // Slider — mutates slider_val in place
        d.gui_slider(
            Rectangle::new(20.0, 110.0, 200.0, 20.0),
            "Min",
            "Max",
            &mut slider_val,
            0.0,
            1.0,
        );
    }
}

Gotchas

  • String parameters are impl AsRef<str>. Pass &str, String, or any type implementing AsRef<str>. Under the hood, each call writes the string to a thread-local CString scratch buffer — safe and zero-alloc per frame.
  • GUI state is global. raygui is immediate-mode; all style and state (gui_set_state, gui_load_style) affects every control drawn this frame. Call ordering matters.
  • gui_load_style_from_memory is absent from the vendored raygui header (backlog #296 — deferred until the vendored raygui advances).
  • raygui feature required. Without features = ["raygui"] the trait methods are not compiled in.

See also

Showcase examples

Showcase examples that exercise this module: