xur_

> module

std::gui

desktop GUI with egui

use std::gui; feature gui native only

std::gui provides an immediate-mode GUI backed by egui. Call gui::run or gui::dialog with a title and a draw function; it is called every frame with a Ui to add widgets to. Widgets don't keep state between frames: pass the current value in and store what comes back. A closure keeps its own copy of the variables it captures, and changes to that copy last from frame to frame, so state can live in variables declared before gui::run. To see the changes outside the closure, keep the state in a cell (see xur.std.cell(7)).

In-game overlays such as std::stub::unity::egui call their draw function with a Ctx instead, and open windows from it.

run and dialog need the gui feature; the Ui and Ctx types also exist without it, for overlays.

> functions

# dialog(title: str, draw: fn(Ui))

Like run, but asks the window manager for a dialog window (on X11).

# run(title: str, draw: fn(Ui))

Opens a 600×400 window and calls draw every frame until the window is closed. An error in draw is shown in red in the window instead of stopping the program.

> types

┌ type Ctx
# ctx.free_texture(tex: Texture)

Releases a texture from load_texture_rgba. Other textures are left alone.

# ctx.load_texture_rgba(name: str, width: i64, height: i64, rgba: bytes) -> Result<Texture, str>

Uploads width × height pixels of RGBA, 4 bytes per pixel, and returns a texture for image. Returns Err if rgba has the wrong length.

# ctx.window(title: str, body: fn(Ui) -> T) -> T | ()

A movable window inside the overlay, 400 points wide by default. Returns what body returns, or () when the window is collapsed. An error in body is shown in red in the window.

# ctx.window_sized(title: str, width: f64, body: fn(Ui) -> T) -> T | ()

Like window, but at most width points wide.

┌ enum Texture

A texture id handed to Xur scripts. Mirrors `egui::TextureId`: a `Managed` texture is one uploaded to egui (e.g. `load_texture_rgba`), a `User` texture is a native game texture registered by a backend (e.g. a Unity texture). The `image` widget renders either; scripts just hold and pass it.

Texture::Managed(i64)
Texture::User(i64)
┌ type Ui

Methods that take a body function call it with a nested Ui and return what it returns. An error in a nested body is logged and the rest of the frame is drawn.

# ui.add_space(amount: f64)

Empty space of amount points.

# ui.button(text: str) -> bool

A button; returns true in the frame it is clicked.

# ui.checkbox(checked: bool, label: str) -> bool

A checkbox; returns the new checked state.

# ui.collapsing(heading: str, body: fn(Ui) -> T) -> T | ()

A section that opens and closes when its heading is clicked. body runs only while it is open; otherwise the result is ().

# ui.colored_label(r: i64, g: i64, b: i64, text: str)

Shows text in an RGB colour; each component is 0–255.

# ui.dialog(title: str, body: fn(Ui))

Shows another native 400×300 window, or a dialog window, drawn by body. Keep calling it every frame to keep the window open. Needs the gui feature.

# ui.end_row()

Ends the current row of a grid.

# ui.grid(id: str, columns: i64, body: fn(Ui) -> T) -> T

A striped grid with columns columns. Widgets fill a row left to right; call end_row to start the next row. id must be unique among grids in the window.

# ui.heading(text: str)

Shows text at normal, heading or small size.

# ui.horizontal(body: fn(Ui) -> T) -> T

Lays out the widgets body adds side by side, or one above the other.

# ui.hover_text(tip: str, body: fn(Ui) -> T) -> T

Groups the widgets body adds and shows tip as a tooltip when the pointer is over them. An empty tip shows nothing.

# ui.image(tex: Texture, width: f64, height: f64)

Draws a texture at the given size in points.

# ui.label(text: str)

Shows text at normal, heading or small size.

# ui.panel_left(id: str, body: fn(Ui))

A panel on the left side. Errors in body are ignored. Needs the gui feature.

# ui.scroll(id?: str, max_height?: f64, body: fn(Ui) -> T) -> T

A vertical scroll area. id and max_height are optional: give an id when there is more than one scroll area, and max_height to limit its height in points.

# ui.selectable(selected: bool, text: str) -> bool

A label that can be highlighted, drawn as selected when selected is true. Returns true in the frame it is clicked.

# ui.separator()

A horizontal line.

# ui.slider_float(label: str, value: f64, min: f64, max: f64) -> f64

A slider over [min, max]; returns the new value. The float slider works in 32-bit precision.

# ui.slider_int(label: str, value: i64, min: i64, max: i64) -> i64

A slider over [min, max]; returns the new value. The float slider works in 32-bit precision.

# ui.small(text: str)

Shows text at normal, heading or small size.

# ui.text_edit(text: str) -> str

A single-line or multi-line text box; returns the new text.

# ui.text_edit_multiline(text: str) -> str

A single-line or multi-line text box; returns the new text.

# ui.vertical(body: fn(Ui) -> T) -> T

Lays out the widgets body adds side by side, or one above the other.

# ui.window(title: str, body: fn(Ui))

Shows another native 400×300 window, or a dialog window, drawn by body. Keep calling it every frame to keep the window open. Needs the gui feature.

> textures

A Texture is a handle to an image that image can draw. It is an enum with two variants: Managed(i64) for an image uploaded with load_texture_rgba and User(i64) for a native game texture registered by an engine module, such as unity::egui::register_texture. Scripts normally just hold one and pass it to image.

> examples

use std::fmt;
use std::gui;

fn main() {
    let name = "";
    let clicks = 0;

    gui::run("Hello", |ui| {
        ui.heading("Hello from Xur!");
        name = ui.text_edit(name);
        if name != "" {
            ui.label(fmt::format("Hello, {}!", name));
        }
        if ui.button("Click me") {
            clicks = clicks + 1;
        }
        ui.label(fmt::format("{} click(s)", clicks));
    });
}