From 011816c8ea963b94faedc6378558d84b29580de6 Mon Sep 17 00:00:00 2001 From: Skrubby Skrub In A Shrub <87662196+SkrubbySkrubInAShrub@users.noreply.github.com> Date: Thu, 7 May 2026 18:31:21 +0200 Subject: [PATCH] refactor(UI): implement theme-colored text rendering functions --- src/Features/HDRDisplay.cpp | 24 +++++--------- src/Features/Upscaling.cpp | 32 +++++------------- src/Menu/AdvancedSettingsRenderer.cpp | 2 +- src/Menu/OverlayRenderer.cpp | 2 +- src/Utils/UI.cpp | 47 +++++++++++++++++++++++++++ src/Utils/UI.h | 16 +++++++++ 6 files changed, 83 insertions(+), 40 deletions(-) diff --git a/src/Features/HDRDisplay.cpp b/src/Features/HDRDisplay.cpp index d35b114606..b071aeff34 100644 --- a/src/Features/HDRDisplay.cpp +++ b/src/Features/HDRDisplay.cpp @@ -294,25 +294,23 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( void HDRDisplay::DrawSettings() { if (isHDRMonitor) { - ImGui::TextColored(Util::Colors::GetSuccess(), "HDR Display Detected"); + Util::Text::Success("HDR Display Detected"); } else if (isHDRCapableMonitor) { - ImGui::TextColored(Util::Colors::GetWarning(), "HDR Capable Display (Windows HDR is off)"); + Util::Text::Warning("HDR Capable Display (Windows HDR is off)"); if (auto _tt = Util::HoverTooltipWrapper()) { ImGui::Text("Your monitor supports HDR, but Windows HDR is currently disabled."); ImGui::Text("Enable HDR in Windows Display Settings to allow auto-detection."); } } else { - ImGui::TextColored(Util::Colors::GetWarning(), "SDR Display (HDR not detected)"); + Util::Text::Warning("SDR Display (HDR not detected)"); } const bool isExclusiveFullscreen = globals::features::upscaling.loaded ? !globals::features::upscaling.isWindowed : wasExclusiveFullscreen; if (isExclusiveFullscreen) { ImGui::Spacing(); - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::TextWrapped("WARNING: Exclusive Fullscreen detected."); - ImGui::TextWrapped("HDR is not compatible with Exclusive Fullscreen and may not work correctly. Switch to Borderless Windowed mode for proper HDR support."); - ImGui::PopStyleColor(); + Util::Text::WrappedWarning("WARNING: Exclusive Fullscreen detected."); + Util::Text::WrappedWarning("HDR is not compatible with Exclusive Fullscreen and may not work correctly. Switch to Borderless Windowed mode for proper HDR support."); ImGui::Spacing(); } @@ -401,9 +399,7 @@ void HDRDisplay::DrawSettings() std::lock_guard lock(settingsMutex); if (!isHDRMonitor && settings.enableHDR) { ImGui::Spacing(); - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::TextWrapped("HDR is enabled but no HDR display was detected."); - ImGui::PopStyleColor(); + Util::Text::WrappedWarning("HDR is enabled but no HDR display was detected."); } } @@ -415,13 +411,11 @@ void HDRDisplay::DrawSettings() // Prevent background dimming by pushing lower modal dimming ImGui::PushStyleVar(ImGuiStyleVar_PopupBorderSize, 1.0f); - ImGui::TextColored(Util::Colors::GetWarning(), "WARNING: Force Enable HDR"); + Util::Text::Warning("WARNING: Force Enable HDR"); ImGui::Separator(); ImGui::Spacing(); - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::TextWrapped("HDR was not detected on your monitor."); - ImGui::TextWrapped("The game will look VERY WRONG on an SDR (standard) display."); - ImGui::PopStyleColor(); + Util::Text::WrappedWarning("HDR was not detected on your monitor."); + Util::Text::WrappedWarning("The game will look VERY WRONG on an SDR (standard) display."); ImGui::Spacing(); ImGui::TextWrapped("Only proceed if you have an HDR-capable display that was not detected correctly."); ImGui::Spacing(); diff --git a/src/Features/Upscaling.cpp b/src/Features/Upscaling.cpp index e0fcbd015f..e9cb120e71 100644 --- a/src/Features/Upscaling.cpp +++ b/src/Features/Upscaling.cpp @@ -211,11 +211,9 @@ void Upscaling::DrawSettings() if (!globals::game::isVR && upscaleMethod == UpscaleMethod::kDLSS) { auto screenSize = globals::state->screenSize; if (screenSize.x > streamline.MAX_RESOLUTION || screenSize.y > streamline.MAX_RESOLUTION) { - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::Text("Warning: Requested resolution %.0f x %.0f exceeds maximum supported resolution %d x %d for DLSS.", + Util::Text::Warning("Warning: Requested resolution %.0f x %.0f exceeds maximum supported resolution %d x %d for DLSS.", screenSize.x, screenSize.y, streamline.MAX_RESOLUTION, streamline.MAX_RESOLUTION); - ImGui::Text("DLSS will not function. Lower your resolution or select a different upscaling method."); - ImGui::PopStyleColor(); + Util::Text::Warning("DLSS will not function. Lower your resolution or select a different upscaling method."); } } @@ -277,40 +275,28 @@ void Upscaling::DrawSettings() bool onlyRequiresRestart = true; if (!isWindowed) { - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::Text("Warning: Requires windowed mode"); - ImGui::PopStyleColor(); + Util::Text::Warning("Warning: Requires windowed mode"); onlyRequiresRestart = false; } if (lowRefreshRate && !settings.frameGenerationForceEnable) { - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::Text("Warning: Requires a high refresh rate monitor or Force Enable Frame Generation"); - ImGui::PopStyleColor(); + Util::Text::Warning("Warning: Requires a high refresh rate monitor or Force Enable Frame Generation"); onlyRequiresRestart = false; } if (fidelityFXMissing) { - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::Text("Warning: FidelityFX DLLs are not loaded"); - ImGui::PopStyleColor(); + Util::Text::Warning("Warning: FidelityFX DLLs are not loaded"); onlyRequiresRestart = false; } - if (onlyRequiresRestart && settings.frameGenerationMode && !frameGenerationDx12PathActive) { - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::Text("Warning: Requires restart"); - ImGui::PopStyleColor(); - } + if (onlyRequiresRestart && settings.frameGenerationMode && !frameGenerationDx12PathActive) + Util::Text::Warning("Warning: Requires restart"); - if (!settings.frameGenerationMode && frameGenerationDx12PathActive) { - ImGui::PushStyleColor(ImGuiCol_Text, Util::Colors::GetWarning()); - ImGui::Text("Warning: Requires restart"); - ImGui::PopStyleColor(); - } + if (!settings.frameGenerationMode && frameGenerationDx12PathActive) + Util::Text::Warning("Warning: Requires restart"); std::string enabledLabel = "Enabled"; const char* toggleModes[] = { "Disabled", "Enabled" }; diff --git a/src/Menu/AdvancedSettingsRenderer.cpp b/src/Menu/AdvancedSettingsRenderer.cpp index c69f4f4bc0..8bd217b20d 100644 --- a/src/Menu/AdvancedSettingsRenderer.cpp +++ b/src/Menu/AdvancedSettingsRenderer.cpp @@ -235,7 +235,7 @@ void AdvancedSettingsRenderer::RenderShaderDebugSection() float maxHeight = ImGui::GetContentRegionAvail().y * 0.3f; // Limit to 30% to keep Active Shaders visible if (ImGui::BeginChild("##BlockedShaderInfo", ImVec2(0, maxHeight), true, ImGuiChildFlags_AutoResizeY)) { - ImGui::TextColored(Util::Colors::GetError(), "Shader Blocking Active"); + Util::Text::Error("Shader Blocking Active"); ImGui::SameLine(); if (ImGui::SmallButton("Stop Blocking##Section")) { shaderCache->DisableShaderBlocking(); diff --git a/src/Menu/OverlayRenderer.cpp b/src/Menu/OverlayRenderer.cpp index 0c1d4d70c8..01d5f619e9 100644 --- a/src/Menu/OverlayRenderer.cpp +++ b/src/Menu/OverlayRenderer.cpp @@ -428,7 +428,7 @@ void OverlayRenderer::RenderShaderBlockingStatus() return; } - ImGui::TextColored(Util::Colors::GetError(), "Shader Blocking Active"); + Util::Text::Error("Shader Blocking Active"); ImGui::Text("Blocked: %s", shaderCache->blockedKey.c_str()); // Try to get more details from active shaders diff --git a/src/Utils/UI.cpp b/src/Utils/UI.cpp index 130858c6b4..27a7c3781f 100644 --- a/src/Utils/UI.cpp +++ b/src/Utils/UI.cpp @@ -1415,6 +1415,53 @@ namespace Util { return globals::menu->GetTheme().StatusPalette.Disable; } + + } + + namespace Text + { + static void ColoredTextV(ImVec4 color, const char* fmt, va_list args) + { + ImGui::PushStyleColor(ImGuiCol_Text, color); + ImGui::TextV(fmt, args); + ImGui::PopStyleColor(); + } + + static void ColoredTextWrappedV(ImVec4 color, const char* fmt, va_list args) + { + ImGui::PushStyleColor(ImGuiCol_Text, color); + ImGui::TextWrappedV(fmt, args); + ImGui::PopStyleColor(); + } + +#define UTIL_TEXT(Name, ColorFn) \ + void Name(const char* fmt, ...) { \ + va_list args; \ + va_start(args, fmt); \ + ColoredTextV(Colors::ColorFn(), fmt, args); \ + va_end(args); \ + } +#define UTIL_TEXT_WRAPPED(Name, ColorFn) \ + void Name(const char* fmt, ...) { \ + va_list args; \ + va_start(args, fmt); \ + ColoredTextWrappedV(Colors::ColorFn(), fmt, args); \ + va_end(args); \ + } + + UTIL_TEXT(Warning, GetWarning) + UTIL_TEXT_WRAPPED(WrappedWarning, GetWarning) + UTIL_TEXT(Error, GetError) + UTIL_TEXT_WRAPPED(WrappedError, GetError) + UTIL_TEXT(Success, GetSuccess) + UTIL_TEXT_WRAPPED(WrappedSuccess, GetSuccess) + UTIL_TEXT(Info, GetInfo) + UTIL_TEXT_WRAPPED(WrappedInfo, GetInfo) + UTIL_TEXT(Disabled, GetDisabled) + UTIL_TEXT_WRAPPED(WrappedDisabled, GetDisabled) + +#undef UTIL_TEXT +#undef UTIL_TEXT_WRAPPED } namespace Input diff --git a/src/Utils/UI.h b/src/Utils/UI.h index 1e10acaa3d..fc81ab7b4b 100644 --- a/src/Utils/UI.h +++ b/src/Utils/UI.h @@ -904,6 +904,22 @@ namespace Util ImVec4 GetError(); // Red - error/negative (from theme Error) ImVec4 GetInfo(); // Blue - informational (from theme InfoColor) ImVec4 GetDisabled(); // Gray - disabled items (from theme Disable) + + } + + /** Theme-colored text rendering — self-contained push/text/pop per call. */ + namespace Text + { + void Warning(const char* fmt, ...) IM_FMTARGS(1); + void WrappedWarning(const char* fmt, ...) IM_FMTARGS(1); + void Error(const char* fmt, ...) IM_FMTARGS(1); + void WrappedError(const char* fmt, ...) IM_FMTARGS(1); + void Success(const char* fmt, ...) IM_FMTARGS(1); + void WrappedSuccess(const char* fmt, ...) IM_FMTARGS(1); + void Info(const char* fmt, ...) IM_FMTARGS(1); + void WrappedInfo(const char* fmt, ...) IM_FMTARGS(1); + void Disabled(const char* fmt, ...) IM_FMTARGS(1); + void WrappedDisabled(const char* fmt, ...) IM_FMTARGS(1); } /**