#imgui #dear #bindings #ui #window #mouse #version

sys aflak_imgui-sys

Raw FFI bindings to dear imgui

1 unstable release

Uses old Rust 2015

0.18.1 Aug 11, 2018

#15 in #dear

38 downloads per month
Used in 5 crates (2 directly)

MIT/Apache

10MB
194K SLoC

C 101K SLoC // 0.2% comments C++ 45K SLoC // 0.1% comments Visual Studio Project 40K SLoC // 0.0% comments Rust 2K SLoC // 0.0% comments Python 2K SLoC // 0.8% comments Objective-C++ 1.5K SLoC // 0.1% comments Objective-C 768 SLoC // 0.1% comments Visual Studio Solution 606 SLoC Perl 422 SLoC // 0.1% comments M4 322 SLoC // 0.2% comments Shell 227 SLoC // 0.2% comments AWK 142 SLoC Batch 71 SLoC GLSL 64 SLoC Forge Config 36 SLoC // 0.8% comments HICAD 24 SLoC INI 8 SLoC

Contains (ELF exe/lib, 1MB) example_glfw_opengl3, (ELF exe/lib, 600KB) third-party/cimgui/imgui/imgui.o, (ELF exe/lib, 730KB) imgui.o, (static library, 295KB) glfw3.lib, (ELF exe/lib, 280KB) third-party/cimgui/imgui/imgui_demo.o, (ELF exe/lib, 295KB) third-party/cimgui/imgui/imgui_draw.o and 9 more.

imgui-rs: Rust bindings for ImGui

Still fairly experimental!

Minimum Rust version: 1.20

Build Status Documentation on docs.rs

Hello world

ui.window(im_str!("Hello world"))
    .size((300.0, 100.0), ImGuiCond::FirstUseEver)
    .build(|| {
        ui.text(im_str!("Hello world!"));
        ui.text(im_str!("This...is...imgui-rs!"));
        ui.separator();
        let mouse_pos = ui.imgui().mouse_pos();
        ui.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1));
    })

Currently implemented things

  • Low-level API (imgui-sys)
  • Renderer for easy integration with Glium projects (optional)
  • Parts of high-level API
  • Not horrible way of defining and passing null-terminated UTF-8 to ImGui. The macro im_str! needs to be used most of the time. For more information and justification for this design, please see issue #7
  • Parts of imgui_demo.cpp reimplemented in Rust as an API usage example (examples/test_window_impl.rs)

Important but unimplemented things

  • Documentation (rustdoc)
  • Support passing a custom Program to Glium renderer (e.g. from a shader cache, or custom shader)

Core design questions and current choices

  • Closures VS begin/end pairs (current choice: closures)
  • Mutable references VS return values (current choice: mutable references)
  • Passing around Ui<'ui> VS passing around &'ui Ui (current choice: Ui<'ui>)
  • Splitting the API to smaller pieces VS all draw calls in Ui (current choice: all draw calls in Ui)
  • Builder pattern for optional arguments VS something else (current choice: builder)
  • Mutation functions in builders VS self-consuming functions in builders (current choice: self-consuming)

Compiling and running the demos

Examples are under the imgui-examples directory.

git clone https://github.com/Gekkio/imgui-rs
cd imgui-rs
git submodule update --init --recursive
cd imgui-examples
cargo test

cargo run --example hello_world
cargo run --example test_window
cargo run --example test_window_impl

Note to Windows users: You will need to use the MSVC ABI version of the Rust compiler along with its associated dependencies to build this libary and run the examples.

How to contribute

  1. Change or add something

  2. Run rustfmt to guarantee code style conformance

     cargo install rustfmt
     cargo fmt -- --write-mode=overwrite
    
  3. Open a pull request in Github

License

Licensed under either of

at your option.

Uses ImGui and cimgui.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies