From 2f981ef91e80335e09da939b3dce09a4a797050b Mon Sep 17 00:00:00 2001 From: paxcut <53811119+paxcut@users.noreply.github.com> Date: Thu, 30 Jan 2025 12:18:44 -0700 Subject: [PATCH] fix: Banners not scaling properly with font size (#2096) The banner windows did not scale with the fonts resulting in cropped text when font size was made bigger than normal. fixed by ensuring the window is big enough and then making sure text is centered in the y-axis. --- main/gui/source/window/window.cpp | 2 +- plugins/ui/include/banners/banner_button.hpp | 5 ++++- plugins/ui/include/banners/banner_icon.hpp | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index ea239ea28..48e72052b 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -615,7 +615,7 @@ namespace hex { const auto windowPos = ImHexApi::System::getMainWindowPosition(); float startY = windowPos.y + ImGui::GetTextLineHeight() + ((ImGui::GetTextLineHeight() + (ImGui::GetStyle().FramePadding.y * 2.0F)) * (onWelcomeScreen ? 1 : 2)); - const auto height = 30_scaled; + const auto height = ImGui::GetTextLineHeightWithSpacing() * 1.5f; // Offset banner based on the size of the title bar. On macOS it's slightly taller #if defined(OS_MACOS) diff --git a/plugins/ui/include/banners/banner_button.hpp b/plugins/ui/include/banners/banner_button.hpp index d3b7d598f..680b1118e 100644 --- a/plugins/ui/include/banners/banner_button.hpp +++ b/plugins/ui/include/banners/banner_button.hpp @@ -15,7 +15,10 @@ namespace hex::ui { void drawContent() override { const std::string buttonText = Lang(m_buttonText); const auto buttonSize = ImGui::CalcTextSize(buttonText.c_str()); - + const auto iconSize = ImGui::CalcTextSize(m_icon); + const auto textHeight = std::max(ImGui::CalcTextSize(Lang(m_message)).y, iconSize.y); + const auto textOffset = (ImGui::GetWindowHeight() - textHeight) / 2; + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textOffset); ImGui::TextUnformatted(m_icon); ImGui::SameLine(0, 10_scaled); diff --git a/plugins/ui/include/banners/banner_icon.hpp b/plugins/ui/include/banners/banner_icon.hpp index f96f4c50e..430d364f4 100644 --- a/plugins/ui/include/banners/banner_icon.hpp +++ b/plugins/ui/include/banners/banner_icon.hpp @@ -11,6 +11,9 @@ namespace hex::ui { : Banner(color), m_icon(icon), m_message(std::move(message)) { } void drawContent() override { + auto textHeight = std::max(ImGui::CalcTextSize(Lang(m_message)).y, ImGui::CalcTextSize(m_icon).y); + auto textOffset = (ImGui::GetWindowHeight() - textHeight) / 2; + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textOffset); ImGui::TextUnformatted(m_icon); ImGui::SameLine(0, 10_scaled); ImGui::TextUnformatted(Lang(m_message));