From 290429bd128eb4ba9d3c8a983a46be5829bd20cd Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Fri, 24 Apr 2020 23:20:45 +0300 Subject: [PATCH] Replace old nonUDT2 function variants --- src/fonts/mod.rs | 4 +++- src/input/mouse.rs | 12 +++++++++--- src/layout.rs | 12 +++++++++--- src/lib.rs | 8 +++++--- src/utils.rs | 12 +++++++++--- src/window/content_region.rs | 16 ++++++++++++---- src/window/mod.rs | 8 ++++++-- 7 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/fonts/mod.rs b/src/fonts/mod.rs index 0ee9f38..0420ced 100644 --- a/src/fonts/mod.rs +++ b/src/fonts/mod.rs @@ -21,7 +21,9 @@ impl<'ui> Ui<'ui> { /// /// Useful for drawing custom shapes with the draw list API. pub fn font_tex_uv_white_pixel(&self) -> [f32; 2] { - unsafe { sys::igGetFontTexUvWhitePixel_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetFontTexUvWhitePixel(&mut out) }; + out.into() } /// Sets the font scale of the current window pub fn set_window_font_scale(&self, scale: f32) { diff --git a/src/input/mouse.rs b/src/input/mouse.rs index 5625dc4..b79cddb 100644 --- a/src/input/mouse.rs +++ b/src/input/mouse.rs @@ -126,14 +126,18 @@ impl<'ui> Ui<'ui> { } /// Returns the mouse position backed up at the time of opening a popup pub fn mouse_pos_on_opening_current_popup(&self) -> [f32; 2] { - unsafe { sys::igGetMousePosOnOpeningCurrentPopup_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetMousePosOnOpeningCurrentPopup(&mut out) }; + out.into() } /// Returns the delta from the initial clicking position. /// /// This is locked and returns [0.0, 0.0] until the mouse has moved past the global distance /// threshold (`io.mouse_drag_threshold`). pub fn mouse_drag_delta(&self, button: MouseButton) -> [f32; 2] { - unsafe { sys::igGetMouseDragDelta_nonUDT2(button as i32, -1.0).into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetMouseDragDelta(&mut out, button as i32, -1.0) }; + out.into() } /// Returns the delta from the initial clicking position. /// @@ -141,7 +145,9 @@ impl<'ui> Ui<'ui> { /// If the given threshold is invalid or negative, the global distance threshold is used /// (`io.mouse_drag_threshold`). pub fn mouse_drag_delta_with_threshold(&self, button: MouseButton, threshold: f32) -> [f32; 2] { - unsafe { sys::igGetMouseDragDelta_nonUDT2(button as i32, threshold).into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetMouseDragDelta(&mut out, button as i32, threshold) }; + out.into() } /// Resets the current delta from initial clicking position. pub fn reset_mouse_drag_delta(&self, button: MouseButton) { diff --git a/src/layout.rs b/src/layout.rs index 8813d83..b5be07d 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -97,7 +97,9 @@ impl<'ui> Ui<'ui> { } /// Returns the cursor position (in window coordinates) pub fn cursor_pos(&self) -> [f32; 2] { - unsafe { sys::igGetCursorPos_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetCursorPos(&mut out) }; + out.into() } /// Sets the cursor position (in window coordinates). /// @@ -107,13 +109,17 @@ impl<'ui> Ui<'ui> { } /// Returns the initial cursor position (in window coordinates) pub fn cursor_start_pos(&self) -> [f32; 2] { - unsafe { sys::igGetCursorStartPos_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetCursorStartPos(&mut out) }; + out.into() } /// Returns the cursor position (in absolute screen coordinates). /// /// This is especially useful for drawing, as the drawing API uses screen coordinates. pub fn cursor_screen_pos(&self) -> [f32; 2] { - unsafe { sys::igGetCursorScreenPos_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetCursorScreenPos(&mut out) }; + out.into() } /// Sets the cursor position (in absolute screen coordinates) pub fn set_cursor_screen_pos(&self, pos: [f32; 2]) { diff --git a/src/lib.rs b/src/lib.rs index 236bac8..e1f326f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -466,15 +466,17 @@ impl<'ui> Ui<'ui> { hide_text_after_double_hash: bool, wrap_width: f32, ) -> [f32; 2] { + let mut out = sys::ImVec2::zero(); unsafe { - sys::igCalcTextSize_nonUDT2( + sys::igCalcTextSize( + &mut out, text.as_ptr(), std::ptr::null(), hide_text_after_double_hash, wrap_width, ) - .into() - } + }; + out.into() } } diff --git a/src/utils.rs b/src/utils.rs index 2ce3309..864b42c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -82,15 +82,21 @@ impl<'ui> Ui<'ui> { } /// Returns the upper-left bounding rectangle of the last item (in screen coordinates) pub fn item_rect_min(&self) -> [f32; 2] { - unsafe { sys::igGetItemRectMin_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetItemRectMin(&mut out) } + out.into() } /// Returns the lower-right bounding rectangle of the last item (in screen coordinates) pub fn item_rect_max(&self) -> [f32; 2] { - unsafe { sys::igGetItemRectMax_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetItemRectMax(&mut out) } + out.into() } /// Returns the size of the last item pub fn item_rect_size(&self) -> [f32; 2] { - unsafe { sys::igGetItemRectSize_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetItemRectSize(&mut out) } + out.into() } /// Allows the last item to be overlapped by a subsequent item. /// diff --git a/src/window/content_region.rs b/src/window/content_region.rs index 82811da..1a222ea 100644 --- a/src/window/content_region.rs +++ b/src/window/content_region.rs @@ -5,23 +5,31 @@ use crate::Ui; impl<'ui> Ui<'ui> { /// Returns the current content boundaries (in *window coordinates*) pub fn content_region_max(&self) -> [f32; 2] { - unsafe { sys::igGetContentRegionMax_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetContentRegionMax(&mut out) }; + out.into() } /// Equal to `ui.content_region_max()` - `ui.cursor_pos()` pub fn content_region_avail(&self) -> [f32; 2] { - unsafe { sys::igGetContentRegionAvail_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetContentRegionAvail(&mut out) }; + out.into() } /// Content boundaries min (in *window coordinates*). /// /// Roughly equal to [0.0, 0.0] - scroll. pub fn window_content_region_min(&self) -> [f32; 2] { - unsafe { sys::igGetWindowContentRegionMin_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetWindowContentRegionMin(&mut out) }; + out.into() } /// Content boundaries max (in *window coordinates*). /// /// Roughly equal to [0.0, 0.0] + size - scroll. pub fn window_content_region_max(&self) -> [f32; 2] { - unsafe { sys::igGetWindowContentRegionMax_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetWindowContentRegionMax(&mut out) }; + out.into() } pub fn window_content_region_width(&self) -> f32 { unsafe { sys::igGetWindowContentRegionWidth() } diff --git a/src/window/mod.rs b/src/window/mod.rs index 4bd3828..57ebe1e 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -140,11 +140,15 @@ impl<'ui> Ui<'ui> { } /// Returns the position of the current window (in screen space) pub fn window_pos(&self) -> [f32; 2] { - unsafe { sys::igGetWindowPos_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetWindowPos(&mut out) }; + out.into() } /// Returns the size of the current window pub fn window_size(&self) -> [f32; 2] { - unsafe { sys::igGetWindowSize_nonUDT2().into() } + let mut out = sys::ImVec2::zero(); + unsafe { sys::igGetWindowSize(&mut out) }; + out.into() } }