Added GetItemBoxMin(),GetItemBoxMax(), renamed IsHovered()-->IsItemHovered()

This commit is contained in:
ocornut 2014-08-14 12:43:30 +01:00
parent 46eee0cee4
commit a905505cca
2 changed files with 21 additions and 3 deletions

View File

@ -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<ImGuiWindow*> ChildWindows;
ImVector<bool> 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;

View File

@ -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);