The test was failing because no `main` function was defined, as explained
in the rustdoc documentation [1].
Add the "no_run" flag. This way, there is no attempt to run the test
code. Only compile checks are done. Thus defining a `main` function is
unnecessary.
Moreover "export crate imgui" is implicit, so removed.
[1] https://doc.rust-lang.org/stable/rustdoc/documentation-tests.html#pre-processing-examples.
Include drawing canvas example into show_example_app_custom_rendering.
The example contains now everything included in the original C++ example
provided with dear imgui.
show_example_app_custom_rendering is implemented exactly as it is in the
original Dear ImGui in C++. The result should be the same.
The only difference is that `DragFloat`, used to control the size of the
drawings, is not implement as of now.
This example demonstrates how the custom drawing API can be used.
This commit defines a new enum: `ImMouseButton`, which is used in the
public-facing API of mouse-related methods.
The discriminant values of the ImMouseButton enum are the value used
internally by ImGui to represent the buttons of the mouse.
This commit adds two methods to the drawing APIs: with_clip_rect and
with_clip_rect_intersect.
Both wrap ImDrawList_PushClipRect and ImDrawList_PopClipRect.
However, with_clip_rect_intersect sets the `intersect` argument of
ImDrawList_PushClipRect to `true`.
As `add_rect_filled_multicolor` does not have any option, the `build`
pattern is not used and calling `add_rect_filled_multicolor` directly
draws the rectangle on the window.
This patch uses bitflags to set the whether the corners are rounded.
Hence the `ImDrawCornerFlags` struct is defined, but only used
internally.
Externally, the valule of the flags can be changed with methods on the
`Rect` structure such as `round_top_right` or `round_bot_left`.
This patch wraps both ImDrawList_AddRectFilled and ImDrawList_AddRect.
ImDrawList_AddRectFilled is seen as a particular case of `add_rect`
where `filled` is set to `true`.
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.
This reverts commit 0d10358942409cf8fad6fcb730dbedfbd7149df7.
`get_window_size` already exists and it's very easy to get just one
of the dimentions. As a result, delete get_window_width and
get_window_height.
If ImGui's mouse_draw_cursor is set to `true`, then ImGui draws the
cursor by itself, so this commits hids the OS cursor.
If ImGui's mouse_draw_cursor is set to `false`, then this commits
updates the OS cursor to the value set by the `set_mouse_cursor`
function provided by the ImGui instance.
For our use case, it seems safe to unwrap the result of the call to
glutin::Window::set_cursor_state, as an error can only potentially when
the `Grab` cursor state is used [1]. In ImGui's use case, the `Grab` state
is never used.
[1] https://docs.rs/crate/winit/0.11.2/source/src/platform/linux/x11/window.rs
Since the following pull request
https://github.com/tomaka/winit/pull/319, `winit` has deprecated
`get_inner_size_points()` and `get_inner_size_pixels()`.
We replace the deprecated API by `get_inner_size()` and
`hidpi_factor()`. The size in points in computed from the returned
hidpi_factor.