From e807d970899636e797a3d49103b90d54c9b2ff0c Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 19 Aug 2014 12:39:30 +0100 Subject: [PATCH] Exposed CalcTextSize(), GetCursorScreenPos() for more advanced fiddling --- imgui.cpp | 7 ++++++- imgui.h | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2d0510379..724eefe9e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -179,7 +179,6 @@ namespace ImGui static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false); static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); -static ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); @@ -2441,6 +2440,12 @@ void SetCursorPos(const ImVec2& pos) window->DC.CursorPos = window->Pos + pos; } +ImVec2 GetCursorScreenPos() +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.CursorPos; +} + void SetScrollPosHere() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index be1604b9f..606a03aeb 100644 --- a/imgui.h +++ b/imgui.h @@ -166,8 +166,9 @@ namespace ImGui float GetColumnOffset(int column_index = -1); void SetColumnOffset(int column_index, float offset); float GetColumnWidth(int column_index = -1); - ImVec2 GetCursorPos(); // cursor position is relative to window position + ImVec2 GetCursorPos(); // cursor position relative to window position void SetCursorPos(const ImVec2& pos); // " + ImVec2 GetCursorScreenPos(); // cursor position in screen space void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match higher widgets. float GetTextLineSpacing(); float GetTextLineHeight(); @@ -251,6 +252,7 @@ namespace ImGui int GetFrameCount(); const char* GetStyleColorName(ImGuiCol idx); void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); + ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); }; // namespace ImGui