Malik Olivier Boussejra db97041936 window_draw_list.rs: Basic structure to wrap ImGui's draw API
This patch makes the basic structure for a wrapper around Dear ImGui's
drawing API.

1. Implement `with_window_draw_list` method on Ui. Call this method to
get access to the `WindowDrawList` object. This object holds the methods
to access ImGui's drawing API.

2. Dear ImGui uses the ImU32 (an unsigned c_int) to represent colors in
the drawing API. This commit wraps this type with ImColor for
convenience.  Any color representation (3or4-tuples, 3or4-arrays, ImU32
or ImVec4) can be converted into ImColor for convenience.

3. Difference between WindowDrawList and ChannelsSplit: Most drawing
functions can be called on WindowDrawList and ChannelsSplit objects.
However for safety, some functions can only be called on WindowDrawList
or ChannelsSplit instance. For example `channels_set_current` can only
be called after channels have been split.  To avoid code duplication,
functions common to WindowDrawList and ChannelsSplit are implemented
within the `impl_draw_list_methods` macro.

4. Implement drawing functions (in this commit, add_line only).  Calling
`add_line` returns a default representation of the line to be drawn, but
does not draw it. Then parameters, such as thickness, can be set.  You
must call `build` to draw the line. All drawing functions will be
implemented following this pattern.
2018-04-16 15:09:55 +09:00
2018-04-14 22:38:34 +01:00
2015-08-18 00:12:58 +03:00
2015-08-31 21:23:01 +03:00
2017-12-23 14:25:43 +02:00
2017-12-23 14:25:43 +02:00
2018-04-07 20:30:47 -05:00
2017-02-14 20:56:18 +02:00
2018-04-07 20:30:47 -05:00
2017-02-15 20:43:20 +02:00

imgui-rs: Rust bindings for ImGui

Still fairly experimental!

Minimum Rust version: 1.20

Build Status Latest release on crates.io 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!("こんにちは世界!"));
        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.

Description
No description provided
Readme 9.9 MiB
Languages
Rust 99.9%