Renamed internal type ImGuiAabb to ImRect

This commit is contained in:
ocornut 2015-03-17 23:35:12 +00:00
parent 7e297945c3
commit 302316c6cf
1 changed files with 112 additions and 111 deletions

223
imgui.cpp
View File

@ -251,7 +251,7 @@
ISSUES & TODO-LIST
==================
- misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
- misc: merge or clarify ImVec4 / ImRect, they are essentially duplicate containers
- window: add horizontal scroll
- window: fix resize grip rendering scaling along with Rounding style setting
- window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
@ -415,16 +415,16 @@ using namespace IMGUI_STB_NAMESPACE;
// Forward Declarations
//-------------------------------------------------------------------------
struct ImRect;
struct ImGuiColMod;
struct ImGuiStyleMod;
struct ImGuiAabb;
struct ImGuiDrawContext;
struct ImGuiTextEditState;
struct ImGuiIniData;
struct ImGuiState;
struct ImGuiWindow;
static bool ButtonBehavior(const ImGuiAabb& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false, bool pressed_on_click = false);
static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false, bool pressed_on_click = false);
static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
@ -434,13 +434,13 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool
static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
static void SetFont(ImFont* font);
static bool ItemAdd(const ImGuiAabb& bb, const ImGuiID* id);
static bool ItemAdd(const ImRect& bb, const ImGuiID* id);
static void ItemSize(ImVec2 size, float text_offset_y = 0.0f);
static void ItemSize(const ImGuiAabb& bb, float text_offset_y = 0.0f);
static void ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
static void PushColumnClipRect(int column_index = -1);
static bool IsClipped(const ImGuiAabb& bb);
static bool IsClipped(const ImRect& bb);
static bool IsMouseHoveringRect(const ImGuiAabb& bb);
static bool IsMouseHoveringRect(const ImRect& bb);
static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
static void Scrollbar(ImGuiWindow* window);
@ -877,32 +877,33 @@ struct ImGuiStyleMod // Style modifier, backup of modified data so we can res
ImVec2 PreviousValue;
};
struct ImGuiAabb // 2D axis aligned bounding-box
struct ImRect // 2D axis aligned bounding-box
{
ImVec2 Min;
ImVec2 Max;
ImGuiAabb() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); }
ImGuiAabb(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; }
ImGuiAabb(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; }
ImGuiAabb(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; }
ImRect() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); }
ImRect(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; }
ImRect(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; }
ImRect(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; }
ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; }
ImVec2 GetSize() const { return Max-Min; }
float GetWidth() const { return (Max-Min).x; }
float GetHeight() const { return (Max-Min).y; }
ImVec2 GetTL() const { return Min; }
ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); }
ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); }
ImVec2 GetBR() const { return Max; }
bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; }
bool Contains(const ImGuiAabb& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; }
bool Overlaps(const ImGuiAabb& r) const { return r.Min.y <= Max.y && r.Max.y >= Min.y && r.Min.x <= Max.x && r.Max.x >= Min.x; }
void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); }
void Add(const ImGuiAabb& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); }
void Expand(const ImVec2& sz) { Min -= sz; Max += sz; }
void Clip(const ImGuiAabb& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); }
ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; }
ImVec2 GetSize() const { return Max-Min; }
float GetWidth() const { return (Max-Min).x; }
float GetHeight() const { return (Max-Min).y; }
ImVec2 GetTL() const { return Min; }
ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); }
ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); }
ImVec2 GetBR() const { return Max; }
bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; }
bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; }
bool Overlaps(const ImRect& r) const { return r.Min.y <= Max.y && r.Max.y >= Min.y && r.Min.x <= Max.x && r.Max.x >= Min.x; }
void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); }
void Add(const ImRect& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); }
void Expand(const ImVec2& sz) { Min -= sz; Max += sz; }
void Clip(const ImRect& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); }
};
typedef ImRect ImGuiAabb; // FIXME-OBSOLETE
struct ImGuiGroupData
{
@ -928,7 +929,7 @@ struct ImGuiDrawContext
float LogLinePosY;
int TreeDepth;
ImGuiID LastItemID;
ImGuiAabb LastItemAabb;
ImRect LastItemRect;
bool LastItemHovered;
ImVector<ImGuiWindow*> ChildWindows;
ImVector<bool> AllowKeyboardFocus;
@ -957,7 +958,7 @@ struct ImGuiDrawContext
LogLinePosY = -1.0f;
TreeDepth = 0;
LastItemID = 0;
LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f);
LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
LastItemHovered = false;
StateStorage = NULL;
@ -1165,7 +1166,7 @@ struct ImGuiWindow
ImGuiDrawContext DC; // Temporary per-window data, reset at the beginning of the frame
ImVector<ImGuiID> IDStack; // ID stack. ID are hashes seeded with the value at the top of the stack
ImVector<ImVec4> ClipRectStack; // Scissoring / clipping rectangle. x1, y1, x2, y2.
ImGuiAabb ClippedAabb; // = ClipRectStack.front() after setup in Begin()
ImRect ClippedRect; // = ClipRectStack.front() after setup in Begin()
int LastFrameDrawn;
float ItemWidthDefault;
ImGuiStorage StateStorage;
@ -1192,12 +1193,12 @@ public:
bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested
void FocusItemUnregister();
ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); }
ImRect Aabb() const { return ImRect(Pos, Pos+Size); }
ImFont* Font() const { return GImGui->Font; }
float FontSize() const { return GImGui->FontSize * FontWindowScale; }
ImVec2 CursorPos() const { return DC.CursorPos; }
float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui->Style.FramePadding.y * 2.0f; }
ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
ImRect TitleBarAabb() const { return ImRect(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; }
ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui->Style.Colors[idx]; c.w *= GImGui->Style.Alpha * a; return ImGui::ColorConvertFloat4ToU32(c); }
ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); }
@ -2421,37 +2422,37 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
continue;
// Using the clipped AABB so a child window will typically be clipped by its parent.
ImGuiAabb bb(window->ClippedAabb.Min - g.Style.TouchExtraPadding, window->ClippedAabb.Max + g.Style.TouchExtraPadding);
ImRect bb(window->ClippedRect.Min - g.Style.TouchExtraPadding, window->ClippedRect.Max + g.Style.TouchExtraPadding);
if (bb.Contains(pos))
return window;
}
return NULL;
}
// Test if mouse cursor is hovering given aabb
// Test if mouse cursor is hovering given rectangle
// NB- Box is clipped by our current clip setting
// NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
static bool IsMouseHoveringRect(const ImGuiAabb& bb)
// NB- Expand the AABB to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
static bool IsMouseHoveringRect(const ImRect& bb)
{
ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
// Clip
ImGuiAabb box_clipped = bb;
ImRect box_clipped = bb;
if (!window->ClipRectStack.empty())
{
const ImVec4 clip_rect = window->ClipRectStack.back();
box_clipped.Clip(ImGuiAabb(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w)));
box_clipped.Clip(ImRect(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w)));
}
// Expand for touch input
const ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding);
const ImRect box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding);
return box_for_touch.Contains(g.IO.MousePos);
}
bool ImGui::IsMouseHoveringRect(const ImVec2& box_min, const ImVec2& box_max)
{
return IsMouseHoveringRect(ImGuiAabb(box_min, box_max));
return IsMouseHoveringRect(ImRect(box_min, box_max));
}
bool ImGui::IsMouseHoveringWindow()
@ -2553,19 +2554,19 @@ bool ImGui::IsAnyItemActive()
ImVec2 ImGui::GetItemRectMin()
{
ImGuiWindow* window = GetCurrentWindow();
return window->DC.LastItemAabb.Min;
return window->DC.LastItemRect.Min;
}
ImVec2 ImGui::GetItemRectMax()
{
ImGuiWindow* window = GetCurrentWindow();
return window->DC.LastItemAabb.Max;
return window->DC.LastItemRect.Max;
}
ImVec2 ImGui::GetItemRectSize()
{
ImGuiWindow* window = GetCurrentWindow();
return window->DC.LastItemAabb.GetSize();
return window->DC.LastItemRect.GetSize();
}
// Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
@ -2673,7 +2674,7 @@ void ImGui::EndChild()
ImGui::End();
window = GetCurrentWindow();
ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + sz);
ImRect bb(window->DC.CursorPos, window->DC.CursorPos + sz);
ItemSize(sz);
ItemAdd(bb, NULL);
}
@ -2932,7 +2933,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
ImGuiAabb title_bar_aabb = window->TitleBarAabb();
ImRect title_bar_aabb = window->TitleBarAabb();
// Apply and ImClamp scrolling
window->ScrollY = window->NextScrollY;
@ -3002,7 +3003,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
else if (!(window->Flags & ImGuiWindowFlags_NoResize))
{
// Manual resize grip
const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
const ImRect resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
const ImGuiID resize_id = window->GetID("#RESIZE");
bool hovered, held;
ButtonBehavior(resize_aabb, resize_id, &hovered, &held, true);
@ -3131,8 +3132,8 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
}
// Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
window->ClippedAabb = window->Aabb();
window->ClippedAabb.Clip(window->ClipRectStack.front());
window->ClippedRect = window->Aabb();
window->ClippedRect.Clip(window->ClipRectStack.front());
// Pressing CTRL+C while holding on a window copy its content to the clipboard
// This works but 1. doesn't handle multiple Begin/End pairs, 2. recursing into another Begin/End pair - so we need to work that out and add better logging scope.
@ -3146,7 +3147,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
// Inner clipping rectangle
// We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
const ImGuiAabb title_bar_aabb = window->TitleBarAabb();
const ImRect title_bar_aabb = window->TitleBarAabb();
ImVec4 clip_rect(title_bar_aabb.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_aabb.Max.y+0.5f, window->Aabb().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Aabb().Max.y-1.5f);
if (window->ScrollbarY)
clip_rect.z -= style.ScrollbarWidth;
@ -3210,7 +3211,7 @@ static void Scrollbar(ImGuiWindow* window)
const ImGuiID id = window->GetID("#SCROLLY");
// Render background
ImGuiAabb bb(window->Aabb().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Aabb().Max.x, window->Aabb().Max.y-1);
ImRect bb(window->Aabb().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Aabb().Max.x, window->Aabb().Max.y-1);
window->DrawList->AddRectFilled(bb.Min, bb.Max, window->Color(ImGuiCol_ScrollbarBg));
bb.Expand(ImVec2(-3,-3));
const float scrollbar_height = bb.GetHeight();
@ -3947,7 +3948,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
// Lines to render
if (line < text_end)
{
ImGuiAabb line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
ImRect line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
while (line < text_end)
{
const char* line_end = strchr(line, '\n');
@ -3981,7 +3982,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
text_size.y += (pos - text_pos).y;
}
ImGuiAabb bb(text_pos, text_pos + text_size);
ImRect bb(text_pos, text_pos + text_size);
ItemSize(bb);
ItemAdd(bb, NULL);
}
@ -3994,7 +3995,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
ImVec2 text_pos = window->DC.CursorPos;
text_pos.y += window->DC.CurrentLineTextBaseOffset;
ImGuiAabb bb(text_pos, text_pos + text_size);
ImRect bb(text_pos, text_pos + text_size);
ItemSize(bb.GetSize());
if (!ItemAdd(bb, NULL))
return;
@ -4031,8 +4032,8 @@ void ImGui::LabelTextV(const char* label, const char* fmt, va_list args)
const char* value_text_end = value_text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y + style.FramePadding.y*2));
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size);
const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y + style.FramePadding.y*2));
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size);
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(value_bb, NULL))
return;
@ -4050,7 +4051,7 @@ void ImGui::LabelText(const char* label, const char* fmt, ...)
va_end(args);
}
static bool IsHovered(const ImGuiAabb& bb, ImGuiID id)
static bool IsHovered(const ImRect& bb, ImGuiID id)
{
ImGuiState& g = *GImGui;
if (g.HoveredId == 0)
@ -4065,7 +4066,7 @@ static bool IsHovered(const ImGuiAabb& bb, ImGuiID id)
return false;
}
static bool ButtonBehavior(const ImGuiAabb& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat, bool pressed_on_click)
static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat, bool pressed_on_click)
{
ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
@ -4130,7 +4131,7 @@ bool ImGui::Button(const char* label, const ImVec2& size_arg, bool repeat_when_h
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : (label_size.x + style.FramePadding.x*2), size_arg.y != 0.0f ? size_arg.y : (label_size.y + style.FramePadding.y*2));
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(bb, &id))
return false;
@ -4162,7 +4163,7 @@ bool ImGui::SmallButton(const char* label)
ImVec2 text_pos = window->DC.CursorPos;
text_pos.y += window->DC.CurrentLineTextBaseOffset;
ImGuiAabb bb(text_pos, text_pos + label_size + ImVec2(style.FramePadding.x*2,0));
ImRect bb(text_pos, text_pos + label_size + ImVec2(style.FramePadding.x*2,0));
ItemSize(bb);
if (!ItemAdd(bb, &id))
return false;
@ -4187,7 +4188,7 @@ bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size)
return false;
const ImGuiID id = window->GetID(str_id);
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
ItemSize(bb);
if (!ItemAdd(bb, &id))
return false;
@ -4205,7 +4206,7 @@ static bool CloseWindowButton(bool* p_opened)
const ImGuiID id = window->GetID("#CLOSE");
const float size = window->TitleBarHeight() - 4.0f;
const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size));
const ImRect bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size));
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, true);
@ -4234,7 +4235,7 @@ void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2&
if (window->SkipItems)
return;
ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
if (border_col.w > 0.0f)
bb.Max += ImVec2(2,2);
ItemSize(bb);
@ -4272,8 +4273,8 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I
ImGui::PopID();
const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding;
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2);
const ImGuiAabb image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size);
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2);
const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size);
ItemSize(bb);
if (!ItemAdd(bb, &id))
return false;
@ -4449,7 +4450,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImVec2 pos_min = window->DC.CursorPos;
const ImVec2 pos_max = window->Pos + GetContentRegionMax();
ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y));
ImRect bb = ImRect(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y));
if (display_frame)
{
bb.Min.x -= window_padding.x*0.5f - 1;
@ -4458,7 +4459,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display
}
// FIXME: we don't provide our width so that it doesn't get feed back into AutoFit. Should manage that better so we can still hover without extending ContentsSize
const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + label_size);
const ImRect text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + label_size);
ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y), display_frame ? style.FramePadding.y : 0.0f);
// When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behavior).
@ -4520,7 +4521,7 @@ void ImGui::Bullet()
const ImGuiStyle& style = g.Style;
const float line_height = window->FontSize();
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height));
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height));
ItemSize(bb);
if (!ItemAdd(bb, NULL))
return;
@ -4547,7 +4548,7 @@ void ImGui::BulletTextV(const char* fmt, va_list args)
const ImGuiStyle& style = g.Style;
const float line_height = window->FontSize();
const ImVec2 label_size = CalcTextSize(text_begin, text_end, true);
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size); // Empty text doesn't add padding
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size); // Empty text doesn't add padding
ItemSize(bb);
if (!ItemAdd(bb, NULL))
return;
@ -4779,7 +4780,7 @@ static void ParseFormat(const char* fmt, int& decimal_precision)
}
}
static bool SliderBehavior(const ImGuiAabb& frame_bb, const ImGuiAabb& slider_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal)
static bool SliderBehavior(const ImRect& frame_bb, const ImRect& slider_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal)
{
ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
@ -4907,11 +4908,11 @@ static bool SliderBehavior(const ImGuiAabb& frame_bb, const ImGuiAabb& slider_bb
if (!horizontal)
grab_t = 1.0f - grab_t;
const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t);
ImGuiAabb grab_bb;
ImRect grab_bb;
if (horizontal)
grab_bb = ImGuiAabb(ImVec2(grab_pos - grab_sz*0.5f, frame_bb.Min.y + 2.0f), ImVec2(grab_pos + grab_sz*0.5f, frame_bb.Max.y - 2.0f));
grab_bb = ImRect(ImVec2(grab_pos - grab_sz*0.5f, frame_bb.Min.y + 2.0f), ImVec2(grab_pos + grab_sz*0.5f, frame_bb.Max.y - 2.0f));
else
grab_bb = ImGuiAabb(ImVec2(frame_bb.Min.x + 2.0f, grab_pos - grab_sz*0.5f), ImVec2(frame_bb.Max.x - 2.0f, grab_pos + grab_sz*0.5f));
grab_bb = ImRect(ImVec2(frame_bb.Min.x + 2.0f, grab_pos - grab_sz*0.5f), ImVec2(frame_bb.Max.x - 2.0f, grab_pos + grab_sz*0.5f));
window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
}
@ -4935,9 +4936,9 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
const float w = ImGui::CalcItemWidth();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
const ImRect slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
// NB- we don't call ItemSize() yet becausae we may turn into a text edit box below
if (!ItemAdd(frame_bb, &id))
@ -5002,9 +5003,9 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
const ImRect slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(frame_bb, &id))
@ -5181,9 +5182,9 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett
if (graph_size.y == 0.0f)
graph_size.y = label_size.y + (style.FramePadding.y * 2);
const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y));
const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0));
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y));
const ImRect graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0));
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(bb, NULL))
return;
@ -5310,17 +5311,17 @@ bool ImGui::Checkbox(const char* label, bool* v)
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2));
const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2));
ItemSize(check_bb, style.FramePadding.y);
ImGuiAabb total_bb = check_bb;
ImRect total_bb = check_bb;
if (label_size.x > 0)
SameLine(0, (int)style.ItemInnerSpacing.x);
const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
const ImRect text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
if (label_size.x > 0)
{
ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
total_bb = ImGuiAabb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
total_bb = ImRect(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
}
if (!ItemAdd(total_bb, &id))
@ -5368,13 +5369,13 @@ bool ImGui::RadioButton(const char* label, bool active)
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1));
const ImRect check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1));
ItemSize(check_bb, style.FramePadding.y);
ImGuiAabb total_bb = check_bb;
ImRect total_bb = check_bb;
if (label_size.x > 0)
SameLine(0, (int)style.ItemInnerSpacing.x);
const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
const ImRect text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
if (label_size.x > 0)
{
ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()), style.FramePadding.y);
@ -5600,7 +5601,7 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast,
const ImGuiStyle& style = g.Style;
const float w = ImGui::CalcItemWidth();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
ImGui::PushID(label);
const ImVec2 button_sz = ImVec2(window->FontSize(), window->FontSize()) + style.FramePadding * 2;
@ -5762,8 +5763,8 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT
const float w = ImGui::CalcItemWidth();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(frame_bb, &id))
return false;
@ -6236,8 +6237,8 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
const float w = ImGui::CalcItemWidth();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + label_size.x,0));
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + label_size.x,0));
ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(frame_bb, &id))
return false;
@ -6246,7 +6247,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
const bool hovered = IsHovered(frame_bb, id);
bool value_changed = false;
const ImGuiAabb value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING
RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);
@ -6284,7 +6285,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
const ImVec2 backup_pos = ImGui::GetCursorPos();
const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x;
const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y;
const ImGuiAabb popup_aabb(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height));
const ImRect popup_aabb(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height));
ImGui::SetCursorPos(popup_aabb.Min - window->Pos);
const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
@ -6341,11 +6342,11 @@ bool ImGui::Selectable(const char* label, bool selected, const ImVec2& size_arg)
const float w = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x;
const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y);
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
ItemSize(bb);
// Selectables are meant to be tightly packed together. So for both rendering and collision we extend to compensate for spacing.
ImGuiAabb bb_with_spacing = bb;
ImRect bb_with_spacing = bb;
const float spacing_L = (float)(int)(style.ItemSpacing.x * 0.5f);
const float spacing_U = (float)(int)(style.ItemSpacing.y * 0.5f);
const float spacing_R = style.ItemSpacing.x - spacing_L;
@ -6398,9 +6399,9 @@ bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
size.x = (size_arg.x != 0.0f) ? (size_arg.x) : ImGui::CalcItemWidth() + style.FramePadding.x * 2.0f;
size.y = (size_arg.y != 0.0f) ? (size_arg.y) : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y;
const ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y));
const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
window->DC.LastItemAabb = bb;
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
window->DC.LastItemRect = bb;
if (label_size.x > 0)
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
@ -6428,7 +6429,7 @@ bool ImGui::ListBoxHeader(const char* label, int items_count, int height_in_item
void ImGui::ListBoxFooter()
{
ImGuiWindow* parent_window = GetParentWindow();
const ImGuiAabb bb = parent_window->DC.LastItemAabb;
const ImRect bb = parent_window->DC.LastItemRect;
const ImGuiStyle& style = ImGui::GetStyle();
ImGui::EndChildFrame();
@ -6487,7 +6488,7 @@ bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_borde
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID("#colorbutton");
const float square_size = window->FontSize();
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2)));
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2)));
ItemSize(bb, small_height ? 0.0f : style.FramePadding.y);
if (!ItemAdd(bb, &id))
return false;
@ -6681,7 +6682,7 @@ void ImGui::Separator()
if (window->DC.ColumnsCount > 1)
PopClipRect();
const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
const ImRect bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
if (!ItemAdd(bb, NULL))
{
@ -6736,17 +6737,17 @@ static void ItemSize(ImVec2 size, float text_offset_y)
window->DC.CurrentLineHeight = window->DC.CurrentLineTextBaseOffset = 0.0f;
}
static inline void ItemSize(const ImGuiAabb& bb, float text_offset_y)
static inline void ItemSize(const ImRect& bb, float text_offset_y)
{
ItemSize(bb.GetSize(), text_offset_y);
}
static bool IsClipped(const ImGuiAabb& bb)
static bool IsClipped(const ImRect& bb)
{
ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
if (!bb.Overlaps(ImGuiAabb(window->ClipRectStack.back())) && !g.LogEnabled)
if (!bb.Overlaps(ImRect(window->ClipRectStack.back())) && !g.LogEnabled)
return true;
return false;
}
@ -6754,14 +6755,14 @@ static bool IsClipped(const ImGuiAabb& bb)
bool ImGui::IsClipped(const ImVec2& item_size)
{
ImGuiWindow* window = GetCurrentWindow();
return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size));
return IsClipped(ImRect(window->DC.CursorPos, window->DC.CursorPos + item_size));
}
static bool ItemAdd(const ImGuiAabb& bb, const ImGuiID* id)
static bool ItemAdd(const ImRect& bb, const ImGuiID* id)
{
ImGuiWindow* window = GetCurrentWindow();
window->DC.LastItemID = id ? *id : 0;
window->DC.LastItemAabb = bb;
window->DC.LastItemRect = bb;
if (IsClipped(bb))
{
window->DC.LastItemHovered = false;
@ -6803,7 +6804,7 @@ void ImGui::EndGroup()
ImGuiGroupData& group_data = window->DC.GroupStack.back();
ImGuiAabb group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos);
ImRect group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos);
group_bb.Max.y -= style.ItemSpacing.y;
window->DC.CursorPos = group_data.BackupCursorPos;
@ -6977,7 +6978,7 @@ void ImGui::Columns(int columns_count, const char* id, bool border)
float x = window->Pos.x + GetColumnOffset(i);
const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2));
const ImRect column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2));
if (IsClipped(column_aabb))
continue;