[][src]Crate imgui_ext

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

Annotations map directly to a subset of imgui types and methods:

Annotation Imgui Type
slider(...) SliderFloat, SliderFloat2, SliderFloat3, SliderFloat4, SliderInt, SliderInt2, SliderInt3, SliderInt4
drag(...) DragFloat, DragFloat2, DragFloat3, DragFloat4, DragInt, DragInt2, DragInt3, DragInt4
input(...) InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputInt2, InputInt3, InputInt4
text(...) InputText, InputTextMultiLine
button(...) Ui::button, Ui::small_button
checkbox(...) Ui::checkbox
separator(...) Ui::separator
new_line(...) Ui::new_line
display(...) Ui::label_text
bullet(...) Ui::bullet_text, Ui::bullet
nested(...) See nested module.

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"),
        display(label = "Is turbo enabled?"),
    )]
    turbo: bool,
}

ui result

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(text(catch = "text"))]
    text: ImString,
}

// init imgui (ui)...

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);
}

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.

display

display(...) docs.

drag

drag(...) docs.

input

input(...) docs.

layout

Support for some (basic) layout annotations.

nested

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

prelude
slider

slider(...) docs.

text

text(...) 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