From 7ce2338f2ae542ead1b56607b78edb47ff6b9901 Mon Sep 17 00:00:00 2001 From: Alan Tse Date: Tue, 29 Jul 2025 20:56:49 -0700 Subject: [PATCH] fix: menu refactor bugs --- src/Menu.cpp | 14 +++++++------- src/Menu.h | 13 ++----------- src/Menu/SettingsTabRenderer.cpp | 2 +- src/Menu/ThemeManager.cpp | 8 ++++---- src/Menu/ThemeManager.h | 17 +++++++++++------ 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/Menu.cpp b/src/Menu.cpp index 7e10c8fe3d..ab0ebd1c34 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -163,25 +163,25 @@ void Menu::Init() // Enhanced font configuration for sharper text rendering ImFontConfig font_config; - font_config.OversampleH = Constants::FCONF_OVERSAMPLE_H; - font_config.OversampleV = Constants::FCONF_OVERSAMPLE_V; - font_config.PixelSnapH = Constants::FCONF_PIXELSNAP_H; - font_config.RasterizerMultiply = Constants::FCONF_RASTERIZER_MULTIPLY; + font_config.OversampleH = ThemeManager::Constants::FCONF_OVERSAMPLE_H; + font_config.OversampleV = ThemeManager::Constants::FCONF_OVERSAMPLE_V; + font_config.PixelSnapH = ThemeManager::Constants::FCONF_PIXELSNAP_H; + font_config.RasterizerMultiply = ThemeManager::Constants::FCONF_RASTERIZER_MULTIPLY; DXGI_SWAP_CHAIN_DESC desc{}; globals::d3d::swapChain->GetDesc(&desc); float fontSize = settings.Theme.FontSize; - if (std::round(fontSize) != std::round(Constants::DEFAULT_FONT_SIZE)) { + if (std::round(fontSize) != std::round(ThemeManager::Constants::DEFAULT_FONT_SIZE)) { if (globals::state->screenSize.y > 0) { - fontSize = globals::state->screenSize.y * Constants::DEFAULT_FONT_RATIO; + fontSize = globals::state->screenSize.y * ThemeManager::Constants::DEFAULT_FONT_RATIO; } else { logger::warn("Menu::Init() - Failed to get game resolution from globals::state->screenSize."); } } - fontSize = std::clamp(fontSize, Constants::MIN_FONT_SIZE, Constants::MAX_FONT_SIZE); + fontSize = std::clamp(fontSize, ThemeManager::Constants::MIN_FONT_SIZE, ThemeManager::Constants::MAX_FONT_SIZE); if (!imgui_io.Fonts->AddFontFromFileTTF("Data\\Interface\\CommunityShaders\\Fonts\\Jost-Regular.ttf", std::round(fontSize), &font_config)) { diff --git a/src/Menu.h b/src/Menu.h index 67d3d19c71..8364c86d0d 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -57,15 +57,6 @@ class Menu struct Constants { static constexpr std::uint16_t KEY_PRESSED_MASK = 0x8000; - static constexpr float DEFAULT_SCREEN_HEIGHT = 1080.0f; // Default screen resolution to use for subsequent calculations - static constexpr float DEFAULT_FONT_RATIO = 0.025f; // Default 2.5% of screen height - static constexpr float MIN_FONT_SIZE = 16.0f; // ~1.5% @ 1080px height - static constexpr float MAX_FONT_SIZE = 108.0f; // 5.0% @ 2160px height - static constexpr float DEFAULT_FONT_SIZE = 27.0f; - static constexpr int FCONF_OVERSAMPLE_H = 3; // ImGui default = 2 - static constexpr int FCONF_OVERSAMPLE_V = 2; // ImGui default = 1 - static constexpr bool FCONF_PIXELSNAP_H = true; // ImGui default = false - static constexpr float FCONF_RASTERIZER_MULTIPLY = 1.1f; // ImGui default = 1.0f. "Linearly brighten (>1.0f) or darken (<1.0f) font output." }; // UI icon textures @@ -103,7 +94,7 @@ class Menu struct ThemeSettings { - float FontSize = Constants::DEFAULT_FONT_SIZE; + float FontSize = ThemeManager::Constants::DEFAULT_FONT_SIZE; float GlobalScale = REL::Module::IsVR() ? -0.5f : 0.f; // exponential bool UseSimplePalette = true; // simple palette or full customization @@ -279,7 +270,7 @@ class Menu private: Settings settings; - float cachedFontSize = Constants::DEFAULT_FONT_SIZE; // Tracks whether font has been modified and may require reloading + float cachedFontSize = ThemeManager::Constants::DEFAULT_FONT_SIZE; // Tracks whether font has been modified and may require reloading // Menu navigation std::string pendingFeatureSelection; // Feature to select on next frame diff --git a/src/Menu/SettingsTabRenderer.cpp b/src/Menu/SettingsTabRenderer.cpp index edd80049e2..f599e1482b 100644 --- a/src/Menu/SettingsTabRenderer.cpp +++ b/src/Menu/SettingsTabRenderer.cpp @@ -181,7 +181,7 @@ void SettingsTabRenderer::RenderSizesTab() auto& io = ImGui::GetIO(); io.FontGlobalScale = trueScale; } - ImGui::SliderFloat("Font Size", &themeSettings.FontSize, Menu::Constants::MIN_FONT_SIZE, Menu::Constants::MAX_FONT_SIZE, "%.0f"); + ImGui::SliderFloat("Font Size", &themeSettings.FontSize, ThemeManager::Constants::MIN_FONT_SIZE, ThemeManager::Constants::MAX_FONT_SIZE, "%.0f"); ImGui::SliderFloat2("Window Padding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("Frame Padding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("Item Spacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f"); diff --git a/src/Menu/ThemeManager.cpp b/src/Menu/ThemeManager.cpp index ea38da9ec2..d2c47e6154 100644 --- a/src/Menu/ThemeManager.cpp +++ b/src/Menu/ThemeManager.cpp @@ -92,11 +92,11 @@ void ThemeManager::SetupImGuiStyle(const Menu& menu) colors[ImGuiCol_CheckMark] = themeSettings.Palette.Text; - colors[ImGuiCol_Tab] = ImVec4(); - colors[ImGuiCol_TabActive] = ImVec4(); + colors[ImGuiCol_Tab] = themeSettings.FullPalette[ImGuiCol_Tab]; + colors[ImGuiCol_TabActive] = themeSettings.FullPalette[ImGuiCol_TabActive]; colors[ImGuiCol_TabHovered] = tabHovered; - colors[ImGuiCol_TabUnfocused] = colors[ImGuiCol_Tab]; - colors[ImGuiCol_TabUnfocusedActive] = colors[ImGuiCol_TabActive]; + colors[ImGuiCol_TabUnfocused] = themeSettings.FullPalette[ImGuiCol_TabUnfocused]; + colors[ImGuiCol_TabUnfocusedActive] = themeSettings.FullPalette[ImGuiCol_TabUnfocusedActive]; colors[ImGuiCol_PopupBg] = themeSettings.Palette.Background; diff --git a/src/Menu/ThemeManager.h b/src/Menu/ThemeManager.h index 1f340fdb99..e002719473 100644 --- a/src/Menu/ThemeManager.h +++ b/src/Menu/ThemeManager.h @@ -10,13 +10,18 @@ class ThemeManager struct Constants { + // Font size constants + static constexpr float DEFAULT_SCREEN_HEIGHT = 1080.0f; // Default screen resolution to use for subsequent calculations + static constexpr float DEFAULT_FONT_RATIO = 0.025f; // Default 2.5% of screen height + static constexpr float MIN_FONT_SIZE = 16.0f; // ~1.5% @ 1080px height + static constexpr float MAX_FONT_SIZE = 108.0f; // 5.0% @ 2160px height + static constexpr float DEFAULT_FONT_SIZE = 27.0f; + // Font configuration constants - static constexpr float MIN_FONT_SIZE = 8.0f; - static constexpr float MAX_FONT_SIZE = 32.0f; - static constexpr int FCONF_OVERSAMPLE_H = 3; - static constexpr int FCONF_OVERSAMPLE_V = 1; - static constexpr bool FCONF_PIXELSNAP_H = true; - static constexpr float FCONF_RASTERIZER_MULTIPLY = 1.1f; + static constexpr int FCONF_OVERSAMPLE_H = 3; // ImGui default = 2 + static constexpr int FCONF_OVERSAMPLE_V = 2; // ImGui default = 1 + static constexpr bool FCONF_PIXELSNAP_H = true; // ImGui default = false + static constexpr float FCONF_RASTERIZER_MULTIPLY = 1.1f; // ImGui default = 1.0f // Header rendering constants static constexpr float HEADER_BASE_TEXT_SCALE = 1.7f;