Windows, Menus: Fixed an issue where the size of sub-menu in their own viewport would be erroneously clamped to the size of main viewport. (#7730)

Amend #7287, #7063
This commit is contained in:
ocornut 2024-06-27 16:05:25 +02:00
parent 10a5a857f5
commit a028c2df2a
2 changed files with 14 additions and 4 deletions

View File

@ -93,6 +93,8 @@ Other changes:
Docking+Viewports Branch:
- Windows, Menus: Fixed an issue where the size of sub-menu in their own viewport
would be erroneously clamped to the size of main viewport. (#7730)
- Backends: SDL3: Update for introduction of SDL_GLContext from void*. (#7701, #7702)
[@bcsanches]
- Backends: Win32: Secondary viewports WndProc handler retrieve/set imgui context from

View File

@ -6173,10 +6173,18 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont
{
// Maximum window size is determined by the viewport size or monitor size
ImVec2 size_min = CalcWindowMinSize(window);
ImVec2 size_max = (window->ViewportOwned || ((window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_Popup))) ? ImVec2(FLT_MAX, FLT_MAX) : ImGui::GetMainViewport()->WorkSize - style.DisplaySafeAreaPadding * 2.0f;
const int monitor_idx = window->ViewportAllowPlatformMonitorExtend;
if (monitor_idx >= 0 && monitor_idx < g.PlatformIO.Monitors.Size && (window->Flags & ImGuiWindowFlags_ChildWindow) == 0)
size_max = g.PlatformIO.Monitors[monitor_idx].WorkSize - style.DisplaySafeAreaPadding * 2.0f;
ImVec2 size_max = ImVec2(FLT_MAX, FLT_MAX);
// Child windows are layed within their parent (unless they are also popups/menus) and thus have no restriction
if ((window->Flags & ImGuiWindowFlags_ChildWindow) == 0 || (window->Flags & ImGuiWindowFlags_Popup) != 0)
{
if (!window->ViewportOwned)
size_max = ImGui::GetMainViewport()->WorkSize - style.DisplaySafeAreaPadding * 2.0f;
const int monitor_idx = window->ViewportAllowPlatformMonitorExtend;
if (monitor_idx >= 0 && monitor_idx < g.PlatformIO.Monitors.Size)
size_max = g.PlatformIO.Monitors[monitor_idx].WorkSize - style.DisplaySafeAreaPadding * 2.0f;
}
ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, size_max));
// FIXME: CalcWindowAutoFitSize() doesn't take into account that only one axis may be auto-fit when calculating scrollbars,