mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Merge branch 'master' into docking
# Conflicts: # docs/CHANGELOG.txt # examples/imgui_impl_dx11.cpp # imgui.cpp
This commit is contained in:
78
imgui.cpp
78
imgui.cpp
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.72b
|
||||
// dear imgui, v1.73 WIP
|
||||
// (main code and documentation)
|
||||
|
||||
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.
|
||||
@ -4789,7 +4789,7 @@ bool ImGui::IsMouseDoubleClicked(int button)
|
||||
return g.IO.MouseDoubleClicked[button];
|
||||
}
|
||||
|
||||
// [Internal] This doesn't test if the button is presed
|
||||
// [Internal] This doesn't test if the button is pressed
|
||||
bool ImGui::IsMouseDragPastThreshold(int button, float lock_threshold)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -5230,7 +5230,7 @@ static ImGuiWindow* GetWindowForTitleAndMenuHeight(ImGuiWindow* window)
|
||||
return (window->DockNodeAsHost && window->DockNodeAsHost->VisibleWindow) ? window->DockNodeAsHost->VisibleWindow : window;
|
||||
}
|
||||
|
||||
static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size)
|
||||
static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSizeConstraint)
|
||||
@ -5263,7 +5263,7 @@ static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size)
|
||||
return new_size;
|
||||
}
|
||||
|
||||
static ImVec2 CalcContentSize(ImGuiWindow* window)
|
||||
static ImVec2 CalcWindowContentSize(ImGuiWindow* window)
|
||||
{
|
||||
if (window->Collapsed)
|
||||
if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
|
||||
@ -5277,7 +5277,7 @@ static ImVec2 CalcContentSize(ImGuiWindow* window)
|
||||
return sz;
|
||||
}
|
||||
|
||||
static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents)
|
||||
static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiStyle& style = g.Style;
|
||||
@ -5308,7 +5308,7 @@ static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents)
|
||||
|
||||
// When the window cannot fit all contents (either because of constraints, either because screen is too small),
|
||||
// we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
|
||||
ImVec2 size_auto_fit_after_constraint = CalcSizeAfterConstraint(window, size_auto_fit);
|
||||
ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
|
||||
bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - size_decorations.x < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar);
|
||||
bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - size_decorations.y < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||
if (will_have_scrollbar_x)
|
||||
@ -5321,8 +5321,10 @@ static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents)
|
||||
|
||||
ImVec2 ImGui::CalcWindowExpectedSize(ImGuiWindow* window)
|
||||
{
|
||||
ImVec2 size_contents = CalcContentSize(window);
|
||||
return CalcSizeAfterConstraint(window, CalcSizeAutoFit(window, size_contents));
|
||||
ImVec2 size_contents = CalcWindowContentSize(window);
|
||||
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, size_contents);
|
||||
ImVec2 size_final = CalcWindowSizeAfterConstraint(window, size_auto_fit);
|
||||
return size_final;
|
||||
}
|
||||
|
||||
static ImGuiCol GetWindowBgColorIdxFromFlags(ImGuiWindowFlags flags)
|
||||
@ -5339,7 +5341,7 @@ static void CalcResizePosSizeFromAnyCorner(ImGuiWindow* window, const ImVec2& co
|
||||
ImVec2 pos_min = ImLerp(corner_target, window->Pos, corner_norm); // Expected window upper-left
|
||||
ImVec2 pos_max = ImLerp(window->Pos + window->Size, corner_target, corner_norm); // Expected window lower-right
|
||||
ImVec2 size_expected = pos_max - pos_min;
|
||||
ImVec2 size_constrained = CalcSizeAfterConstraint(window, size_expected);
|
||||
ImVec2 size_constrained = CalcWindowSizeAfterConstraint(window, size_expected);
|
||||
*out_pos = pos_min;
|
||||
if (corner_norm.x == 0.0f)
|
||||
out_pos->x -= (size_constrained.x - size_expected.x);
|
||||
@ -5420,7 +5422,7 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
||||
if (held && g.IO.MouseDoubleClicked[0] && resize_grip_n == 0)
|
||||
{
|
||||
// Manual auto-fit when double-clicking
|
||||
size_target = CalcSizeAfterConstraint(window, size_auto_fit);
|
||||
size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit);
|
||||
ret_auto_fit = true;
|
||||
ClearActiveID();
|
||||
}
|
||||
@ -5475,7 +5477,7 @@ static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
||||
g.NavDisableMouseHover = true;
|
||||
resize_grip_col[0] = GetColorU32(ImGuiCol_ResizeGripActive);
|
||||
// FIXME-NAV: Should store and accumulate into a separate size buffer to handle sizing constraints properly, right now a constraint will make us stuck.
|
||||
size_target = CalcSizeAfterConstraint(window, window->SizeFull + nav_resize_delta);
|
||||
size_target = CalcWindowSizeAfterConstraint(window, window->SizeFull + nav_resize_delta);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5930,7 +5932,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
// UPDATE CONTENTS SIZE, UPDATE HIDDEN STATUS
|
||||
|
||||
// Update contents size from last frame for auto-fitting (or use explicit size)
|
||||
window->ContentSize = CalcContentSize(window);
|
||||
window->ContentSize = CalcWindowContentSize(window);
|
||||
if (window->HiddenFramesCanSkipItems > 0)
|
||||
window->HiddenFramesCanSkipItems--;
|
||||
if (window->HiddenFramesCannotSkipItems > 0)
|
||||
@ -6002,7 +6004,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
// SIZE
|
||||
|
||||
// Calculate auto-fit size, handle automatic resize
|
||||
const ImVec2 size_auto_fit = CalcSizeAutoFit(window, window->ContentSize);
|
||||
const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSize);
|
||||
bool use_current_size_for_scrollbar_x = window_just_created;
|
||||
bool use_current_size_for_scrollbar_y = window_just_created;
|
||||
if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window->Collapsed)
|
||||
@ -6038,7 +6040,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
}
|
||||
|
||||
// Apply minimum/maximum window size constraints and final size
|
||||
window->SizeFull = CalcSizeAfterConstraint(window, window->SizeFull);
|
||||
window->SizeFull = CalcWindowSizeAfterConstraint(window, window->SizeFull);
|
||||
window->Size = window->Collapsed && !(flags & ImGuiWindowFlags_ChildWindow) ? window->TitleBarRect().GetSize() : window->SizeFull;
|
||||
|
||||
// Decoration size
|
||||
@ -7879,22 +7881,33 @@ static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window, bool s
|
||||
}
|
||||
|
||||
// Scroll to keep newly navigated item fully into view
|
||||
void ImGui::ScrollToBringRectIntoView(ImGuiWindow* window, const ImRect& item_rect)
|
||||
ImVec2 ImGui::ScrollToBringRectIntoView(ImGuiWindow* window, const ImRect& item_rect)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImRect window_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1));
|
||||
//GetForegroundDrawList(window)->AddRect(window_rect.Min, window_rect.Max, IM_COL32_WHITE); // [DEBUG]
|
||||
if (window_rect.Contains(item_rect))
|
||||
return;
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (window->ScrollbarX && item_rect.Min.x < window_rect.Min.x)
|
||||
SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x + g.Style.ItemSpacing.x, 0.0f);
|
||||
else if (window->ScrollbarX && item_rect.Max.x >= window_rect.Max.x)
|
||||
SetScrollFromPosX(window, item_rect.Max.x - window->Pos.x + g.Style.ItemSpacing.x, 1.0f);
|
||||
if (item_rect.Min.y < window_rect.Min.y)
|
||||
SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y - g.Style.ItemSpacing.y, 0.0f);
|
||||
else if (item_rect.Max.y >= window_rect.Max.y)
|
||||
SetScrollFromPosY(window, item_rect.Max.y - window->Pos.y + g.Style.ItemSpacing.y, 1.0f);
|
||||
ImVec2 delta_scroll;
|
||||
if (!window_rect.Contains(item_rect))
|
||||
{
|
||||
if (window->ScrollbarX && item_rect.Min.x < window_rect.Min.x)
|
||||
SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x + g.Style.ItemSpacing.x, 0.0f);
|
||||
else if (window->ScrollbarX && item_rect.Max.x >= window_rect.Max.x)
|
||||
SetScrollFromPosX(window, item_rect.Max.x - window->Pos.x + g.Style.ItemSpacing.x, 1.0f);
|
||||
if (item_rect.Min.y < window_rect.Min.y)
|
||||
SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y - g.Style.ItemSpacing.y, 0.0f);
|
||||
else if (item_rect.Max.y >= window_rect.Max.y)
|
||||
SetScrollFromPosY(window, item_rect.Max.y - window->Pos.y + g.Style.ItemSpacing.y, 1.0f);
|
||||
|
||||
ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window, false);
|
||||
delta_scroll = next_scroll - window->Scroll;
|
||||
}
|
||||
|
||||
// Also scroll parent window to keep us into view if necessary
|
||||
if (window->Flags & ImGuiWindowFlags_ChildWindow)
|
||||
delta_scroll += ScrollToBringRectIntoView(window->ParentWindow, ImRect(item_rect.Min - delta_scroll, item_rect.Max - delta_scroll));
|
||||
|
||||
return delta_scroll;
|
||||
}
|
||||
|
||||
float ImGui::GetScrollX()
|
||||
@ -9221,16 +9234,11 @@ static void ImGui::NavUpdateMoveResult()
|
||||
if (g.NavLayer == 0)
|
||||
{
|
||||
ImRect rect_abs = ImRect(result->RectRel.Min + result->Window->Pos, result->RectRel.Max + result->Window->Pos);
|
||||
ScrollToBringRectIntoView(result->Window, rect_abs);
|
||||
ImVec2 delta_scroll = ScrollToBringRectIntoView(result->Window, rect_abs);
|
||||
|
||||
// Estimate upcoming scroll so we can offset our result position so mouse position can be applied immediately after in NavUpdate()
|
||||
ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(result->Window, false);
|
||||
ImVec2 delta_scroll = result->Window->Scroll - next_scroll;
|
||||
result->RectRel.Translate(delta_scroll);
|
||||
|
||||
// Also scroll parent window to keep us into view if necessary (we could/should technically recurse back the whole the parent hierarchy).
|
||||
if (result->Window->Flags & ImGuiWindowFlags_ChildWindow)
|
||||
ScrollToBringRectIntoView(result->Window->ParentWindow, ImRect(rect_abs.Min + delta_scroll, rect_abs.Max + delta_scroll));
|
||||
// Offset our result position so mouse position can be applied immediately after in NavUpdate()
|
||||
result->RectRel.TranslateX(-delta_scroll.x);
|
||||
result->RectRel.TranslateY(-delta_scroll.y);
|
||||
}
|
||||
|
||||
ClearActiveID();
|
||||
|
Reference in New Issue
Block a user