[][src]Crate imgui_ext

A crate to quickly build imgui GUIs using a #[derive] macro.

Basic usage

use imgui_ext::prelude::*;

#[derive(ImGuiExt)]
struct Example {
    #[imgui(slider(min = 0.0, max = 4.0))]
    x: f32,
    #[imgui(input(step = 2))]
    y: i32,
    #[imgui(drag(label = "Drag 2D"))]
    drag_2d: [f32; 2],

    #[imgui(
        checkbox(label = "Turbo mode"),
        label(label = "Is turbo enabled?"),
    )]
    turbo: bool,
}

ui result

Static code generation

The generated code won't contain extra dynamic allocations.

In this example you can see what the generated code looks like.

Nested UIs

Types that #[derive(ImGuiExt)] can be nested:

use imgui::{ImString, ImGuiInputTextFlags};
use imgui_ext::prelude::*;

#[derive(ImGuiExt)]
struct Form {
    #[imgui(input)]
    user: ImString,
    #[imgui(input(flags = "passwd_flags"))]
    passwd: ImString,
    #[imgui(button(label = "Login", size = "size"))]
    _btn: (),
}

fn passwd_flags() -> ImGuiInputTextFlags {
    ImGuiInputTextFlags::Password
}

fn size() -> (f32, f32) {
    (64.0, 24.0)
}

#[derive(ImGuiExt)]
struct Example {
    #[imgui(nested)]
    login_form: Form,
    #[imgui(checkbox(label = "Remember login?"))]
    remember: bool,
}

Input events

Most annotations can take an optional catch = "..." parameter which can be used to identify when a button is pressed, an input has changed, etc.., later on:

This example is not tested
use imgui_ext::prelude::*;

#[derive(ImGuiExt)]
struct Example {
    #[imgui(checkbox(catch = "check"))]
    input_check: bool,
    #[imgui(input(catch = "text"))]
    text: ImString,
}

let events = ui.imgui_ext(&mut example);
if events.check {
    println!("New value: {}", example.input_check);
}
if events.text {
    println!("New text value: {:?}", example.text);
}

Limitations

Not available for nested UIs yet. See #0

Combining UI and non-UI fields

If a field is not annotated, it will be ignored in the UI.

use imgui_ext::prelude::*;

#[derive(ImGuiExt)]
struct Example {
    #[imgui(label = "Some i32")]
    in_ui: u32,

    // since this field is not annotated, it is ignored by the UI
    not_in_ui: Vec<u8>,
}

Descriptive errors

UI correctness is checked at compile time.

This example is not tested
#[derive(ImGuiExt)]
struct Example {
    #[imgui(slider(min = 0.0))]
    foo: f32,
}
error: Parameter `max` missing.
  --> example/src/main.rs:10:13
   |
10 |     #[imgui(slider(min = 0.0))]
   |             ^^^^^^

Re-exports

pub use imgui_ext_derive::ImGuiExt;

Modules

bullet

bullet(...) docs.

button

button(...) docs.

checkbox

checkbox(...) docs.

drag

drag(...) docs.

input

input(...) docs.

label

label(...) docs.

layout

Support for some (basic) layout annotations.

nested

nested(...) docs (used to build nested UIs).

prelude
slider

slider(...) docs.

Macros

Events

A macro that expands to the type that contains the UI events.

Traits

ImGuiExt

Trait implemented by the derive macro.

UiExt

Extension trait for imgui Ui.

Functions

imgui_ext

Render imgui UI and collect all the events