From b43c8cdd55f8d0f9b841384f8652474487b51791 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 3 Nov 2022 15:36:43 +0100 Subject: [PATCH] Improved some theme warning messages in TextListComponent. Also changed some theme values to be read by reference instead of by copy in CarouselComponent. --- .../components/primary/CarouselComponent.h | 22 +++---- .../components/primary/TextListComponent.h | 64 +++++++++++-------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index 6a47e8023..2be7f9d0b 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -931,7 +931,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, mLegacyMode = theme->isLegacyTheme(); if (elem->has("type")) { - const std::string type {elem->get("type")}; + const std::string& type {elem->get("type")}; if (type == "horizontal") { mType = CarouselType::HORIZONTAL; } @@ -960,7 +960,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, mCarouselColorEnd = elem->get("colorEnd"); if (elem->has("gradientType")) { - const std::string gradientType {elem->get("gradientType")}; + const std::string& gradientType {elem->get("gradientType")}; if (gradientType == "horizontal") { mColorGradientHorizontal = true; } @@ -1009,7 +1009,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, mItemScale = glm::clamp(elem->get("itemScale"), 0.2f, 3.0f); if (elem->has("itemTransitions")) { - const std::string itemTransitions {elem->get("itemTransitions")}; + const std::string& itemTransitions {elem->get("itemTransitions")}; if (itemTransitions == "slide") { mInstantItemTransitions = false; } @@ -1026,7 +1026,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("itemInterpolation")) { - const std::string itemInterpolation {elem->get("itemInterpolation")}; + const std::string& itemInterpolation {elem->get("itemInterpolation")}; if (itemInterpolation == "linear") { mLinearInterpolation = true; } @@ -1052,7 +1052,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, (elem->has("itemAxisHorizontal") && elem->get("itemAxisHorizontal")); if (elem->has("itemHorizontalAlignment")) { - const std::string alignment {elem->get("itemHorizontalAlignment")}; + const std::string& alignment {elem->get("itemHorizontalAlignment")}; if (alignment == "left" && mType != CarouselType::HORIZONTAL) { mItemHorizontalAlignment = ALIGN_LEFT; } @@ -1071,7 +1071,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("itemVerticalAlignment")) { - const std::string alignment {elem->get("itemVerticalAlignment")}; + const std::string& alignment {elem->get("itemVerticalAlignment")}; if (alignment == "top" && mType != CarouselType::VERTICAL) { mItemVerticalAlignment = ALIGN_TOP; } @@ -1090,7 +1090,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("wheelHorizontalAlignment")) { - const std::string alignment {elem->get("wheelHorizontalAlignment")}; + const std::string& alignment {elem->get("wheelHorizontalAlignment")}; if (alignment == "left") { mWheelHorizontalAlignment = ALIGN_LEFT; } @@ -1172,7 +1172,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, mItemRotationOrigin = elem->get("logoRotationOrigin"); if (elem->has("logoAlignment")) { - const std::string alignment {elem->get("logoAlignment")}; + const std::string& alignment {elem->get("logoAlignment")}; if (alignment == "left" && mType != CarouselType::HORIZONTAL) { mItemHorizontalAlignment = ALIGN_LEFT; mItemVerticalAlignment = ALIGN_CENTER; @@ -1216,7 +1216,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, mLineSpacing = glm::clamp(elem->get("lineSpacing"), 0.5f, 3.0f); if (elem->has("letterCase")) { - const std::string letterCase {elem->get("letterCase")}; + const std::string& letterCase {elem->get("letterCase")}; if (letterCase == "uppercase") { mLetterCase = LetterCase::UPPERCASE; @@ -1235,7 +1235,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("letterCaseCollections")) { - const std::string letterCase {elem->get("letterCaseCollections")}; + const std::string& letterCase {elem->get("letterCaseCollections")}; if (letterCase == "uppercase") { mLetterCaseCollections = LetterCase::UPPERCASE; @@ -1254,7 +1254,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("letterCaseGroupedCollections")) { - const std::string letterCase {elem->get("letterCaseGroupedCollections")}; + const std::string& letterCase {elem->get("letterCaseGroupedCollections")}; if (letterCase == "uppercase") { mLetterCaseGroupedCollections = LetterCase::UPPERCASE; diff --git a/es-core/src/components/primary/TextListComponent.h b/es-core/src/components/primary/TextListComponent.h index 2bc074751..25ec89eed 100644 --- a/es-core/src/components/primary/TextListComponent.h +++ b/es-core/src/components/primary/TextListComponent.h @@ -499,7 +499,7 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("selectorColorEnd")) setSelectorColorEnd(elem->get("selectorColorEnd")); if (elem->has("selectorGradientType")) { - const std::string gradientType {elem->get("selectorGradientType")}; + const std::string& gradientType {elem->get("selectorGradientType")}; if (gradientType == "horizontal") { setSelectorColorGradientHorizontal(true); } @@ -509,8 +509,8 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, else { setSelectorColorGradientHorizontal(true); LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " - " defined as \"" - << gradientType << "\""; + "\"selectorGradientType\" for element \"" + << element.substr(9) << "\" defined as \"" << gradientType << "\""; } } if (elem->has("selectedColor")) @@ -527,31 +527,40 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, if (properties & ALIGNMENT) { if (elem->has("horizontalAlignment")) { - const std::string& str {elem->get("horizontalAlignment")}; - if (str == "left") + const std::string& horizontalAlignment {elem->get("horizontalAlignment")}; + if (horizontalAlignment == "left") { setAlignment(PrimaryAlignment::ALIGN_LEFT); - else if (str == "center") + } + else if (horizontalAlignment == "center") { setAlignment(PrimaryAlignment::ALIGN_CENTER); - else if (str == "right") + } + else if (horizontalAlignment == "right") { setAlignment(PrimaryAlignment::ALIGN_RIGHT); - else + } + else { LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " - " defined as \"" - << str << "\""; + "\"horizontalAlignment\" for element \"" + << element.substr(9) << "\" defined as \"" << horizontalAlignment + << "\""; + } } // Legacy themes only. else if (elem->has("alignment")) { - const std::string& str {elem->get("alignment")}; - if (str == "left") + const std::string& alignment {elem->get("alignment")}; + if (alignment == "left") { setAlignment(PrimaryAlignment::ALIGN_LEFT); - else if (str == "center") + } + else if (alignment == "center") { setAlignment(PrimaryAlignment::ALIGN_CENTER); - else if (str == "right") + } + else if (alignment == "right") { setAlignment(PrimaryAlignment::ALIGN_RIGHT); - else + } + else { LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " - " defined as \"" - << str << "\""; + "\"alignment\" for element \"" + << element.substr(9) << "\" defined as \"" << alignment << "\""; + } } if (elem->has("horizontalMargin")) { mHorizontalMargin = @@ -561,7 +570,7 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, } if (properties & LETTER_CASE && elem->has("letterCase")) { - const std::string letterCase {elem->get("letterCase")}; + const std::string& letterCase {elem->get("letterCase")}; if (letterCase == "uppercase") { mLetterCase = LetterCase::UPPERCASE; } @@ -579,7 +588,7 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, } if (properties & LETTER_CASE && elem->has("letterCaseCollections")) { - const std::string letterCase {elem->get("letterCaseCollections")}; + const std::string& letterCase {elem->get("letterCaseCollections")}; if (letterCase == "uppercase") { mLetterCaseCollections = LetterCase::UPPERCASE; } @@ -597,7 +606,7 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, } if (properties & LETTER_CASE && elem->has("letterCaseGroupedCollections")) { - const std::string letterCase {elem->get("letterCaseGroupedCollections")}; + const std::string& letterCase {elem->get("letterCaseGroupedCollections")}; if (letterCase == "uppercase") { mLetterCaseGroupedCollections = LetterCase::UPPERCASE; } @@ -636,33 +645,34 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("indicators")) { - std::string indicators {elem->get("indicators")}; + const std::string& indicators {elem->get("indicators")}; if (indicators == "symbols" || indicators == "ascii" || indicators == "none") { mIndicators = indicators; } else { mIndicators = "symbols"; LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " - " defined as \"" - << indicators << "\""; + "\"indicators\" for element \"" + << element.substr(9) << "\" defined as \"" << indicators << "\""; } } if (elem->has("collectionIndicators")) { - std::string collectionIndicators {elem->get("collectionIndicators")}; + const std::string& collectionIndicators {elem->get("collectionIndicators")}; if (collectionIndicators == "symbols" || collectionIndicators == "ascii") { mCollectionIndicators = collectionIndicators; } else { mCollectionIndicators = "symbols"; LOG(LogWarning) << "TextListComponent: Invalid theme configuration, property " - " defined as \"" - << collectionIndicators << "\""; + "\"collectionIndicators\" for element \"" + << element.substr(9) << "\" defined as \"" << collectionIndicators + << "\""; } } if (elem->has("selectorImagePath")) { - std::string path {elem->get("selectorImagePath")}; + const std::string& path {elem->get("selectorImagePath")}; bool tile {elem->has("selectorImageTile") && elem->get("selectorImageTile")}; mSelectorImage.setImage(path, tile); mSelectorImage.setSize(mSize.x, mSelectorHeight);