The 'Gamelist on startup' setting now shows the full system names.

This commit is contained in:
Leon Styhre 2021-01-30 15:52:10 +01:00
parent 152fa84529
commit 74ba7d0590
3 changed files with 34 additions and 3 deletions

View file

@ -93,14 +93,33 @@ void GuiMenu::openUISettings()
auto startup_system = std::make_shared<OptionListComponent<std::string>>
(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());

View file

@ -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;

View file

@ -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(