diff --git a/imgui.cpp b/imgui.cpp index e2c66f7d..48775f68 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -113,6 +113,7 @@ - window: autofit is losing its purpose when user relies on any dynamic layout (window width multiplier, column). maybe just discard autofit? - window: support horizontal scroll - window: fix resize grip scaling along with Rounding style setting + - window/style: add global alpha modifier (not just "fill_alpha") - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes @@ -516,6 +517,7 @@ struct ImGuiDrawContext float PrevLineHeight; float LogLineHeight; int TreeDepth; + ImGuiAabb LastItemAabb; bool LastItemHovered; ImVector ChildWindows; ImVector AllowKeyboardFocus; @@ -538,6 +540,7 @@ struct ImGuiDrawContext CurrentLineHeight = PrevLineHeight = 0.0f; LogLineHeight = -1.0f; TreeDepth = 0; + LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f); LastItemHovered = false; StateStorage = NULL; OpenNextNode = -1; @@ -1668,12 +1671,24 @@ ImVec2 GetMousePos() return GImGui.IO.MousePos; } -bool IsHovered() +bool IsItemHovered() { ImGuiWindow* window = GetCurrentWindow(); return window->DC.LastItemHovered; } +ImVec2 GetItemBoxMin() +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.LastItemAabb.Min; +} + +ImVec2 GetItemBoxMax() +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.LastItemAabb.Max; +} + void SetTooltip(const char* fmt, ...) { ImGuiState& g = GImGui; @@ -4398,6 +4413,7 @@ bool IsClipped(ImVec2 item_size) static bool ClipAdvance(const ImGuiAabb& bb) { ImGuiWindow* window = GetCurrentWindow(); + window->DC.LastItemAabb = bb; if (ImGui::IsClipped(bb)) { window->DC.LastItemHovered = false; @@ -5411,7 +5427,7 @@ void ShowTestWindow(bool* open) ImGui::RadioButton("radio c", &e, 2); ImGui::Text("Hover me"); - if (ImGui::IsHovered()) + if (ImGui::IsItemHovered()) ImGui::SetTooltip("I am a tooltip"); static int item = 1; diff --git a/imgui.h b/imgui.h index 6b44fb7e..0102911c 100644 --- a/imgui.h +++ b/imgui.h @@ -231,7 +231,9 @@ namespace ImGui // Utilities void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). (currently no contention handling, last call win) void SetNewWindowDefaultPos(ImVec2 pos); // set position of window that do - bool IsHovered(); // was the last item active area hovered by mouse? + bool IsItemHovered(); // was the last item active area hovered by mouse? + ImVec2 GetItemBoxMin(); // get bounding box of last item + ImVec2 GetItemBoxMax(); // get bounding box of last item bool IsClipped(ImVec2 item_size); // to perform coarse clipping on user's side (as an optimisation) bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry bool IsMouseClicked(int button, bool repeat = false);