From eea2c8b00e485c8d41a2ab6c005c9dd81474bcd9 Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Thu, 29 Nov 2018 21:43:52 +0200 Subject: [PATCH] Use nonUDT2 variants of functions that return ImVec2/4 --- imgui-sys/src/lib.rs | 190 +++++++++++++++++++++++++++++++++++---- imgui-sys/src/structs.rs | 42 ++++++++- src/lib.rs | 14 +-- 3 files changed, 218 insertions(+), 28 deletions(-) diff --git a/imgui-sys/src/lib.rs b/imgui-sys/src/lib.rs index d8f7b43..8850d28 100644 --- a/imgui-sys/src/lib.rs +++ b/imgui-sys/src/lib.rs @@ -225,15 +225,15 @@ extern "C" { pub fn igIsWindowFocused(flags: ImGuiFocusedFlags) -> bool; pub fn igIsWindowHovered(flags: ImGuiHoveredFlags) -> bool; pub fn igGetWindowDrawList() -> *mut ImDrawList; - pub fn igGetWindowPos() -> ImVec2; - pub fn igGetWindowSize() -> ImVec2; + pub fn igGetWindowPos_nonUDT2() -> ImVec2; + pub fn igGetWindowSize_nonUDT2() -> ImVec2; pub fn igGetWindowWidth() -> c_float; pub fn igGetWindowHeight() -> c_float; - pub fn igGetContentRegionMax() -> ImVec2; - pub fn igGetContentRegionAvail() -> ImVec2; + pub fn igGetContentRegionMax_nonUDT2() -> ImVec2; + pub fn igGetContentRegionAvail_nonUDT2() -> ImVec2; pub fn igGetContentRegionAvailWidth() -> c_float; - pub fn igGetWindowContentRegionMin() -> ImVec2; - pub fn igGetWindowContentRegionMax() -> ImVec2; + pub fn igGetWindowContentRegionMin_nonUDT2() -> ImVec2; + pub fn igGetWindowContentRegionMax_nonUDT2() -> ImVec2; pub fn igGetWindowContentRegionWidth() -> c_float; pub fn igSetNextWindowPos(pos: ImVec2, cond: ImGuiCond, pivot: ImVec2); @@ -259,6 +259,55 @@ extern "C" { pub fn igSetWindowFocusStr(name: *const c_char); } +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetWindowPos() -> ImVec2 { + igGetWindowPos_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetWindowSize() -> ImVec2 { + igGetWindowSize_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetContentRegionMax() -> ImVec2 { + igGetContentRegionMax_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetContentRegionAvail() -> ImVec2 { + igGetContentRegionAvail_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetWindowContentRegionMin() -> ImVec2 { + igGetWindowContentRegionMin_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetWindowContentRegionMax() -> ImVec2 { + igGetWindowContentRegionMax_nonUDT2() +} + // Windows scrolling extern "C" { pub fn igGetScrollX() -> c_float; @@ -284,12 +333,21 @@ extern "C" { pub fn igGetStyleColorVec4(idx: ImGuiCol) -> *const ImVec4; pub fn igGetFont() -> *mut ImFont; pub fn igGetFontSize() -> c_float; - pub fn igGetFontTexUvWhitePixel() -> ImVec2; + pub fn igGetFontTexUvWhitePixel_nonUDT2() -> ImVec2; pub fn igGetColorU32(idx: ImGuiCol, alpha_mul: c_float) -> ImU32; pub fn igGetColorU32Vec(col: ImVec4) -> ImU32; pub fn igGetColorU32U32(col: ImU32) -> ImU32; } +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetFontTexUvWhitePixel() -> ImVec2 { + igGetFontTexUvWhitePixel_nonUDT2() +} + // Parameter stack (current window) extern "C" { pub fn igPushItemWidth(item_width: c_float); @@ -314,14 +372,14 @@ extern "C" { pub fn igUnindent(indent_w: c_float); pub fn igBeginGroup(); pub fn igEndGroup(); - pub fn igGetCursorPos() -> ImVec2; + pub fn igGetCursorPos_nonUDT2() -> ImVec2; pub fn igGetCursorPosX() -> c_float; pub fn igGetCursorPosY() -> c_float; pub fn igSetCursorPos(local_pos: ImVec2); pub fn igSetCursorPosX(x: c_float); pub fn igSetCursorPosY(y: c_float); - pub fn igGetCursorStartPos() -> ImVec2; - pub fn igGetCursorScreenPos() -> ImVec2; + pub fn igGetCursorStartPos_nonUDT2() -> ImVec2; + pub fn igGetCursorScreenPos_nonUDT2() -> ImVec2; pub fn igSetCursorScreenPos(screen_pos: ImVec2); pub fn igAlignTextToFramePadding(); pub fn igGetTextLineHeight() -> c_float; @@ -330,6 +388,31 @@ extern "C" { pub fn igGetFrameHeightWithSpacing() -> c_float; } +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetCursorPos() -> ImVec2 { + igGetCursorPos_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetCursorStartPos() -> ImVec2 { + igGetCursorStartPos_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetCursorScreenPos() -> ImVec2 { + igGetCursorScreenPos_nonUDT2() +} + // ID stack/scopes extern "C" { pub fn igPushIDStr(str_id: *const c_char); @@ -1030,9 +1113,9 @@ extern "C" { pub fn igIsAnyItemHovered() -> bool; pub fn igIsAnyItemActive() -> bool; pub fn igIsAnyItemFocused() -> bool; - pub fn igGetItemRectMin() -> ImVec2; - pub fn igGetItemRectMax() -> ImVec2; - pub fn igGetItemRectSize() -> ImVec2; + pub fn igGetItemRectMin_nonUDT2() -> ImVec2; + pub fn igGetItemRectMax_nonUDT2() -> ImVec2; + pub fn igGetItemRectSize_nonUDT2() -> ImVec2; pub fn igSetItemAllowOverlap(); pub fn igIsRectVisible(size: ImVec2) -> bool; pub fn igIsRectVisibleVec2(rect_min: ImVec2, rect_max: ImVec2) -> bool; @@ -1043,7 +1126,7 @@ extern "C" { pub fn igGetStyleColorName(idx: ImGuiCol) -> *const c_char; pub fn igSetStateStorage(storage: *mut ImGuiStorage); pub fn igGetStateStorage() -> *mut ImGuiStorage; - pub fn igCalcTextSize( + pub fn igCalcTextSize_nonUDT2( text: *const c_char, text_end: *const c_char, hide_text_after_double_hash: bool, @@ -1059,7 +1142,7 @@ extern "C" { pub fn igBeginChildFrame(id: ImGuiID, size: ImVec2, flags: ImGuiWindowFlags) -> bool; pub fn igEndChildFrame(); - pub fn igColorConvertU32ToFloat4(color: ImU32) -> ImVec4; + pub fn igColorConvertU32ToFloat4_nonUDT2(color: ImU32) -> ImVec4; pub fn igColorConvertFloat4ToU32(color: ImVec4) -> ImU32; pub fn igColorConvertRGBtoHSV( r: c_float, @@ -1079,6 +1162,52 @@ extern "C" { ); } +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetItemRectMin() -> ImVec2 { + igGetItemRectMin_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetItemRectMax() -> ImVec2 { + igGetItemRectMax_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetItemRectSize() -> ImVec2 { + igGetItemRectSize_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igCalcTextSize( + text: *const c_char, + text_end: *const c_char, + hide_text_after_double_hash: bool, + wrap_width: c_float, +) -> ImVec2 { + igCalcTextSize_nonUDT2(text, text_end, hide_text_after_double_hash, wrap_width) +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igColorConvertU32ToFloat4(color: ImU32) -> ImVec4 { + igColorConvertU32ToFloat4_nonUDT2(color) +} + // Inputs extern "C" { pub fn igGetKeyIndex(imgui_key: ImGuiKey) -> c_int; @@ -1094,9 +1223,9 @@ extern "C" { pub fn igIsMouseDragging(button: c_int, lock_threshold: c_float) -> bool; pub fn igIsMouseHoveringRect(r_min: ImVec2, r_max: ImVec2, clip: bool) -> bool; pub fn igIsMousePosValid(mouse_pos: *const ImVec2) -> bool; - pub fn igGetMousePos() -> ImVec2; - pub fn igGetMousePosOnOpeningCurrentPopup() -> ImVec2; - pub fn igGetMouseDragDelta(button: c_int, lock_threshold: c_float) -> ImVec2; + pub fn igGetMousePos_nonUDT2() -> ImVec2; + pub fn igGetMousePosOnOpeningCurrentPopup_nonUDT2() -> ImVec2; + pub fn igGetMouseDragDelta_nonUDT2(button: c_int, lock_threshold: c_float) -> ImVec2; pub fn igResetMouseDragDelta(button: c_int); pub fn igGetMouseCursor() -> ImGuiMouseCursor; pub fn igSetMouseCursor(cursor: ImGuiMouseCursor); @@ -1104,6 +1233,31 @@ extern "C" { pub fn igCaptureMouseFromApp(capture: bool); } +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetMousePos() -> ImVec2 { + igGetMousePos_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetMousePosOnOpeningCurrentPopup() -> ImVec2 { + igGetMousePosOnOpeningCurrentPopup_nonUDT2() +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn igGetMouseDragDelta(button: c_int, lock_threshold: c_float) -> ImVec2 { + igGetMouseDragDelta_nonUDT2(button, lock_threshold) +} + // Clipboard utilities extern "C" { pub fn igGetClipboardText() -> *const c_char; diff --git a/imgui-sys/src/structs.rs b/imgui-sys/src/structs.rs index d9349a2..6469571 100644 --- a/imgui-sys/src/structs.rs +++ b/imgui-sys/src/structs.rs @@ -608,8 +608,8 @@ extern "C" { pub fn ImDrawList_PopClipRect(this: *mut ImDrawList); pub fn ImDrawList_PushTextureID(this: *mut ImDrawList, texture_id: ImTextureID); pub fn ImDrawList_PopTextureID(this: *mut ImDrawList); - pub fn ImDrawList_GetClipRectMin(this: *mut ImDrawList) -> ImVec2; - pub fn ImDrawList_GetClipRectMax(this: *mut ImDrawList) -> ImVec2; + pub fn ImDrawList_GetClipRectMin_nonUDT2(this: *mut ImDrawList) -> ImVec2; + pub fn ImDrawList_GetClipRectMax_nonUDT2(this: *mut ImDrawList) -> ImVec2; pub fn ImDrawList_AddLine( this: *mut ImDrawList, @@ -851,6 +851,23 @@ extern "C" { pub fn ImDrawList_UpdateTextureID(this: *mut ImDrawList); } +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn ImDrawList_GetClipRectMin(this: *mut ImDrawList) -> ImVec2 { + ImDrawList_GetClipRectMin_nonUDT2(this) +} +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn ImDrawList_GetClipRectMax(this: *mut ImDrawList) -> ImVec2 { + ImDrawList_GetClipRectMax_nonUDT2(this) +} + // ImDrawData extern "C" { pub fn ImDrawData_Clear(this: *mut ImDrawData); @@ -1000,7 +1017,7 @@ extern "C" { pub fn ImFont_GetCharAdvance(this: *mut ImFont, c: ImWchar) -> c_float; pub fn ImFont_IsLoaded(this: *mut ImFont) -> bool; pub fn ImFont_GetDebugName(this: *mut ImFont) -> *const c_char; - pub fn ImFont_CalcTextSizeA( + pub fn ImFont_CalcTextSizeA_nonUDT2( this: *mut ImFont, size: c_float, max_width: c_float, @@ -1052,3 +1069,22 @@ extern "C" { ); pub fn ImFont_AddRemapChar(this: *mut ImFont, dst: ImWchar, src: ImWchar, overwrite_dst: bool); } + +#[deprecated( + since = "0.0.22", + note = "please use the _nonUDT2 suffixed version of this function" +)] +#[allow(non_snake_case)] +pub unsafe fn ImFont_CalcTextSizeA( + this: *mut ImFont, + size: c_float, + max_width: c_float, + wrap_width: c_float, + text_begin: *const c_char, + text_end: *const c_char, + remaining: *mut *const c_char, +) -> ImVec2 { + ImFont_CalcTextSizeA_nonUDT2( + this, size, max_width, wrap_width, text_begin, text_end, remaining, + ) +} diff --git a/src/lib.rs b/src/lib.rs index d4b05d8..810f952 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -605,12 +605,12 @@ impl<'ui> Ui<'ui> { } /// Get current window's size in pixels pub fn get_window_size(&self) -> (f32, f32) { - let size = unsafe { sys::igGetWindowSize() }; + let size = unsafe { sys::igGetWindowSize_nonUDT2() }; size.into() } /// Get current window's position in pixels pub fn get_window_pos(&self) -> (f32, f32) { - let size = unsafe { sys::igGetWindowPos() }; + let size = unsafe { sys::igGetWindowPos_nonUDT2() }; size.into() } } @@ -696,7 +696,7 @@ impl<'ui> Ui<'ui> { /// This is especially useful for drawing, as the drawing API uses /// screen coordiantes. pub fn get_cursor_screen_pos(&self) -> (f32, f32) { - let size = unsafe { sys::igGetCursorScreenPos() }; + let size = unsafe { sys::igGetCursorScreenPos_nonUDT2() }; size.into() } @@ -708,7 +708,7 @@ impl<'ui> Ui<'ui> { /// Get cursor position on the screen, in window coordinates. pub fn get_cursor_pos(&self) -> (f32, f32) { - let size = unsafe { sys::igGetCursorPos() }; + let size = unsafe { sys::igGetCursorPos_nonUDT2() }; size.into() } @@ -721,7 +721,7 @@ impl<'ui> Ui<'ui> { /// Get available space left between the cursor and the edges of the current /// window. pub fn get_content_region_avail(&self) -> (f32, f32) { - let size = unsafe { sys::igGetContentRegionAvail() }; + let size = unsafe { sys::igGetContentRegionAvail_nonUDT2() }; size.into() } } @@ -1359,7 +1359,7 @@ impl<'ui> Ui<'ui> { wrap_width: f32, ) -> ImVec2 { unsafe { - sys::igCalcTextSize( + sys::igCalcTextSize_nonUDT2( text.as_ptr(), std::ptr::null(), hide_text_after_double_hash, @@ -1376,7 +1376,7 @@ impl<'ui> Ui<'ui> { } /// Get previously drawn item's size pub fn get_item_rect_size(&self) -> (f32, f32) { - let size = unsafe { sys::igGetItemRectSize() }; + let size = unsafe { sys::igGetItemRectSize_nonUDT2() }; size.into() } }