From 334fdeafd26c15e03b4f198002ad86b8422c0e2f Mon Sep 17 00:00:00 2001 From: Daniel Worley Date: Thu, 7 Aug 2025 13:53:24 -0400 Subject: [PATCH] Scale menu at higher resolutions (#502) * Scale menu at higher resolutions * Options for menu extent/scaling --------- Co-authored-by: coco875 <59367621+coco875@users.noreply.github.com> --- src/port/ui/Menu.cpp | 16 +++++++++++++++- src/port/ui/Menu.h | 1 + src/port/ui/PortMenu.cpp | 17 +++++++++++++++++ src/port/ui/PortMenu.h | 5 +++++ src/port/ui/UIWidgets.h | 5 +++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/port/ui/Menu.cpp b/src/port/ui/Menu.cpp index 0c18e27af..44471b431 100644 --- a/src/port/ui/Menu.cpp +++ b/src/port/ui/Menu.cpp @@ -551,7 +551,21 @@ void Menu::DrawElement() { headerWidth += style.ItemSpacing.x; } } + ImVec2 menuSize = { std::fminf(1280, windowWidth), std::fminf(800, windowHeight) }; + UIWidgets::MenuExtent menuExtent = static_cast( + CVarGetInteger("gSettings.Menu.Extent", UIWidgets::MenuExtent::Condensed) + ); + + if (menuExtent == UIWidgets::MenuExtent::Stretched) { + menuSize = { 0.9f * windowWidth, 0.9f * windowHeight }; + uiScale = CVarGetFloat("gSettings.Menu.Scale", 1.0f); + } else { + uiScale = 1.0f; // Scaling doesn't play nice with condensed menu + } + ImGuiIO& io = ImGui::GetIO(); + io.FontGlobalScale = uiScale; + pos += window->WorkRect.GetSize() / 2 - menuSize / 2; ImGui::SetNextWindowPos(pos); ImGui::BeginChild("Menu Block", menuSize, @@ -671,7 +685,7 @@ void Menu::DrawElement() { float sectionHeight = menuSize.y - headerHeight - 4 - style.ItemSpacing.y * 2; float columnHeight = sectionHeight - style.ItemSpacing.y * 4; ImGui::SetNextWindowPos(pos + style.ItemSpacing * 2); - float sidebarWidth = 200 - style.ItemSpacing.x; + float sidebarWidth = 200 * uiScale - style.ItemSpacing.x; const char* sidebarCvar = menuEntries.at(headerIndex).sidebarCvar; diff --git a/src/port/ui/Menu.h b/src/port/ui/Menu.h index bfa7e68a8..229befb95 100644 --- a/src/port/ui/Menu.h +++ b/src/port/ui/Menu.h @@ -93,6 +93,7 @@ class Menu : public GuiWindow { bool popped; ImVec2 poppedSize; ImVec2 poppedPos; + float uiScale = 1.0f; float windowHeight; float windowWidth; }; diff --git a/src/port/ui/PortMenu.cpp b/src/port/ui/PortMenu.cpp index 93642c66f..1bbb56637 100644 --- a/src/port/ui/PortMenu.cpp +++ b/src/port/ui/PortMenu.cpp @@ -115,6 +115,23 @@ void PortMenu::AddSettings() { .Tooltip("Changes the Theme of the Menu Widgets.") .ComboMap(menuThemeOptions) .DefaultIndex(Colors::LightBlue)); + AddWidget(path, "Menu Extent", WIDGET_CVAR_COMBOBOX) + .CVar("gSettings.Menu.Extent") + .Options(ComboboxOptions() + .Tooltip("Changes the extent of the onscreen menu") + .ComboMap(menuExtentOptions) + .DefaultIndex(MenuExtent::Condensed)); + + AddWidget(path, "Menu Scale: %.0fx", WIDGET_CVAR_SLIDER_FLOAT) + .CVar("gSettings.Menu.Scale") + .PreFunc([](WidgetInfo& info) { info.isHidden = !CVarGetInteger("gSettings.Menu.Extent", 0); }) + .Options(FloatSliderOptions() + .Tooltip("Adjust the scale for the menu.") + .Min(1.0f) + .Max(2.0f) + .DefaultValue(1.0f) + .Format("%.1f") + .Step(0.1f)); AddWidget(path, "Controller pak screen", WIDGET_CVAR_CHECKBOX) .CVar("gControllerPakScreen") .Options(CheckboxOptions().Tooltip( diff --git a/src/port/ui/PortMenu.h b/src/port/ui/PortMenu.h index 32cb9148e..a5540776f 100644 --- a/src/port/ui/PortMenu.h +++ b/src/port/ui/PortMenu.h @@ -9,6 +9,11 @@ namespace GameUI { +static const std::unordered_map menuExtentOptions = { + { UIWidgets::MenuExtent::Condensed, "Condensed" }, + { UIWidgets::MenuExtent::Stretched, "Stretched" }, +}; + static const std::unordered_map menuThemeOptions = { { UIWidgets::Colors::Red, "Red" }, { UIWidgets::Colors::DarkRed, "Dark Red" }, diff --git a/src/port/ui/UIWidgets.h b/src/port/ui/UIWidgets.h index 079c66869..6cc1bd998 100644 --- a/src/port/ui/UIWidgets.h +++ b/src/port/ui/UIWidgets.h @@ -104,6 +104,11 @@ namespace UIWidgets { Right, }; + enum MenuExtent { + Condensed, + Stretched + }; + struct WidgetOptions{ const char* tooltip = ""; bool disabled = false;