[][src]Crate imgui_ext

Derive macro that allows you to quickly build immediate mode UIs (based on the imgui crate).

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,
}

Input events

In immediate mode UI, generally you respond to user inputs (button presses, value changes, etc...) at the same time that you render the UI.

With imgui-ext, you have to first render the UI, and then check for these events:

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

#[derive(ImGuiExt)]
struct Example {
    #[imgui(checkbox(label = "Checkbox"))]
    check: bool,
}

// init imgui (ui)...

// All events are stored as booleans in the returned type.
let events = ui.imgui_ext(&mut example);

if events.check() {
    // Checkbox value has changes.
    // Do something...
}

In the above example, the checkbox event is mapped to the method check() of the type returned by the call to ui.imgui_ext(...). The name of the method is the same as the field. You can override this value by defining the catch parameter in the annotation:

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

#[derive(ImGuiExt)]
struct Example {
    #[imgui(checkbox(label = "Checkbox", catch = "checkbox_event"))]
    check: bool,
}

// init imgui (ui)...

let events = ui.imgui_ext(&mut example);

if events.checkbox_event() {
    // Do something...
}

Nice compiler errors

UI correctness is checked at compile time. If you mistype an annotation, the compiler will point you directly to the issue:

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.

color

color(...) 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(...) and text_wrap(...) docs.

tree

tree(...) docs.

vars

vars(...) docs.

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

Type Definitions

Events

Alias for the ImGuiExt::Events associated type.