Added size restrictions to the 'size' and 'maxSize' theme properties for the image and video elements.

This commit is contained in:
Leon Styhre 2022-06-04 17:25:36 +02:00
parent 2ac706e0c5
commit 3ecb821c00
2 changed files with 38 additions and 10 deletions

View file

@ -501,12 +501,26 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
glm::vec2(Renderer::getScreenWidth(), Renderer::getScreenHeight())}; glm::vec2(Renderer::getScreenWidth(), Renderer::getScreenHeight())};
if (properties & ThemeFlags::SIZE) { if (properties & ThemeFlags::SIZE) {
if (elem->has("size")) if (elem->has("size")) {
setResize(elem->get<glm::vec2>("size") * scale); glm::vec2 imageSize {elem->get<glm::vec2>("size")};
else if (elem->has("maxSize")) if (imageSize == glm::vec2 {0.0f, 0.0f}) {
setMaxSize(elem->get<glm::vec2>("maxSize") * scale); LOG(LogWarning) << "ImageComponent: Invalid theme configuration, property <size> "
else if (elem->has("minSize")) "for element \""
setMinSize(elem->get<glm::vec2>("minSize") * scale); << element.substr(6) << "\" is set to zero";
imageSize = {0.001f, 0.001f};
}
if (imageSize.x > 0.0f)
imageSize.x = glm::clamp(imageSize.x, 0.001f, 2.0f);
if (imageSize.y > 0.0f)
imageSize.y = glm::clamp(imageSize.y, 0.001f, 2.0f);
setResize(imageSize * scale);
}
else if (elem->has("maxSize")) {
glm::vec2 imageMaxSize {elem->get<glm::vec2>("maxSize")};
imageMaxSize.x = glm::clamp(imageMaxSize.x, 0.001f, 2.0f);
imageMaxSize.y = glm::clamp(imageMaxSize.y, 0.001f, 2.0f);
setMaxSize(imageMaxSize * scale);
}
} }
if (elem->has("interpolation")) { if (elem->has("interpolation")) {

View file

@ -119,12 +119,26 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & ThemeFlags::SIZE) { if (properties & ThemeFlags::SIZE) {
if (elem->has("size")) { if (elem->has("size")) {
setResize(elem->get<glm::vec2>("size") * scale); glm::vec2 videoSize {elem->get<glm::vec2>("size")};
mVideoAreaSize = elem->get<glm::vec2>("size") * scale; if (videoSize == glm::vec2 {0.0f, 0.0f}) {
LOG(LogWarning) << "VideoComponent: Invalid theme configuration, property <size> "
"for element \""
<< element.substr(6) << "\" is set to zero";
videoSize = {0.01f, 0.01f};
}
if (videoSize.x > 0.0f)
videoSize.x = glm::clamp(videoSize.x, 0.01f, 2.0f);
if (videoSize.y > 0.0f)
videoSize.y = glm::clamp(videoSize.y, 0.01f, 2.0f);
setResize(videoSize * scale);
mVideoAreaSize = videoSize * scale;
} }
else if (elem->has("maxSize")) { else if (elem->has("maxSize")) {
setMaxSize(elem->get<glm::vec2>("maxSize") * scale); glm::vec2 videoMaxSize {elem->get<glm::vec2>("maxSize")};
mVideoAreaSize = elem->get<glm::vec2>("maxSize") * scale; videoMaxSize.x = glm::clamp(videoMaxSize.x, 0.01f, 2.0f);
videoMaxSize.y = glm::clamp(videoMaxSize.y, 0.01f, 2.0f);
setMaxSize(videoMaxSize * scale);
mVideoAreaSize = videoMaxSize * scale;
} }
} }