Changed the theme property forceUppercase to the more versatile letterCase property.

This commit is contained in:
Leon Styhre 2022-02-09 22:06:34 +01:00
parent 6db671de3d
commit 09bc9770f2
7 changed files with 149 additions and 29 deletions

View file

@ -1066,11 +1066,16 @@ void ThemeData::parseElement(const pugi::xml_node& root,
std::string nodeName = node.name(); std::string nodeName = node.name();
if (!mLegacyTheme && element.type == "video") { if (!mLegacyTheme) {
if (nodeName == "showSnapshotNoVideo" || nodeName == "showSnapshotDelay") if (nodeName == "showSnapshotNoVideo" || nodeName == "showSnapshotDelay") {
throw error << ": Legacy <" << nodeName throw error << ": Legacy <" << nodeName
<< "> property found for non-legacy theme set"; << "> property found for non-legacy theme set";
} }
else if (nodeName == "forceUppercase") {
throw error << ": Legacy <" << nodeName
<< "> property found for non-legacy theme set";
}
}
// If an attribute exists, then replace nodeName with its name. // If an attribute exists, then replace nodeName with its name.
auto attributeEntry = sPropertyAttributeMap.find(element.type); auto attributeEntry = sPropertyAttributeMap.find(element.type);

View file

@ -50,12 +50,13 @@ namespace ThemeFlags
ALIGNMENT = 0x00000080, ALIGNMENT = 0x00000080,
TEXT = 0x00000100, TEXT = 0x00000100,
METADATA = 0x00000200, METADATA = 0x00000200,
FORCE_UPPERCASE = 0x00000400, LETTER_CASE = 0x00000400,
LINE_SPACING = 0x00000800, FORCE_UPPERCASE = 0x00000800, // For backward compatibility with legacy themes.
DELAY = 0x00001000, LINE_SPACING = 0x00001000,
Z_INDEX = 0x00002000, DELAY = 0x00002000,
ROTATION = 0x00004000, Z_INDEX = 0x00004000,
VISIBLE = 0x00008000, ROTATION = 0x00008000,
VISIBLE = 0x00010000,
ALL = 0xFFFFFFFF ALL = 0xFFFFFFFF
}; };
// clang-format on // clang-format on

View file

@ -94,8 +94,8 @@ void CarouselComponent::addEntry(const std::shared_ptr<ThemeData>& theme,
if (legacyMode) { if (legacyMode) {
text->applyTheme(theme, "system", "text_logoText", text->applyTheme(theme, "system", "text_logoText",
ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR | ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR |
ThemeFlags::FORCE_UPPERCASE | ThemeFlags::LINE_SPACING | ThemeFlags::LETTER_CASE | ThemeFlags::FORCE_UPPERCASE |
ThemeFlags::TEXT); ThemeFlags::LINE_SPACING | ThemeFlags::TEXT);
} }
if (!legacyMode) { if (!legacyMode) {
text->setLineSpacing(mLineSpacing); text->setLineSpacing(mLineSpacing);
@ -401,15 +401,25 @@ void CarouselComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
letterCase = elem->get<std::string>("letterCase"); letterCase = elem->get<std::string>("letterCase");
if (elem->has("text")) { if (elem->has("text")) {
if (letterCase == "uppercase") if (letterCase == "uppercase") {
mText = Utils::String::toUpper(elem->get<std::string>("text")); mText = Utils::String::toUpper(elem->get<std::string>("text"));
else if (letterCase == "lowercase") }
else if (letterCase == "lowercase") {
mText = Utils::String::toLower(elem->get<std::string>("text")); mText = Utils::String::toLower(elem->get<std::string>("text"));
else if (letterCase == "capitalize") }
else if (letterCase == "capitalize") {
mText = Utils::String::toCapitalized(elem->get<std::string>("text")); mText = Utils::String::toCapitalized(elem->get<std::string>("text"));
else }
else if (letterCase == "none") {
mText = elem->get<std::string>("text"); mText = elem->get<std::string>("text");
} }
else {
LOG(LogWarning)
<< "CarouselComponent: Invalid theme configuration, property <letterCase> set to \""
<< letterCase << "\"";
mText = elem->get<std::string>("text");
}
}
GuiComponent::applyTheme(theme, view, element, ALL); GuiComponent::applyTheme(theme, view, element, ALL);
} }

View file

@ -147,6 +147,25 @@ void DateTimeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & METADATA && elem->has("metadata")) if (properties & METADATA && elem->has("metadata"))
setMetadataField(elem->get<std::string>("metadata")); setMetadataField(elem->get<std::string>("metadata"));
if (properties & LETTER_CASE && elem->has("letterCase")) {
std::string letterCase {elem->get<std::string>("letterCase")};
if (letterCase == "uppercase") {
setUppercase(true);
}
else if (letterCase == "lowercase") {
setLowercase(true);
}
else if (letterCase == "capitalize") {
setCapitalize(true);
}
else if (letterCase != "none") {
LOG(LogWarning)
<< "DateTimeComponent: Invalid theme configuration, property <letterCase> set to \""
<< letterCase << "\"";
}
}
// Legacy themes only.
if (properties & FORCE_UPPERCASE && elem->has("forceUppercase")) if (properties & FORCE_UPPERCASE && elem->has("forceUppercase"))
setUppercase(elem->get<bool>("forceUppercase")); setUppercase(elem->get<bool>("forceUppercase"));

View file

@ -21,7 +21,7 @@ TextComponent::TextComponent()
, mRenderBackground {false} , mRenderBackground {false}
, mUppercase {false} , mUppercase {false}
, mLowercase {false} , mLowercase {false}
, mCapitalized {false} , mCapitalize {false}
, mAutoCalcExtent {1, 1} , mAutoCalcExtent {1, 1}
, mHorizontalAlignment {ALIGN_LEFT} , mHorizontalAlignment {ALIGN_LEFT}
, mVerticalAlignment {ALIGN_CENTER} , mVerticalAlignment {ALIGN_CENTER}
@ -46,7 +46,7 @@ TextComponent::TextComponent(const std::string& text,
, mRenderBackground {false} , mRenderBackground {false}
, mUppercase {false} , mUppercase {false}
, mLowercase {false} , mLowercase {false}
, mCapitalized {false} , mCapitalize {false}
, mAutoCalcExtent {1, 1} , mAutoCalcExtent {1, 1}
, mHorizontalAlignment {align} , mHorizontalAlignment {align}
, mVerticalAlignment {ALIGN_CENTER} , mVerticalAlignment {ALIGN_CENTER}
@ -126,7 +126,7 @@ void TextComponent::setUppercase(bool uppercase)
mUppercase = uppercase; mUppercase = uppercase;
if (uppercase) { if (uppercase) {
mLowercase = false; mLowercase = false;
mCapitalized = false; mCapitalize = false;
} }
onTextChanged(); onTextChanged();
} }
@ -136,15 +136,15 @@ void TextComponent::setLowercase(bool lowercase)
mLowercase = lowercase; mLowercase = lowercase;
if (lowercase) { if (lowercase) {
mUppercase = false; mUppercase = false;
mCapitalized = false; mCapitalize = false;
} }
onTextChanged(); onTextChanged();
} }
void TextComponent::setCapitalized(bool capitalized) void TextComponent::setCapitalize(bool capitalize)
{ {
mCapitalized = capitalized; mCapitalize = capitalize;
if (capitalized) { if (capitalize) {
mUppercase = false; mUppercase = false;
mLowercase = false; mLowercase = false;
} }
@ -230,7 +230,7 @@ void TextComponent::calculateExtent()
mSize = mFont->sizeText(Utils::String::toUpper(mText), mLineSpacing); mSize = mFont->sizeText(Utils::String::toUpper(mText), mLineSpacing);
else if (mLowercase) else if (mLowercase)
mSize = mFont->sizeText(Utils::String::toLower(mText), mLineSpacing); mSize = mFont->sizeText(Utils::String::toLower(mText), mLineSpacing);
else if (mCapitalized) else if (mCapitalize)
mSize = mFont->sizeText(Utils::String::toCapitalized(mText), mLineSpacing); mSize = mFont->sizeText(Utils::String::toCapitalized(mText), mLineSpacing);
else else
mSize = mFont->sizeText(mText, mLineSpacing); // Original case. mSize = mFont->sizeText(mText, mLineSpacing); // Original case.
@ -247,7 +247,7 @@ void TextComponent::calculateExtent()
mFont->sizeWrappedText(Utils::String::toLower(mText), getSize().x, mLineSpacing) mFont->sizeWrappedText(Utils::String::toLower(mText), getSize().x, mLineSpacing)
.y; .y;
} }
else if (mCapitalized) { else if (mCapitalize) {
mSize.y = mFont mSize.y = mFont
->sizeWrappedText(Utils::String::toCapitalized(mText), getSize().x, ->sizeWrappedText(Utils::String::toCapitalized(mText), getSize().x,
mLineSpacing) mLineSpacing)
@ -275,7 +275,7 @@ void TextComponent::onTextChanged()
text = Utils::String::toUpper(mText); text = Utils::String::toUpper(mText);
else if (mLowercase) else if (mLowercase)
text = Utils::String::toLower(mText); text = Utils::String::toLower(mText);
else if (mCapitalized) else if (mCapitalize)
text = Utils::String::toCapitalized(mText); text = Utils::String::toCapitalized(mText);
else else
text = mText; // Original case. text = mText; // Original case.
@ -397,6 +397,25 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & METADATA && elem->has("metadata")) if (properties & METADATA && elem->has("metadata"))
setMetadataField(elem->get<std::string>("metadata")); setMetadataField(elem->get<std::string>("metadata"));
if (properties & LETTER_CASE && elem->has("letterCase")) {
std::string letterCase {elem->get<std::string>("letterCase")};
if (letterCase == "uppercase") {
setUppercase(true);
}
else if (letterCase == "lowercase") {
setLowercase(true);
}
else if (letterCase == "capitalize") {
setCapitalize(true);
}
else if (letterCase != "none") {
LOG(LogWarning)
<< "TextComponent: Invalid theme configuration, property <letterCase> set to \""
<< letterCase << "\"";
}
}
// Legacy themes only.
if (properties & FORCE_UPPERCASE && elem->has("forceUppercase")) if (properties & FORCE_UPPERCASE && elem->has("forceUppercase"))
setUppercase(elem->get<bool>("forceUppercase")); setUppercase(elem->get<bool>("forceUppercase"));

View file

@ -36,7 +36,7 @@ public:
void setFont(const std::shared_ptr<Font>& font); void setFont(const std::shared_ptr<Font>& font);
void setUppercase(bool uppercase); void setUppercase(bool uppercase);
void setLowercase(bool lowercase); void setLowercase(bool lowercase);
void setCapitalized(bool capitalize); void setCapitalize(bool capitalize);
void onSizeChanged() override; void onSizeChanged() override;
void setText(const std::string& text, bool update = true); void setText(const std::string& text, bool update = true);
void setHiddenText(const std::string& text) { mHiddenText = text; } void setHiddenText(const std::string& text) { mHiddenText = text; }
@ -93,7 +93,7 @@ private:
bool mUppercase; bool mUppercase;
bool mLowercase; bool mLowercase;
bool mCapitalized; bool mCapitalize;
glm::ivec2 mAutoCalcExtent; glm::ivec2 mAutoCalcExtent;
std::shared_ptr<TextCache> mTextCache; std::shared_ptr<TextCache> mTextCache;
Alignment mHorizontalAlignment; Alignment mHorizontalAlignment;

View file

@ -78,6 +78,38 @@ public:
void setUppercase(bool uppercase) void setUppercase(bool uppercase)
{ {
mUppercase = uppercase; mUppercase = uppercase;
if (uppercase) {
mLowercase = false;
mCapitalize = false;
}
for (auto it = mEntries.begin(); it != mEntries.end(); ++it)
it->data.textCache.reset();
}
void setLowercase(bool lowercase)
{
mLowercase = lowercase;
if (lowercase) {
mUppercase = false;
mCapitalize = false;
}
for (auto it = mEntries.begin(); it != mEntries.end(); ++it)
it->data.textCache.reset();
}
void setCapitalize(bool capitalize)
{
mCapitalize = capitalize;
if (capitalize) {
mUppercase = false;
mLowercase = false;
}
for (auto it = mEntries.begin(); it != mEntries.end(); ++it) for (auto it = mEntries.begin(); it != mEntries.end(); ++it)
it->data.textCache.reset(); it->data.textCache.reset();
} }
@ -115,6 +147,8 @@ private:
std::shared_ptr<Font> mFont; std::shared_ptr<Font> mFont;
bool mUppercase; bool mUppercase;
bool mLowercase;
bool mCapitalize;
float mLineSpacing; float mLineSpacing;
float mSelectorHeight; float mSelectorHeight;
float mSelectorOffsetY; float mSelectorOffsetY;
@ -140,6 +174,8 @@ template <typename T> TextListComponent<T>::TextListComponent()
mFont = Font::get(FONT_SIZE_MEDIUM); mFont = Font::get(FONT_SIZE_MEDIUM);
mUppercase = false; mUppercase = false;
mLowercase = false;
mCapitalize = false;
mLineSpacing = 1.5f; mLineSpacing = 1.5f;
mSelectorHeight = mFont->getSize() * 1.5f; mSelectorHeight = mFont->getSize() * 1.5f;
mSelectorOffsetY = 0; mSelectorOffsetY = 0;
@ -229,9 +265,20 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
else else
color = mColors[entry.data.colorId]; color = mColors[entry.data.colorId];
if (!entry.data.textCache) if (!entry.data.textCache) {
if (mUppercase)
entry.data.textCache = std::unique_ptr<TextCache>(
font->buildTextCache(Utils::String::toUpper(entry.name), 0, 0, 0x000000FF));
else if (mLowercase)
entry.data.textCache = std::unique_ptr<TextCache>(
font->buildTextCache(Utils::String::toLower(entry.name), 0, 0, 0x000000FF));
else if (mCapitalize)
entry.data.textCache = std::unique_ptr<TextCache>(font->buildTextCache( entry.data.textCache = std::unique_ptr<TextCache>(font->buildTextCache(
mUppercase ? Utils::String::toUpper(entry.name) : entry.name, 0, 0, 0x000000FF)); Utils::String::toCapitalized(entry.name), 0, 0, 0x000000FF));
else
entry.data.textCache =
std::unique_ptr<TextCache>(font->buildTextCache(entry.name, 0, 0, 0x000000FF));
}
// If a game is marked as hidden, lower the text opacity a lot. // If a game is marked as hidden, lower the text opacity a lot.
// If a game is marked to not be counted, lower the opacity a moderate amount. // If a game is marked to not be counted, lower the opacity a moderate amount.
@ -462,6 +509,25 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
} }
if (properties & LETTER_CASE && elem->has("letterCase")) {
std::string letterCase {elem->get<std::string>("letterCase")};
if (letterCase == "uppercase") {
setUppercase(true);
}
else if (letterCase == "lowercase") {
setLowercase(true);
}
else if (letterCase == "capitalize") {
setCapitalize(true);
}
else if (letterCase != "none") {
LOG(LogWarning)
<< "TextListComponent: Invalid theme configuration, property <letterCase> set to \""
<< letterCase << "\"";
}
}
// Legacy themes only.
if (properties & FORCE_UPPERCASE && elem->has("forceUppercase")) if (properties & FORCE_UPPERCASE && elem->has("forceUppercase"))
setUppercase(elem->get<bool>("forceUppercase")); setUppercase(elem->get<bool>("forceUppercase"));