xur_

> module

std::stub::overlay::egui

engine-agnostic egui overlay (OpenGL/Vulkan)

use std::stub::overlay::egui; feature overlay native only

std::stub::overlay::egui draws an egui immediate-mode GUI over any game that renders with OpenGL or Vulkan, by hooking the swapchain present. Both backends are hooked; whichever the game uses first wins. Unlike std::stub::unity::egui, it needs no engine runtime. Call init() in ctor(), then run() in stub_main().

Each frame the render thread hands its egui context to the run() thread and waits until the draw function returns. The draw function receives a Ctx; its windows and widgets are the std::gui ones — see xur.std.gui(7). This module also gives Ctx a key(name) method that is true while a key is held, read from egui's input. Key names (case-insensitive): f1–f5, escape/esc, space, tab, return/enter. Unknown names are never pressed.

> functions

# frame_count() -> i64

The number of frames the render hook has seen since init(), counted whether or not run() has started; 0 before init().

# init()

Install the OpenGL and Vulkan render hooks. Call it from ctor(), before the game creates its renderer.

# run(draw: fn(Ctx))

Enter the draw loop: calls draw once per presented frame with a Ctx. Blocks for the life of the process. Raises if init() wasn't called. A runtime error in draw is logged and shown in an "xur error" window for that frame; the loop keeps going.

# set_scale(factor: f64) -> Result<(), EguiError>

Set the overlay's UI scale (1.0 = default; below shrinks, above enlarges). Fails with EguiError::InvalidScale if factor is not positive.

> types

┌ enum EguiError
EguiError::InvalidScale
EguiError::NotInitialized

> examples

use std::stub::overlay::egui;
use std::fmt;

fn ctor() {
    egui::init();
}

fn stub_main() {
    let clicks = 0;
    egui::run(|ctx| {
        ctx.window("Overlay", |ui| {
            ui.label(fmt::format("frame {}", egui::frame_count()));
            if ui.button("Click me") { clicks = clicks + 1; }
            ui.label(fmt::format("clicked {} times", clicks));
        });
    });
}