From 74ba7d05905c968fd1d91d344a2f8cba0c403df1 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 30 Jan 2021 15:52:10 +0100 Subject: [PATCH] The 'Gamelist on startup' setting now shows the full system names. --- es-app/src/guis/GuiMenu.cpp | 25 ++++++++++++++++++++++--- es-core/src/resources/Font.cpp | 10 ++++++++++ es-core/src/resources/Font.h | 2 ++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index fcb3152c9..f4547ecaf 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -93,14 +93,33 @@ void GuiMenu::openUISettings() auto startup_system = std::make_shared> (mWindow, getHelpStyle(), "GAMELIST ON STARTUP", false); startup_system->add("NONE", "", Settings::getInstance()->getString("StartupSystem") == ""); + float dotsSize = Font::get(FONT_SIZE_MEDIUM)->sizeText("...").x(); for (auto it = SystemData::sSystemVector.cbegin(); it != SystemData::sSystemVector.cend(); it++) { - if ("retropie" != (*it)->getName()) { - startup_system->add((*it)->getName(), (*it)->getName(), + if ((*it)->getName() != "retropie") { + // If required, abbreviate the system name so it doesn't overlap the setting name. + std::string abbreviatedString = Font::get(FONT_SIZE_MEDIUM)-> + getTextMaxWidth((*it)->getFullName(), Renderer::getScreenWidth() * 0.25f); + float sizeDifference = Font::get(FONT_SIZE_MEDIUM)->sizeText((*it)->getFullName()).x() - + Font::get(FONT_SIZE_MEDIUM)->sizeText(abbreviatedString).x(); + if (sizeDifference > 0) { + // It doesn't make sense to abbreviate if the number of pixels removed by + // the abbreviation is less or equal to the size of the three dots that + // would be appended to the string. + if (sizeDifference <= dotsSize) { + abbreviatedString = (*it)->getFullName(); + } + else { + if (abbreviatedString.back() == ' ') + abbreviatedString.pop_back(); + abbreviatedString += "..."; + } + } + startup_system->add(abbreviatedString, (*it)->getName(), Settings::getInstance()->getString("StartupSystem") == (*it)->getName()); } } - s->addWithLabel("GAMELIST TO SHOW ON STARTUP", startup_system); + s->addWithLabel("GAMELIST ON STARTUP", startup_system); s->addSaveFunc([startup_system, s] { if (startup_system->getSelected() != Settings::getInstance()->getString("StartupSystem")) { Settings::getInstance()->setString("StartupSystem", startup_system->getSelected()); diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index 20d90e767..84476c45b 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -416,6 +416,16 @@ Vector2f Font::sizeText(std::string text, float lineSpacing) return Vector2f(highestWidth, y); } +std::string Font::getTextMaxWidth(std::string text, float maxWidth) +{ + float width = sizeText(text).x(); + while (width > maxWidth) { + text.pop_back(); + width = sizeText(text).x(); + } + return text; +} + float Font::getHeight(float lineSpacing) const { return mMaxGlyphHeight * lineSpacing; diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index 571c90f48..11648fde7 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -55,6 +55,8 @@ public: // Returns the expected size of a string when rendered. Extra spacing is applied to the Y axis. Vector2f sizeText(std::string text, float lineSpacing = 1.5f); + // Returns the portion of a string that fits within the passed argument maxWidth. + std::string getTextMaxWidth(std::string text, float maxWidth); TextCache* buildTextCache(const std::string& text, float offsetX, float offsetY, unsigned int color, float lineSpacing = 1.5f); TextCache* buildTextCache(