From f0e3addee6c6edae69a2a58612a309719a7ce61c Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 10 Dec 2022 14:31:04 +0100 Subject: [PATCH] Added support for setting one of the itemSize property axes to -1 to get square GridComponent items. --- es-core/src/components/primary/GridComponent.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/es-core/src/components/primary/GridComponent.h b/es-core/src/components/primary/GridComponent.h index 955965262..d2c4ff3a9 100644 --- a/es-core/src/components/primary/GridComponent.h +++ b/es-core/src/components/primary/GridComponent.h @@ -722,8 +722,21 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, mFractionalRows = (elem->has("fractionalRows") && elem->get("fractionalRows")); if (elem->has("itemSize")) { - const glm::vec2& itemSize {glm::clamp(elem->get("itemSize"), 0.05f, 1.0f)}; - mItemSize = itemSize * glm::vec2(Renderer::getScreenWidth(), Renderer::getScreenHeight()); + const glm::vec2& itemSize {elem->get("itemSize")}; + if (!(itemSize.x == -1 && itemSize.y == -1)) { + if (itemSize.x == -1) { + mItemSize.y = glm::clamp(itemSize.y, 0.05f, 1.0f) * mRenderer->getScreenHeight(); + mItemSize.x = mItemSize.y; + } + else if (itemSize.y == -1) { + mItemSize.x = glm::clamp(itemSize.x, 0.05f, 1.0f) * mRenderer->getScreenWidth(); + mItemSize.y = mItemSize.x; + } + else { + mItemSize = glm::clamp(itemSize, 0.05f, 1.0f) * + glm::vec2(mRenderer->getScreenWidth(), mRenderer->getScreenHeight()); + } + } } if (elem->has("itemScale"))