[][src]Crate imgui_ext

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

Supported annotations

Annotations map to a subset of imgui types and methods:

Annotation Mapped Imgui Types
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
progress(...) ProgressBar
image(...) Image
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(...)

Basic usage

use imgui_ext::ImGuiExt;

// Make your type derive ImGuiExt and place annotations on the fields you want
// to include in the ui
#[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,

    // not every field has to be annotated
    _not_in_ui: Vec<u8>
}

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::ImGuiExt;

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

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))]
   |             ^^^^^^

Contributions

Feedback, suggestions, and contributions, are very much welcome!

Please file an issue or open a PR to germangb/imgui-ext if you wish to do so.

Re-exports

pub use imgui_ext_derive::ImGuiExt;

Modules

bullet

bullet(...) docs.

button

button(...) docs.

checkbox

checkbox(...) docs.

display

display(...) docs.

drag

drag(...) docs.

image

image(...) docs.

input

input(...) docs.

layout

Support for some (basic) layout annotations.

nested

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

prelude
progress

progress(...) docs.

slider

slider(...) docs.

text

text(...) docs.

Macros

Events

A macro that expands to the type that contains catched input 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