From 3d1261b6d2e7f10a0a55f52c91b5758c61dad308 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 10 Feb 2023 00:45:10 +0100 Subject: [PATCH] Added support for changing the medium and large system font sizes automatically depending on screen orientation. Also fixed an issue where the font size was not calculated correctly when using a vertical screen orientation. --- es-core/src/resources/Font.cpp | 10 ++++--- es-core/src/resources/Font.h | 49 +++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index 0cf5b8858..cf23b0c6e 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -435,14 +435,16 @@ std::shared_ptr Font::getFromTheme(const ThemeData::ThemeElement* elem, if (!(properties & FONT_PATH) && !(properties & FONT_SIZE)) return orig; - float size {static_cast(orig ? orig->mFontSize : FONT_SIZE_MEDIUM)}; + float size {static_cast(orig ? orig->mFontSize : FONT_SIZE_MEDIUM_FIXED)}; std::string path {orig ? orig->mPath : getDefaultPath()}; - float screenHeight {static_cast(Renderer::getScreenHeight())}; + const float screenSize {Renderer::getIsVerticalOrientation() ? + static_cast(Renderer::getScreenWidth()) : + static_cast(Renderer::getScreenHeight())}; if (properties & FONT_SIZE && elem->has("fontSize")) { - size = glm::clamp(screenHeight * elem->get("fontSize"), screenHeight * 0.001f, - screenHeight * 1.5f); + size = glm::clamp(screenSize * elem->get("fontSize"), screenSize * 0.001f, + screenSize * 1.5f); // This is used by the carousel where the itemScale property also scales the font size. size *= sizeMultiplier; } diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index 22ca1ff83..ece1cd7c9 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -21,10 +21,12 @@ class TextCache; -#define FONT_SIZE_MINI 0.030f * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()) -#define FONT_SIZE_SMALL 0.035f * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()) -#define FONT_SIZE_MEDIUM 0.045f * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()) -#define FONT_SIZE_LARGE 0.085f * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth()) +#define FONT_SIZE_MINI Font::getMiniFont() +#define FONT_SIZE_SMALL Font::getSmallFont() +#define FONT_SIZE_MEDIUM Font::getMediumFont() +#define FONT_SIZE_MEDIUM_FIXED Font::getMediumFixedFont() +#define FONT_SIZE_LARGE Font::getLargeFont() +#define FONT_SIZE_LARGE_FIXED Font::getLargeFixedFont() #define FONT_PATH_LIGHT ":/fonts/Akrobat-Regular.ttf" #define FONT_PATH_REGULAR ":/fonts/Akrobat-SemiBold.ttf" @@ -39,6 +41,45 @@ public: static std::shared_ptr get(float size, const std::string& path = getDefaultPath(), const bool linearMagnify = false); + static float getMiniFont() + { + static float sMiniFont {0.030f * + std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())}; + return sMiniFont; + } + static float getSmallFont() + { + static float sSmallFont {0.035f * + std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())}; + return sSmallFont; + } + static float getMediumFont() + { + static float sMediumFont { + (Renderer::getIsVerticalOrientation() ? 0.040f : 0.045f) * + std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())}; + return sMediumFont; + } + static float getMediumFixedFont() + { + // Fixed size regardless of screen orientation. + static float sMediumFixedFont { + 0.045f * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())}; + return sMediumFixedFont; + } + static float getLargeFont() + { + static float sLargeFont {(Renderer::getIsVerticalOrientation() ? 0.080f : 0.085f) * + std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())}; + return sLargeFont; + } + static float getLargeFixedFont() + { + // Fixed size regardless of screen orientation. + static float sLargeFixedFont { + 0.085f * std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())}; + return sLargeFixedFont; + } // Returns the expected size of a string when rendered. Extra spacing is applied to the Y axis. glm::vec2 sizeText(std::string text, float lineSpacing = 1.5f);