From abbbfdfa79fee0a31257cbba307d838779d2b0a7 Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Mon, 26 Mar 2018 00:31:23 +0900 Subject: [PATCH 1/9] imgui: Add mouse_delta --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ef59fc7..36b960a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,6 +190,11 @@ impl ImGui { io.mouse_pos.x = x; io.mouse_pos.y = y; } + /// Get mouse's position's delta between the current and the last frame. + pub fn mouse_delta(&self) -> (f32, f32) { + let io = self.io(); + (io.mouse_delta.x, io.mouse_delta.y) + } pub fn set_mouse_down(&mut self, states: &[bool; 5]) { let io = self.io_mut(); io.mouse_down = *states; From 72ddc788b17ee2304656984eb1f9384d25b8f0b9 Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Mon, 26 Mar 2018 13:38:24 +0900 Subject: [PATCH 2/9] imgui: Ui: Add is_item_active --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 36b960a..4a15b2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1099,4 +1099,11 @@ impl<'ui> Ui<'ui> { pub fn is_item_hovered(&self) -> bool { unsafe { sys::igIsItemHovered(ImGuiHoveredFlags::empty()) } } + + /// Returns `true` if the last item is being active. + pub fn is_item_active(&self) -> bool { + unsafe { + sys::igIsItemActive() + } + } } From d6897b15562dcac22bdf1be364c05af9608e103a Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Sun, 25 Mar 2018 23:08:15 +0900 Subject: [PATCH 3/9] ImGui: Add safe wrapper around igGetWindowSize --- src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4a15b2b..7bee4ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -384,6 +384,14 @@ impl<'a> Ui<'a> { // Window impl<'ui> Ui<'ui> { pub fn window<'p>(&self, name: &'p ImStr) -> Window<'ui, 'p> { Window::new(self, name) } + /// Get current window's size in pixels + pub fn get_window_size(&self) -> (f32, f32) { + let mut out = ImVec2::new(0.0, 0.0); + unsafe { + sys::igGetWindowSize(&mut out as *mut ImVec2); + } + (out.x, out.y) + } } // Layout From 0d10358942409cf8fad6fcb730dbedfbd7149df7 Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Mon, 26 Mar 2018 16:10:47 +0900 Subject: [PATCH 4/9] imgui: Add get_window_width, get_window_height helper functions --- src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7bee4ba..bbc23d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -392,6 +392,18 @@ impl<'ui> Ui<'ui> { } (out.x, out.y) } + /// Get current window's width in pixels + pub fn get_window_width(&self) -> f32 { + unsafe { + sys::igGetWindowWidth() + } + } + /// Get current window's height in pixels + pub fn get_window_height(&self) -> f32 { + unsafe { + sys::igGetWindowHeight() + } + } } // Layout From 4ccae8bc10e596a15393a3b3c033ac0471d317c0 Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Fri, 13 Apr 2018 13:45:30 +0000 Subject: [PATCH 5/9] 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. --- src/lib.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bbc23d2..7bee4ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -392,18 +392,6 @@ impl<'ui> Ui<'ui> { } (out.x, out.y) } - /// Get current window's width in pixels - pub fn get_window_width(&self) -> f32 { - unsafe { - sys::igGetWindowWidth() - } - } - /// Get current window's height in pixels - pub fn get_window_height(&self) -> f32 { - unsafe { - sys::igGetWindowHeight() - } - } } // Layout From 435eeaf8924b751fe79c376defa781d6fbbd575e Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Mon, 26 Mar 2018 16:47:40 +0900 Subject: [PATCH 6/9] imgui: Add with_style_and_color_vars convenient function Wraps with_style_vars and with_color_vars inside a single call. --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7bee4ba..2be116b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1088,6 +1088,24 @@ impl<'ui> Ui<'ui> { } } +impl<'ui> Ui<'ui> { + /// Runs a function after temporarily pushing an array of values to the + /// style and color stack. + pub fn with_style_and_color_vars( + &self, + style_vars: &[StyleVar], + color_vars: &[(ImGuiCol, C)], + f: F, + ) where + F: FnOnce(), + C: Into + Copy, + { + self.with_style_vars(style_vars, || { + self.with_color_vars(color_vars, f); + }); + } +} + /// # Utilities impl<'ui> Ui<'ui> { /// Returns `true` if the last item is being hovered by the mouse. From 6515779000eddfefd3937c73808ed5424ddbffe3 Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Fri, 13 Apr 2018 14:10:00 +0000 Subject: [PATCH 7/9] 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. --- src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 2be116b..b7b63bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -444,6 +444,40 @@ impl<'ui> Ui<'ui> { } pub fn get_columns_count(&self) -> i32 { unsafe { sys::igGetColumnsCount() } } + + /// Get cursor position on the screen, in screen coordinates. + /// This sets the point on which the next widget will be drawn. + /// + /// This is especially useful for drawing, as the drawing API uses + /// screen coordiantes. + pub fn get_cursor_screen_pos(&self) -> (f32, f32) { + let mut out = ImVec2::new(0.0, 0.0); + unsafe { + sys::igGetCursorScreenPos(&mut out); + } + (out.x, out.y) + } + + /// Set cursor position on the screen, in screen coordinates. + /// This sets the point on which the next widget will be drawn. + pub fn set_cursor_screen_pos>(&self, pos: P) { + unsafe { sys::igSetCursorScreenPos(pos.into()) } + } + + /// Get cursor position on the screen, in window coordinates. + pub fn get_cursor_pos(&self) -> (f32, f32) { + let mut out = ImVec2::new(0.0, 0.0); + unsafe { + sys::igGetCursorPos(&mut out); + } + (out.x, out.y) + } + + /// Set cursor position on the screen, in window coordinates. + /// This sets the point on which the next widget will be drawn. + pub fn set_cursor_pos>(&self, pos: P) { + unsafe { sys::igSetCursorPos(pos.into()) } + } } // ID scopes From 43ea9a96930520f0bbbae2db1d6633449964b55a Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Fri, 13 Apr 2018 14:19:23 +0000 Subject: [PATCH 8/9] Wrap BeginGroup / EndGroup --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b7b63bb..33ca86c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1166,4 +1166,13 @@ impl<'ui> Ui<'ui> { sys::igIsItemActive() } } + + /// Group items together as a single item. + /// + /// May be useful to handle the same mouse event on a group of items, for example. + pub fn group(&self, f: F) { + unsafe { sys::igBeginGroup(); } + f(); + unsafe { sys::igEndGroup(); } + } } From 1a1fe3bad5fc22d02c35ad7da0a879628aba8b3d Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Fri, 13 Apr 2018 14:27:22 +0000 Subject: [PATCH 9/9] Wrap get_text_line_height_with_spacing && get_item_rect_size --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 33ca86c..418b3c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -953,6 +953,19 @@ impl<'ui> Ui<'ui> { } } +impl<'ui> Ui<'ui> { + /// Get height of a line of previously drawn text item + pub fn get_text_line_height_with_spacing(&self) -> f32 { + unsafe { sys::igGetTextLineHeightWithSpacing() } + } + /// Get previously drawn item's size + pub fn get_item_rect_size(&self) -> (f32, f32) { + let mut out = ImVec2::new(0.0, 0.0); + unsafe { sys::igGetItemRectSize(&mut out); } + (out.x, out.y) + } +} + impl<'ui> Ui<'ui> { /// Creates a progress bar. Fraction is the progress level with 0.0 = 0% and 1.0 = 100%. ///