Improved some theme warning messages in TextListComponent.

Also changed some theme values to be read by reference instead of by copy in CarouselComponent.
This commit is contained in:
Leon Styhre 2022-11-03 15:36:43 +01:00
parent 7684c92646
commit b43c8cdd55
2 changed files with 48 additions and 38 deletions

View file

@ -931,7 +931,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
mLegacyMode = theme->isLegacyTheme(); mLegacyMode = theme->isLegacyTheme();
if (elem->has("type")) { if (elem->has("type")) {
const std::string type {elem->get<std::string>("type")}; const std::string& type {elem->get<std::string>("type")};
if (type == "horizontal") { if (type == "horizontal") {
mType = CarouselType::HORIZONTAL; mType = CarouselType::HORIZONTAL;
} }
@ -960,7 +960,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
mCarouselColorEnd = elem->get<unsigned int>("colorEnd"); mCarouselColorEnd = elem->get<unsigned int>("colorEnd");
if (elem->has("gradientType")) { if (elem->has("gradientType")) {
const std::string gradientType {elem->get<std::string>("gradientType")}; const std::string& gradientType {elem->get<std::string>("gradientType")};
if (gradientType == "horizontal") { if (gradientType == "horizontal") {
mColorGradientHorizontal = true; mColorGradientHorizontal = true;
} }
@ -1009,7 +1009,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
mItemScale = glm::clamp(elem->get<float>("itemScale"), 0.2f, 3.0f); mItemScale = glm::clamp(elem->get<float>("itemScale"), 0.2f, 3.0f);
if (elem->has("itemTransitions")) { if (elem->has("itemTransitions")) {
const std::string itemTransitions {elem->get<std::string>("itemTransitions")}; const std::string& itemTransitions {elem->get<std::string>("itemTransitions")};
if (itemTransitions == "slide") { if (itemTransitions == "slide") {
mInstantItemTransitions = false; mInstantItemTransitions = false;
} }
@ -1026,7 +1026,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (elem->has("itemInterpolation")) { if (elem->has("itemInterpolation")) {
const std::string itemInterpolation {elem->get<std::string>("itemInterpolation")}; const std::string& itemInterpolation {elem->get<std::string>("itemInterpolation")};
if (itemInterpolation == "linear") { if (itemInterpolation == "linear") {
mLinearInterpolation = true; mLinearInterpolation = true;
} }
@ -1052,7 +1052,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
(elem->has("itemAxisHorizontal") && elem->get<bool>("itemAxisHorizontal")); (elem->has("itemAxisHorizontal") && elem->get<bool>("itemAxisHorizontal"));
if (elem->has("itemHorizontalAlignment")) { if (elem->has("itemHorizontalAlignment")) {
const std::string alignment {elem->get<std::string>("itemHorizontalAlignment")}; const std::string& alignment {elem->get<std::string>("itemHorizontalAlignment")};
if (alignment == "left" && mType != CarouselType::HORIZONTAL) { if (alignment == "left" && mType != CarouselType::HORIZONTAL) {
mItemHorizontalAlignment = ALIGN_LEFT; mItemHorizontalAlignment = ALIGN_LEFT;
} }
@ -1071,7 +1071,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (elem->has("itemVerticalAlignment")) { if (elem->has("itemVerticalAlignment")) {
const std::string alignment {elem->get<std::string>("itemVerticalAlignment")}; const std::string& alignment {elem->get<std::string>("itemVerticalAlignment")};
if (alignment == "top" && mType != CarouselType::VERTICAL) { if (alignment == "top" && mType != CarouselType::VERTICAL) {
mItemVerticalAlignment = ALIGN_TOP; mItemVerticalAlignment = ALIGN_TOP;
} }
@ -1090,7 +1090,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (elem->has("wheelHorizontalAlignment")) { if (elem->has("wheelHorizontalAlignment")) {
const std::string alignment {elem->get<std::string>("wheelHorizontalAlignment")}; const std::string& alignment {elem->get<std::string>("wheelHorizontalAlignment")};
if (alignment == "left") { if (alignment == "left") {
mWheelHorizontalAlignment = ALIGN_LEFT; mWheelHorizontalAlignment = ALIGN_LEFT;
} }
@ -1172,7 +1172,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
mItemRotationOrigin = elem->get<glm::vec2>("logoRotationOrigin"); mItemRotationOrigin = elem->get<glm::vec2>("logoRotationOrigin");
if (elem->has("logoAlignment")) { if (elem->has("logoAlignment")) {
const std::string alignment {elem->get<std::string>("logoAlignment")}; const std::string& alignment {elem->get<std::string>("logoAlignment")};
if (alignment == "left" && mType != CarouselType::HORIZONTAL) { if (alignment == "left" && mType != CarouselType::HORIZONTAL) {
mItemHorizontalAlignment = ALIGN_LEFT; mItemHorizontalAlignment = ALIGN_LEFT;
mItemVerticalAlignment = ALIGN_CENTER; mItemVerticalAlignment = ALIGN_CENTER;
@ -1216,7 +1216,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
mLineSpacing = glm::clamp(elem->get<float>("lineSpacing"), 0.5f, 3.0f); mLineSpacing = glm::clamp(elem->get<float>("lineSpacing"), 0.5f, 3.0f);
if (elem->has("letterCase")) { if (elem->has("letterCase")) {
const std::string letterCase {elem->get<std::string>("letterCase")}; const std::string& letterCase {elem->get<std::string>("letterCase")};
if (letterCase == "uppercase") { if (letterCase == "uppercase") {
mLetterCase = LetterCase::UPPERCASE; mLetterCase = LetterCase::UPPERCASE;
@ -1235,7 +1235,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (elem->has("letterCaseCollections")) { if (elem->has("letterCaseCollections")) {
const std::string letterCase {elem->get<std::string>("letterCaseCollections")}; const std::string& letterCase {elem->get<std::string>("letterCaseCollections")};
if (letterCase == "uppercase") { if (letterCase == "uppercase") {
mLetterCaseCollections = LetterCase::UPPERCASE; mLetterCaseCollections = LetterCase::UPPERCASE;
@ -1254,7 +1254,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (elem->has("letterCaseGroupedCollections")) { if (elem->has("letterCaseGroupedCollections")) {
const std::string letterCase {elem->get<std::string>("letterCaseGroupedCollections")}; const std::string& letterCase {elem->get<std::string>("letterCaseGroupedCollections")};
if (letterCase == "uppercase") { if (letterCase == "uppercase") {
mLetterCaseGroupedCollections = LetterCase::UPPERCASE; mLetterCaseGroupedCollections = LetterCase::UPPERCASE;

View file

@ -499,7 +499,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("selectorColorEnd")) if (elem->has("selectorColorEnd"))
setSelectorColorEnd(elem->get<unsigned int>("selectorColorEnd")); setSelectorColorEnd(elem->get<unsigned int>("selectorColorEnd"));
if (elem->has("selectorGradientType")) { if (elem->has("selectorGradientType")) {
const std::string gradientType {elem->get<std::string>("selectorGradientType")}; const std::string& gradientType {elem->get<std::string>("selectorGradientType")};
if (gradientType == "horizontal") { if (gradientType == "horizontal") {
setSelectorColorGradientHorizontal(true); setSelectorColorGradientHorizontal(true);
} }
@ -509,8 +509,8 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
else { else {
setSelectorColorGradientHorizontal(true); setSelectorColorGradientHorizontal(true);
LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property "
"<selectorGradientType> defined as \"" "\"selectorGradientType\" for element \""
<< gradientType << "\""; << element.substr(9) << "\" defined as \"" << gradientType << "\"";
} }
} }
if (elem->has("selectedColor")) if (elem->has("selectedColor"))
@ -527,31 +527,40 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & ALIGNMENT) { if (properties & ALIGNMENT) {
if (elem->has("horizontalAlignment")) { if (elem->has("horizontalAlignment")) {
const std::string& str {elem->get<std::string>("horizontalAlignment")}; const std::string& horizontalAlignment {elem->get<std::string>("horizontalAlignment")};
if (str == "left") if (horizontalAlignment == "left") {
setAlignment(PrimaryAlignment::ALIGN_LEFT); setAlignment(PrimaryAlignment::ALIGN_LEFT);
else if (str == "center") }
else if (horizontalAlignment == "center") {
setAlignment(PrimaryAlignment::ALIGN_CENTER); setAlignment(PrimaryAlignment::ALIGN_CENTER);
else if (str == "right") }
else if (horizontalAlignment == "right") {
setAlignment(PrimaryAlignment::ALIGN_RIGHT); setAlignment(PrimaryAlignment::ALIGN_RIGHT);
else }
else {
LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property "
"<horizontalAlignment> defined as \"" "\"horizontalAlignment\" for element \""
<< str << "\""; << element.substr(9) << "\" defined as \"" << horizontalAlignment
<< "\"";
}
} }
// Legacy themes only. // Legacy themes only.
else if (elem->has("alignment")) { else if (elem->has("alignment")) {
const std::string& str {elem->get<std::string>("alignment")}; const std::string& alignment {elem->get<std::string>("alignment")};
if (str == "left") if (alignment == "left") {
setAlignment(PrimaryAlignment::ALIGN_LEFT); setAlignment(PrimaryAlignment::ALIGN_LEFT);
else if (str == "center") }
else if (alignment == "center") {
setAlignment(PrimaryAlignment::ALIGN_CENTER); setAlignment(PrimaryAlignment::ALIGN_CENTER);
else if (str == "right") }
else if (alignment == "right") {
setAlignment(PrimaryAlignment::ALIGN_RIGHT); setAlignment(PrimaryAlignment::ALIGN_RIGHT);
else }
else {
LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property "
"<alignment> defined as \"" "\"alignment\" for element \""
<< str << "\""; << element.substr(9) << "\" defined as \"" << alignment << "\"";
}
} }
if (elem->has("horizontalMargin")) { if (elem->has("horizontalMargin")) {
mHorizontalMargin = mHorizontalMargin =
@ -561,7 +570,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (properties & LETTER_CASE && elem->has("letterCase")) { if (properties & LETTER_CASE && elem->has("letterCase")) {
const std::string letterCase {elem->get<std::string>("letterCase")}; const std::string& letterCase {elem->get<std::string>("letterCase")};
if (letterCase == "uppercase") { if (letterCase == "uppercase") {
mLetterCase = LetterCase::UPPERCASE; mLetterCase = LetterCase::UPPERCASE;
} }
@ -579,7 +588,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (properties & LETTER_CASE && elem->has("letterCaseCollections")) { if (properties & LETTER_CASE && elem->has("letterCaseCollections")) {
const std::string letterCase {elem->get<std::string>("letterCaseCollections")}; const std::string& letterCase {elem->get<std::string>("letterCaseCollections")};
if (letterCase == "uppercase") { if (letterCase == "uppercase") {
mLetterCaseCollections = LetterCase::UPPERCASE; mLetterCaseCollections = LetterCase::UPPERCASE;
} }
@ -597,7 +606,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (properties & LETTER_CASE && elem->has("letterCaseGroupedCollections")) { if (properties & LETTER_CASE && elem->has("letterCaseGroupedCollections")) {
const std::string letterCase {elem->get<std::string>("letterCaseGroupedCollections")}; const std::string& letterCase {elem->get<std::string>("letterCaseGroupedCollections")};
if (letterCase == "uppercase") { if (letterCase == "uppercase") {
mLetterCaseGroupedCollections = LetterCase::UPPERCASE; mLetterCaseGroupedCollections = LetterCase::UPPERCASE;
} }
@ -636,33 +645,34 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
if (elem->has("indicators")) { if (elem->has("indicators")) {
std::string indicators {elem->get<std::string>("indicators")}; const std::string& indicators {elem->get<std::string>("indicators")};
if (indicators == "symbols" || indicators == "ascii" || indicators == "none") { if (indicators == "symbols" || indicators == "ascii" || indicators == "none") {
mIndicators = indicators; mIndicators = indicators;
} }
else { else {
mIndicators = "symbols"; mIndicators = "symbols";
LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property "
"<indicators> defined as \"" "\"indicators\" for element \""
<< indicators << "\""; << element.substr(9) << "\" defined as \"" << indicators << "\"";
} }
} }
if (elem->has("collectionIndicators")) { if (elem->has("collectionIndicators")) {
std::string collectionIndicators {elem->get<std::string>("collectionIndicators")}; const std::string& collectionIndicators {elem->get<std::string>("collectionIndicators")};
if (collectionIndicators == "symbols" || collectionIndicators == "ascii") { if (collectionIndicators == "symbols" || collectionIndicators == "ascii") {
mCollectionIndicators = collectionIndicators; mCollectionIndicators = collectionIndicators;
} }
else { else {
mCollectionIndicators = "symbols"; mCollectionIndicators = "symbols";
LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property "
"<collectionIndicators> defined as \"" "\"collectionIndicators\" for element \""
<< collectionIndicators << "\""; << element.substr(9) << "\" defined as \"" << collectionIndicators
<< "\"";
} }
} }
if (elem->has("selectorImagePath")) { if (elem->has("selectorImagePath")) {
std::string path {elem->get<std::string>("selectorImagePath")}; const std::string& path {elem->get<std::string>("selectorImagePath")};
bool tile {elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile")}; bool tile {elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile")};
mSelectorImage.setImage(path, tile); mSelectorImage.setImage(path, tile);
mSelectorImage.setSize(mSize.x, mSelectorHeight); mSelectorImage.setSize(mSize.x, mSelectorHeight);