213 Commits

Author SHA1 Message Date
Malik Olivier Boussejra
0e1ec3cb6a fonts: Use ImFontConfig_DefaultConstructor to initialize sys::ImFontConfig 2018-05-05 12:13:28 +09:00
Malik Olivier Boussejra
abd39597ed input: Add API to set read_only, password and no_undo_redo falgs 2018-04-30 12:46:18 +09:00
Malik Olivier Boussejra
112d21133b [cimgui 1.53.1] Remove ImGuiWindowFlags::ShowBorders 2018-04-30 11:56:10 +09:00
Malik Olivier Boussejra
adfa447d2f [cimgui 1.53.1] Style: Add PopupRounding, FrameBorderSize, WindowBorderSize, PopupBorderSize 2018-04-30 11:43:17 +09:00
Malik Olivier Boussejra
3b231d9838 [cimgui 1.53.1] Rename ChildWindowRounding to ChildRounding
Add deprecation warning for each renamed variant.

However, it will just fail to compile if the deprecated variant is used
inside a match statement. It is not possible to make aliases of variants
in Rust.
2018-04-30 11:28:17 +09:00
Malik Olivier Boussejra
cf15d49e36 [cimgui 1.53.1] Rename Ui::show_test_window to Ui::show_demo_window 2018-04-29 23:49:26 +09:00
Joonas Javanainen
99aeb18299
Merge pull request #116 from michaelfairley/master
Add drag widgets
2018-04-29 11:57:15 +03:00
Michael Fairley
90c096183c Add drag widgets 2018-04-24 15:22:08 -05: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
734292fdab imgui: Make ChannelsSplit struct visible outside the crate 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
43a2484c22 ImMouseButton: Derive Copy, Clone, Eq, PartialEq, Debug
For convenience.
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
738a9c978e ui: Wrap get_content_region_avail 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
c58a93bfc1 ui: Wrap invisible_button 2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
15048ad698 ui: Add mouse helper methods is_mouse_{dragging,down,clicked}
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.
2018-04-16 15:14:04 +09:00
Malik Olivier Boussejra
a60465cd40 ui: Wrap dummy 2018-04-16 15:14:01 +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
Joonas Javanainen
b6e5086eb2
Merge pull request #112 from Lymia/master
Implement custom fonts.
2018-04-16 08:51:02 +03:00
Joonas Javanainen
a662155972
Merge pull request #110 from malikolivier/add-miscellaneous-wrappers
Add some helper functions: mouse_delta, get_window_size, is_item_active
2018-04-16 08:49:12 +03:00
Malik Olivier Boussejra
1a1fe3bad5 Wrap get_text_line_height_with_spacing && get_item_rect_size 2018-04-13 14:27:22 +00:00
Malik Olivier Boussejra
43ea9a9693 Wrap BeginGroup / EndGroup 2018-04-13 14:19:37 +00:00
Malik Olivier Boussejra
6515779000 Wrap utilities to get and set Ui's cursor
This utilities are set_cursor_screen_pos, set_cursor_pos, get_cursor_screen_pos
and get_cursor_pos.
2018-04-13 14:12:29 +00:00
Malik Olivier Boussejra
435eeaf892 imgui: Add with_style_and_color_vars convenient function
Wraps with_style_vars and with_color_vars inside a single call.
2018-04-13 13:49:06 +00:00
Malik Olivier Boussejra
4ccae8bc10 Revert "imgui: Add get_window_width, get_window_height helper functions"
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.
2018-04-13 13:46:27 +00:00
Lymia Aluysia
c5775ef53c
Adjust custom font functions to use Into with ImVec2. 2018-04-13 04:26:16 -05:00
Lymia Aluysia
228192bb9b
Use f32 instead of f64 for font sizes/etc for consistancy with imgui. 2018-04-13 04:21:01 -05:00
Lymia Aluysia
5b2c1f0861
Implement custom fonts. 2018-04-07 20:30:47 -05:00
Malik Olivier Boussejra
0d10358942 imgui: Add get_window_width, get_window_height helper functions 2018-03-26 17:21:27 +09:00
Malik Olivier Boussejra
d6897b1556 ImGui: Add safe wrapper around igGetWindowSize 2018-03-26 17:17:46 +09:00
Malik Olivier Boussejra
72ddc788b1 imgui: Ui: Add is_item_active 2018-03-26 17:17:02 +09:00
Malik Olivier Boussejra
abbbfdfa79 imgui: Add mouse_delta 2018-03-26 17:17:02 +09:00
Malik Olivier Boussejra
785f773966 imgui: Add method to set/get mouse cursor
Include some documentation as well.
2018-03-26 14:04:00 +09:00
Malik Olivier Boussejra
42be8d69ed lib.rs: Add function to know whever Ctrl, Alt or Shift are pressed 2018-03-15 14:57:58 +09:00
Jingkai Mao
bef6702a8f Use $crate instead of ::imgui. 2017-12-13 14:57:53 +08:00