From 31c5b200d192250d18f4759b7c1cc4b08fb767e1 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 13 Feb 2022 15:01:55 +0100 Subject: [PATCH] Added support for using unsigned integers for theme properties. --- es-core/src/ThemeData.cpp | 13 +++++++++---- es-core/src/ThemeData.h | 1 + es-core/src/components/BadgeComponent.cpp | 12 ++++++------ es-core/src/components/CarouselComponent.cpp | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 55c6f7f94..2ead841c9 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -88,8 +88,8 @@ std::map> {"rotationOrigin", NORMALIZED_PAIR}, {"path", PATH}, {"default", PATH}, - {"tile", BOOLEAN}, {"imageType", STRING}, + {"tile", BOOLEAN}, {"interpolation", STRING}, {"color", COLOR}, {"colorEnd", COLOR}, @@ -141,8 +141,8 @@ std::map> {"horizontalAlignment", STRING}, {"alignment", STRING}, // For backward compatibility with legacy themes. {"direction", STRING}, - {"lines", FLOAT}, - {"itemsPerLine", FLOAT}, + {"lines", UNSIGNED_INTEGER}, + {"itemsPerLine", UNSIGNED_INTEGER}, {"itemMargin", NORMALIZED_PAIR}, {"slots", STRING}, {"controllerPos", NORMALIZED_PAIR}, @@ -245,7 +245,7 @@ std::map> {"logoHorizontalAlignment", STRING}, {"logoVerticalAlignment", STRING}, {"logoAlignment", STRING}, // For backward compatibility with legacy themes. - {"maxLogoCount", FLOAT}, + {"maxLogoCount", UNSIGNED_INTEGER}, {"text", STRING}, {"textColor", COLOR}, {"textBackgroundColor", COLOR}, @@ -1208,6 +1208,11 @@ void ThemeData::parseElement(const pugi::xml_node& root, } break; } + case UNSIGNED_INTEGER: { + unsigned int integerVal {static_cast(strtoul(str.c_str(), 0, 0))}; + element.properties[node.name()] = integerVal; + break; + } case FLOAT: { float floatVal {static_cast(strtod(str.c_str(), 0))}; element.properties[node.name()] = floatVal; diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index 911cf23c7..75a658e9f 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -217,6 +217,7 @@ public: PATH, STRING, COLOR, + UNSIGNED_INTEGER, FLOAT, BOOLEAN }; diff --git a/es-core/src/components/BadgeComponent.cpp b/es-core/src/components/BadgeComponent.cpp index 989133f67..54ded9daf 100644 --- a/es-core/src/components/BadgeComponent.cpp +++ b/es-core/src/components/BadgeComponent.cpp @@ -229,25 +229,25 @@ void BadgeComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("lines")) { - const float lines {elem->get("lines")}; - if (lines < 1.0f || lines > 10.0f) { + const unsigned int lines {elem->get("lines")}; + if (lines < 1 || lines > 10) { LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, set to \"" << lines << "\""; } else { - mFlexboxComponent.setLines(static_cast(lines)); + mFlexboxComponent.setLines(lines); } } if (elem->has("itemsPerLine")) { - const float itemsPerLine {elem->get("itemsPerLine")}; - if (itemsPerLine < 1.0f || itemsPerLine > 10.0f) { + const unsigned int itemsPerLine {elem->get("itemsPerLine")}; + if (itemsPerLine < 1 || itemsPerLine > 10) { LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, set to \"" << itemsPerLine << "\""; } else { - mFlexboxComponent.setItemsPerLine(static_cast(itemsPerLine)); + mFlexboxComponent.setItemsPerLine(itemsPerLine); } } diff --git a/es-core/src/components/CarouselComponent.cpp b/es-core/src/components/CarouselComponent.cpp index c651799fb..a1ff64b0f 100644 --- a/es-core/src/components/CarouselComponent.cpp +++ b/es-core/src/components/CarouselComponent.cpp @@ -379,7 +379,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("maxLogoCount")) mMaxLogoCount = - glm::clamp(static_cast(std::round(elem->get("maxLogoCount"))), 2, 30); + glm::clamp(static_cast(elem->get("maxLogoCount")), 2, 30); if (elem->has("logoRotation")) mLogoRotation = elem->get("logoRotation");