29 Commits

Author SHA1 Message Date
Nicolas
79951acf39 Replace static mut bool with AtomicBool 2019-07-15 04:34:47 -03:00
Joonas Javanainen
109e232422
Abolish ImVec2/ImVec4 from safe APIs
[f32; 2] and [f32; 4] are now the canonical types
2019-06-28 00:05:10 +03:00
Joonas Javanainen
c37bd8b1f9
Purge imgui-sys fully of legacy manual bindings 2019-06-27 22:12:35 +03:00
Joonas Javanainen
c1f48896e4
Use generated ImDraw* structs 2019-06-27 09:02:31 +03:00
Joonas Javanainen
319f7aa4c6
Reformat everything 2018-08-12 14:16:56 +03:00
Malik Olivier Boussejra
f0b3010684
Merge pull request #125 from malikolivier/draw_list_add_methods
window_draw_list: Add support for drawing text
2018-06-02 19:48:50 +09:00
Malik Olivier Boussejra
9b0804f6be window_draw_list: Use c_char instead of i8
Target expects a c_char, which happens to be an i8 on x86, but it may be
something else on other platforms (e.g. u8 on ARM).
2018-05-30 14:39:37 +09:00
Malik Olivier Boussejra
485c8a230e window_draw_list: Use generic to add_text
This change allows to use `add_text` with any type that implements
`AsRef<str>`. This includes `String`, `&str`, `ImString` and `&ImStr`.
2018-05-30 14:23:43 +09:00
Malik Olivier Boussejra
17504fd723 window_draw_list: Add #[must_use] to relevant types
It is easy to forget to call .build() on these temporary types.

To avoid this kind of error, we emit a compiler warning when .build() is
forgotten.
2018-05-23 17:57:55 +09:00
Malik Olivier Boussejra
429073a29c window_draw_list: Add support for drawing text 2018-05-23 11:33:11 +09:00
Malik Olivier Boussejra
892fe558a3 WindowDrawList: Get rid of DrawApi trait
Since there are no mutable borrows in the WindowDrawList API, we can remove all
draw functions from ChannelsSplit and just use the same `draw_list' all
the time, as shown in the `WindowDrawList::channels_split` example.

This approach makes the `DrawAPI` trait pointless so it can be removed, and
ChannelsSplit is reduced to a type with just one function:
`set_current`.
2018-04-24 13:23:39 +09:00
Malik Olivier Boussejra
9a9484ff21 ChannelsSplit: Rename channels_set_current to set_current
Fancier API
2018-04-24 13:23:08 +09:00
Malik Olivier Boussejra
454e98037e Do not allow to create coexisting instances of WindowDrawList
At run time, the environment checks that at most one instance of
WindowDrawList exists using a static boolean: WINDOW_DRAW_LIST_LOADED.

If two WindowDrawList could exist at the same time, there would be
several instances of the same `*mut ImDrawList`, which could lead
to unfathomable bad things.

When a WindowDrawList is created, WINDOW_DRAW_LIST_LOADED is set to
true. And when it is dropped, WINDOW_DRAW_LIST_LOADED is set to false.
Creating a new WindowDrawList while WINDOW_DRAW_LIST_LOADED is true
causes a panic.

AtomicBool could have been used instead of a bool for
WINDOW_DRAW_LIST_LOADED. Though it allows to avoid the use of `unsafe { }`,
the construct we are doing is already inherently unsafe.
WindowDrawList and Ui are !Send and !Sync, so they cannot anyway be shared
among threads.
So we'd better be explicit and use an unsafe block with a normal bool.
2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
082d5e47f9 window_draw_list: Fix awkward wording in doc 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
29b0d20fc1 ChannelsSplit: Panic when channel index overflows 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
95577a0d8c ui: Rename to with_window_draw_list ot get_window_draw_list 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
9a65a64eca WindowDrawList: Cannot use WindowDrawList::new outside of crate 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
3aa807b173 DrawAPI: Remove unused lifetime 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
7be9f15acb window_draw_list: Fix typo in doc 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
746bdc5ef3 ImColor: Derive Eq, PartialEq, Debug 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
eab85ea871 with_window_draw_list: Fix example test
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.
2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
664660a090 Add missing imports in example code 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
4358360d47 window_draw_list.rs: Wrap ImDrawList_PushClipRect
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`.
2018-04-16 15:09:55 +09:00
Malik Olivier Boussejra
35db5fca72 window_draw_list.rs: Wrap add_bezier_curve 2018-04-16 15:09:55 +09:00
Malik Olivier Boussejra
8471bd4034 window_draw_list.rs: Wrap add_triangle 2018-04-16 15:09:55 +09:00
Malik Olivier Boussejra
878de089e8 window_draw_list.rs: Wrap add_circle
ImDrawList_AddCircle was missing an argument in the bindings, resulting
in UB. This patches includes it and wrap the AddCircle API.
2018-04-16 15:09:55 +09:00
Malik Olivier Boussejra
d1879b2a04 window_draw_list.rs: Add add_rect_filled_multicolor
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.
2018-04-16 15:09:55 +09:00
Malik Olivier Boussejra
05b382e317 WindowDrawList: Wrap add_rect method
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`.
2018-04-16 15:09:55 +09:00
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