From 8ab47188c130d0236a86d84f8cd54bbb5d5249b7 Mon Sep 17 00:00:00 2001 From: soda3000 Date: Thu, 3 Jul 2025 20:49:07 -0300 Subject: [PATCH 1/3] feat(ui): implement dynamic font scaling based on screen resolution --- src/Menu.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Menu.cpp b/src/Menu.cpp index 3ff1e61eb7..5b87e80c17 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -269,11 +269,18 @@ void Menu::Init() font_config.RasterizerMultiply = 1.1f; // Slightly darker font rendering font_config.FontBuilderFlags = 0; // No additional flags needed - // Add high-quality font with improved settings - imgui_io.Fonts->AddFontFromFileTTF("Data\\Interface\\CommunityShaders\\Fonts\\Jost-Regular.ttf", 36, &font_config); - + // Load font DXGI_SWAP_CHAIN_DESC desc; globals::d3d::swapChain->GetDesc(&desc); + UINT height = desc.BufferDesc.Height; // Screen pixel height + // Calculate base font size based on screen height (e.g., 2% of screen height) + const float baseFontSize = height * 0.02f; + // Clamp between reasonable min/max values + const float fontSize = std::clamp(baseFontSize, 24.0f, 48.0f); + + // Add font with dynamic size + imgui_io.Fonts->AddFontFromFileTTF("Data\\Interface\\CommunityShaders\\Fonts\\Jost-Regular.ttf", + std::round(fontSize), &font_config); // Setup Platform/Renderer backends ImGui_ImplWin32_Init(desc.OutputWindow); From 0e84e4229d14eab26753010be64b4e596aee99a9 Mon Sep 17 00:00:00 2001 From: soda3000 Date: Fri, 4 Jul 2025 19:50:00 -0300 Subject: [PATCH 2/3] refactor(ui): fixed typing and exception handling for font loading --- src/Menu.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Menu.cpp b/src/Menu.cpp index 5b87e80c17..d20ffe9d2e 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -270,17 +270,23 @@ void Menu::Init() font_config.FontBuilderFlags = 0; // No additional flags needed // Load font - DXGI_SWAP_CHAIN_DESC desc; - globals::d3d::swapChain->GetDesc(&desc); - UINT height = desc.BufferDesc.Height; // Screen pixel height + DXGI_SWAP_CHAIN_DESC desc{}; + if (FAILED(globals::d3d::swapChain->GetDesc(&desc)) || desc.BufferDesc.Height == 0) { + logger::warn("Failed to get swap chain description. Using default 1080p font size."); + desc.BufferDesc.Height = 1080; + } + uint32_t height = desc.BufferDesc.Height; // Screen pixel height // Calculate base font size based on screen height (e.g., 2% of screen height) const float baseFontSize = height * 0.02f; // Clamp between reasonable min/max values const float fontSize = std::clamp(baseFontSize, 24.0f, 48.0f); // Add font with dynamic size - imgui_io.Fonts->AddFontFromFileTTF("Data\\Interface\\CommunityShaders\\Fonts\\Jost-Regular.ttf", - std::round(fontSize), &font_config); + if (!imgui_io.Fonts->AddFontFromFileTTF("Data\\Interface\\CommunityShaders\\Fonts\\Jost-Regular.ttf", + std::round(fontSize), &font_config)) { + logger::warn("Failed to load custom font. Using default font."); + imgui_io.Fonts->AddFontDefault(); + } // Setup Platform/Renderer backends ImGui_ImplWin32_Init(desc.OutputWindow); From 6c684e4b09b4999a188e5ff67101a08792908618 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 22:50:42 +0000 Subject: [PATCH 3/3] =?UTF-8?q?style:=20=F0=9F=8E=A8=20apply=20pre-commit.?= =?UTF-8?q?ci=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automated formatting by clang-format, prettier, and other hooks. See https://pre-commit.ci for details. --- src/Menu.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Menu.cpp b/src/Menu.cpp index d20ffe9d2e..52f8e05c3e 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -275,15 +275,15 @@ void Menu::Init() logger::warn("Failed to get swap chain description. Using default 1080p font size."); desc.BufferDesc.Height = 1080; } - uint32_t height = desc.BufferDesc.Height; // Screen pixel height + uint32_t height = desc.BufferDesc.Height; // Screen pixel height // Calculate base font size based on screen height (e.g., 2% of screen height) const float baseFontSize = height * 0.02f; // Clamp between reasonable min/max values const float fontSize = std::clamp(baseFontSize, 24.0f, 48.0f); // Add font with dynamic size - if (!imgui_io.Fonts->AddFontFromFileTTF("Data\\Interface\\CommunityShaders\\Fonts\\Jost-Regular.ttf", - std::round(fontSize), &font_config)) { + if (!imgui_io.Fonts->AddFontFromFileTTF("Data\\Interface\\CommunityShaders\\Fonts\\Jost-Regular.ttf", + std::round(fontSize), &font_config)) { logger::warn("Failed to load custom font. Using default font."); imgui_io.Fonts->AddFontDefault(); }