From 584c7ffac8a49e4abde6c8a3a47df5a6c61bbdcf Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 15 Jan 2015 14:41:22 +0000 Subject: [PATCH] Added SetCursorScreenPos() helper (WindowPos+CursorPos = SrceenPos) --- imgui.cpp | 8 ++++++++ imgui.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 61ad4d8a..23a36630 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3111,6 +3111,8 @@ void ImGui::SetWindowFontScale(float scale) window->FontWindowScale = scale; } +// NB: internally we store CursorPos in absolute screen coordinates because it is more convenient. +// Conversion happens as we pass the value to user, but it makes our naming convention dodgy. May want to rename 'DC.CursorPos'. ImVec2 ImGui::GetCursorPos() { ImGuiWindow* window = GetCurrentWindow(); @@ -3141,6 +3143,12 @@ ImVec2 ImGui::GetCursorScreenPos() return window->DC.CursorPos; } +void ImGui::SetCursorScreenPos(const ImVec2& screen_pos) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos = screen_pos; +} + void ImGui::SetScrollPosHere() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index 1cc8fb4c..a798a05a 100644 --- a/imgui.h +++ b/imgui.h @@ -206,7 +206,8 @@ namespace ImGui IMGUI_API void SetCursorPos(const ImVec2& pos); // " IMGUI_API void SetCursorPosX(float x); // " IMGUI_API void SetCursorPosY(float y); // " - IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in screen space + IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates (0..io.DisplaySize) + IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates (0..io.DisplaySize) IMGUI_API void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets. IMGUI_API float GetTextLineSpacing(); IMGUI_API float GetTextLineHeight();