Added support for using unsigned integers for theme properties.

This commit is contained in:
Leon Styhre 2022-02-13 15:01:55 +01:00
parent 0d799575ca
commit 31c5b200d1
4 changed files with 17 additions and 11 deletions

View file

@ -88,8 +88,8 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"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<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"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<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"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<unsigned int>(strtoul(str.c_str(), 0, 0))};
element.properties[node.name()] = integerVal;
break;
}
case FLOAT: {
float floatVal {static_cast<float>(strtod(str.c_str(), 0))};
element.properties[node.name()] = floatVal;

View file

@ -217,6 +217,7 @@ public:
PATH,
STRING,
COLOR,
UNSIGNED_INTEGER,
FLOAT,
BOOLEAN
};

View file

@ -229,25 +229,25 @@ void BadgeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (elem->has("lines")) {
const float lines {elem->get<float>("lines")};
if (lines < 1.0f || lines > 10.0f) {
const unsigned int lines {elem->get<unsigned int>("lines")};
if (lines < 1 || lines > 10) {
LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, <lines> set to \""
<< lines << "\"";
}
else {
mFlexboxComponent.setLines(static_cast<unsigned int>(lines));
mFlexboxComponent.setLines(lines);
}
}
if (elem->has("itemsPerLine")) {
const float itemsPerLine {elem->get<float>("itemsPerLine")};
if (itemsPerLine < 1.0f || itemsPerLine > 10.0f) {
const unsigned int itemsPerLine {elem->get<unsigned int>("itemsPerLine")};
if (itemsPerLine < 1 || itemsPerLine > 10) {
LOG(LogWarning)
<< "BadgeComponent: Invalid theme configuration, <itemsPerLine> set to \""
<< itemsPerLine << "\"";
}
else {
mFlexboxComponent.setItemsPerLine(static_cast<unsigned int>(itemsPerLine));
mFlexboxComponent.setItemsPerLine(itemsPerLine);
}
}

View file

@ -379,7 +379,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (elem->has("maxLogoCount"))
mMaxLogoCount =
glm::clamp(static_cast<int>(std::round(elem->get<float>("maxLogoCount"))), 2, 30);
glm::clamp(static_cast<int>(elem->get<unsigned int>("maxLogoCount")), 2, 30);
if (elem->has("logoRotation"))
mLogoRotation = elem->get<float>("logoRotation");