mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-22 15:46:35 +00:00
Internals: Added GetWindowResizeID(), renamed GetScrollbarID() to GetWindowScrollbarID(). Using integer for resize ID so they matches regardless of the pointer size.
Internals: Renamed IMGUI_USER_ERROR to IM_ASSERT_USER_ERROR().
This commit is contained in:
parent
8f40020ca6
commit
7e232092a6
31
imgui.cpp
31
imgui.cpp
@ -4840,10 +4840,10 @@ struct ImGuiResizeGripDef
|
||||
|
||||
static const ImGuiResizeGripDef resize_grip_def[4] =
|
||||
{
|
||||
{ ImVec2(1,1), ImVec2(-1,-1), 0, 3 }, // Lower right
|
||||
{ ImVec2(0,1), ImVec2(+1,-1), 3, 6 }, // Lower left
|
||||
{ ImVec2(0,0), ImVec2(+1,+1), 6, 9 }, // Upper left
|
||||
{ ImVec2(1,0), ImVec2(-1,+1), 9,12 }, // Upper right
|
||||
{ ImVec2(1,1), ImVec2(-1,-1), 0, 3 }, // Lower-right
|
||||
{ ImVec2(0,1), ImVec2(+1,-1), 3, 6 }, // Lower-left
|
||||
{ ImVec2(0,0), ImVec2(+1,+1), 6, 9 }, // Upper-left (Unused)
|
||||
{ ImVec2(1,0), ImVec2(-1,+1), 9,12 }, // Upper-right (Unused)
|
||||
};
|
||||
|
||||
static ImRect GetResizeBorderRect(ImGuiWindow* window, int border_n, float perp_padding, float thickness)
|
||||
@ -4858,6 +4858,17 @@ static ImRect GetResizeBorderRect(ImGuiWindow* window, int border_n, float perp_
|
||||
return ImRect();
|
||||
}
|
||||
|
||||
// 0..3: corners (Lower-right, Lower-left, Unused, Unused)
|
||||
// 4..7: borders (Top, Right, Bottom, Left)
|
||||
ImGuiID ImGui::GetWindowResizeID(ImGuiWindow* window, int n)
|
||||
{
|
||||
IM_ASSERT(n >= 0 && n <= 7);
|
||||
ImGuiID id = window->ID;
|
||||
id = ImHashStr("#RESIZE", 0, id);
|
||||
id = ImHashData(&n, sizeof(int), id);
|
||||
return id;
|
||||
}
|
||||
|
||||
// Handle resize for: Resize Grips, Borders, Gamepad
|
||||
// Return true when using auto-fit (double click on resize grip)
|
||||
static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4])
|
||||
@ -4895,7 +4906,7 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
||||
if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x);
|
||||
if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
|
||||
bool hovered, held;
|
||||
ButtonBehavior(resize_rect, window->GetID((void*)(intptr_t)resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
|
||||
ButtonBehavior(resize_rect, window->GetID(resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
|
||||
//GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
|
||||
if (hovered || held)
|
||||
g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE;
|
||||
@ -4921,7 +4932,7 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
||||
{
|
||||
bool hovered, held;
|
||||
ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS);
|
||||
ButtonBehavior(border_rect, window->GetID((void*)(intptr_t)(border_n + 4)), &hovered, &held, ImGuiButtonFlags_FlattenChildren);
|
||||
ButtonBehavior(border_rect, window->GetID(border_n + 4), &hovered, &held, ImGuiButtonFlags_FlattenChildren);
|
||||
//GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255));
|
||||
if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held)
|
||||
{
|
||||
@ -5822,14 +5833,14 @@ void ImGui::End()
|
||||
// Error checking: verify that user hasn't called End() too many times!
|
||||
if (g.CurrentWindowStack.Size <= 1 && g.WithinFrameScopeWithImplicitWindow)
|
||||
{
|
||||
IMGUI_USER_ERROR(g.CurrentWindowStack.Size > 1, "Calling End() too many times!");
|
||||
IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size > 1, "Calling End() too many times!");
|
||||
return;
|
||||
}
|
||||
IM_ASSERT(g.CurrentWindowStack.Size > 0);
|
||||
|
||||
// Error checking: verify that user doesn't directly call End() on a child window.
|
||||
if (window->Flags & ImGuiWindowFlags_ChildWindow)
|
||||
IMGUI_USER_ERROR(g.WithinEndChild, "Must call EndChild() and not End()!");
|
||||
IM_ASSERT_USER_ERROR(g.WithinEndChild, "Must call EndChild() and not End()!");
|
||||
|
||||
// Close anything that is open
|
||||
if (window->DC.CurrentColumns)
|
||||
@ -7003,13 +7014,13 @@ static void ImGui::ErrorCheckEndFrame()
|
||||
{
|
||||
if (g.CurrentWindowStack.Size > 1)
|
||||
{
|
||||
IMGUI_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?");
|
||||
IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild?");
|
||||
while (g.CurrentWindowStack.Size > 1)
|
||||
End();
|
||||
}
|
||||
else
|
||||
{
|
||||
IMGUI_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?");
|
||||
IM_ASSERT_USER_ERROR(g.CurrentWindowStack.Size == 1, "Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much?");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,8 +166,8 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer
|
||||
#define IM_ROUND(_VAL) ((float)(int)((_VAL) + 0.5f)) //
|
||||
|
||||
// Error handling
|
||||
#ifndef IMGUI_USER_ERROR
|
||||
#define IMGUI_USER_ERROR(_EXPR, _MSG) IM_ASSERT((_EXPR) && (_MSG)) // Recoverable User Error
|
||||
#ifndef IM_ASSERT_USER_ERROR
|
||||
#define IM_ASSERT_USER_ERROR(_EXPR,_MSG) IM_ASSERT((_EXPR) && (_MSG)) // Recoverable User Error
|
||||
#endif
|
||||
|
||||
// Debug Logging
|
||||
@ -1712,7 +1712,8 @@ namespace ImGui
|
||||
IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags);
|
||||
IMGUI_API void Scrollbar(ImGuiAxis axis);
|
||||
IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* p_scroll_v, float avail_v, float contents_v, ImDrawCornerFlags rounding_corners);
|
||||
IMGUI_API ImGuiID GetScrollbarID(ImGuiWindow* window, ImGuiAxis axis);
|
||||
IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis);
|
||||
IMGUI_API ImGuiID GetWindowResizeID(ImGuiWindow* window, int n); // 0..3: corners, 4..7: borders
|
||||
IMGUI_API void SeparatorEx(ImGuiSeparatorFlags flags);
|
||||
|
||||
// Widgets low-level behaviors
|
||||
|
@ -774,7 +774,7 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos)
|
||||
return pressed;
|
||||
}
|
||||
|
||||
ImGuiID ImGui::GetScrollbarID(ImGuiWindow* window, ImGuiAxis axis)
|
||||
ImGuiID ImGui::GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis)
|
||||
{
|
||||
return window->GetIDNoKeepAlive(axis == ImGuiAxis_X ? "#SCROLLX" : "#SCROLLY");
|
||||
}
|
||||
@ -881,7 +881,7 @@ void ImGui::Scrollbar(ImGuiAxis axis)
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
|
||||
const ImGuiID id = GetScrollbarID(window, axis);
|
||||
const ImGuiID id = GetWindowScrollbarID(window, axis);
|
||||
KeepAliveID(id);
|
||||
|
||||
// Calculate scrollbar bounding box
|
||||
@ -3464,8 +3464,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
|
||||
const bool user_clicked = hovered && io.MouseClicked[0];
|
||||
const bool user_nav_input_start = (g.ActiveId != id) && ((g.NavInputId == id) || (g.NavActivateId == id && g.NavInputSource == ImGuiInputSource_NavKeyboard));
|
||||
const bool user_scroll_finish = is_multiline && state != NULL && g.ActiveId == 0 && g.ActiveIdPreviousFrame == GetScrollbarID(draw_window, ImGuiAxis_Y);
|
||||
const bool user_scroll_active = is_multiline && state != NULL && g.ActiveId == GetScrollbarID(draw_window, ImGuiAxis_Y);
|
||||
const bool user_scroll_finish = is_multiline && state != NULL && g.ActiveId == 0 && g.ActiveIdPreviousFrame == GetWindowScrollbarID(draw_window, ImGuiAxis_Y);
|
||||
const bool user_scroll_active = is_multiline && state != NULL && g.ActiveId == GetWindowScrollbarID(draw_window, ImGuiAxis_Y);
|
||||
|
||||
bool clear_active_id = false;
|
||||
bool select_all = (g.ActiveId != id) && ((flags & ImGuiInputTextFlags_AutoSelectAll) != 0 || user_nav_input_start) && (!is_multiline);
|
||||
@ -6472,7 +6472,7 @@ void ImGui::EndTabBar()
|
||||
ImGuiTabBar* tab_bar = g.CurrentTabBar;
|
||||
if (tab_bar == NULL)
|
||||
{
|
||||
IMGUI_USER_ERROR(tab_bar != NULL, "Mismatched BeginTabBar()/EndTabBar()!");
|
||||
IM_ASSERT_USER_ERROR(tab_bar != NULL, "Mismatched BeginTabBar()/EndTabBar()!");
|
||||
return;
|
||||
}
|
||||
if (tab_bar->WantLayout)
|
||||
@ -6869,7 +6869,7 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f
|
||||
ImGuiTabBar* tab_bar = g.CurrentTabBar;
|
||||
if (tab_bar == NULL)
|
||||
{
|
||||
IMGUI_USER_ERROR(tab_bar, "BeginTabItem() Needs to be called between BeginTabBar() and EndTabBar()!");
|
||||
IM_ASSERT_USER_ERROR(tab_bar, "BeginTabItem() Needs to be called between BeginTabBar() and EndTabBar()!");
|
||||
return false;
|
||||
}
|
||||
bool ret = TabItemEx(tab_bar, label, p_open, flags);
|
||||
|
Loading…
Reference in New Issue
Block a user