imgui-log

Crates.ioimgui-log
lib.rsimgui-log
version0.1.0
sourcesrc
created_at2019-10-07 06:58:49.859114
updated_at2019-10-07 06:58:49.859114
descriptionlog backend that mirrors to an imgui window and/or stdout
homepage
repositoryhttps://github.com/Smasher816/imgui-log
max_upload_size
id170524
size198,039
Rowan Decker (smasher816)

documentation

README

imgui-log

A logger that routes logs to an imgui window.

Supports both standalone mode (hook into your ui yourself), and an amethyst-imgui system (automatically rendered every frame).

preview

Setup

Add this to your Cargo.toml

[dependencies]
imgui-log = "0.1.0"

Basic Example

// Start the logger
let log = imgui_log::init(); 

// Create your UI
let ui: imgui::Ui = ... ;

// Render loop
loop {
    // Output some info
    info!("Hello World");

    // Draw to a window
    let window = imgui::Window::new(im_str!("My Log"));
    log.draw(&ui, window);
}

Configuring

A default config is provided, but you are free to customize the format string, coloring, etc if desired.

imgui_log::init_with_config(LoggerConfig::default()
    .stdout(false)
    .colors(LogColors {
        trace: [1., 1., 1., 1.],
        debug: [1., 1., 1., 1.],
        info: [1., 1., 1., 1.],
        warn: [1., 1., 1., 1.],
        error: [1., 1., 1., 1.],
    })
);

Amethyst usage

Enable the amethyst-system feature.

[dependencies]
imgui-log = { version = "0.1.0", features = ["amethyst-system"] }

Replace imgui::init with imgui_log::create_system and add it to your app's .with() statements

Add the RenderImgui plugin if it is not already being used. (This is re-exported from the amethyst-imgui crate for your convenience)

    use imgui_log::amethyst_imgui::RenderImgui;

    /// ....

    let app_root = application_root_dir()?;
    let display_config_path = app_root.join("examples/display.ron");
    let game_data = GameDataBuilder::default()
        .with_barrier()
        .with(imgui_log::create_system(), "imgui_log", &[]) // <--- ADDED LINE 
        .with_bundle(InputBundle::<StringBindings>::default())?
        .with_bundle(
            RenderingBundle::<DefaultBackend>::new()
                .with_plugin(
                    RenderToWindow::from_config_path(display_config_path)
                        .with_clear([0.34, 0.36, 0.52, 1.0]),
                )
                .with_plugin(RenderImgui::<StringBindings>::default()), // <--- ADDED LINE
        )?;

    Application::build("/", Example)?.build(game_data)?.run();
Commit count: 2

cargo fmt