diff --git a/es-core/src/components/primary/GridComponent.h b/es-core/src/components/primary/GridComponent.h index d2c4ff3a9..9c4fcac40 100644 --- a/es-core/src/components/primary/GridComponent.h +++ b/es-core/src/components/primary/GridComponent.h @@ -110,6 +110,12 @@ private: BOTTOM }; + enum class ItemFit { + CONTAIN, + FILL, + COVER + }; + Renderer* mRenderer; std::function mCancelTransitionsCallback; std::function mCursorChangedCallback; @@ -144,6 +150,7 @@ private: glm::vec2 mItemSize; float mItemScale; float mItemRelativeScale; + ItemFit mItemFit; glm::vec2 mItemSpacing; unsigned int mItemColor; unsigned int mItemColorEnd; @@ -195,6 +202,7 @@ GridComponent::GridComponent() mRenderer->getScreenHeight() * 0.25f}} , mItemScale {1.05f} , mItemRelativeScale {1.0f} + , mItemFit {ItemFit::CONTAIN} , mItemSpacing {0.0f, 0.0f} , mItemColor {0xFFFFFFFF} , mItemColorEnd {0xFFFFFFFF} @@ -225,7 +233,12 @@ void GridComponent::addEntry(Entry& entry, const std::shared_ptr& auto item = std::make_shared(false, dynamic); item->setLinearInterpolation(true); item->setMipmapping(true); - item->setMaxSize(mItemSize * mItemRelativeScale); + if (mItemFit == ItemFit::CONTAIN) + item->setMaxSize(mItemSize * mItemRelativeScale); + else if (mItemFit == ItemFit::FILL) + item->setResize(mItemSize * mItemRelativeScale); + else if (mItemFit == ItemFit::COVER) + item->setCroppedSize(mItemSize * mItemRelativeScale); item->setImage(entry.data.itemPath); item->applyTheme(theme, "system", "", ThemeFlags::ALL); if (mItemColor != 0xFFFFFFFF) @@ -244,7 +257,12 @@ void GridComponent::addEntry(Entry& entry, const std::shared_ptr& auto defaultItem = std::make_shared(false, dynamic); defaultItem->setLinearInterpolation(true); defaultItem->setMipmapping(true); - defaultItem->setMaxSize(mItemSize * mItemRelativeScale); + if (mItemFit == ItemFit::CONTAIN) + defaultItem->setMaxSize(mItemSize * mItemRelativeScale); + else if (mItemFit == ItemFit::FILL) + defaultItem->setResize(mItemSize * mItemRelativeScale); + else if (mItemFit == ItemFit::COVER) + defaultItem->setCroppedSize(mItemSize * mItemRelativeScale); defaultItem->setImage(entry.data.defaultItemPath); defaultItem->applyTheme(theme, "system", "", ThemeFlags::ALL); if (mItemColor != 0xFFFFFFFF) @@ -286,7 +304,12 @@ void GridComponent::updateEntry(Entry& entry, const std::shared_ptr(false, true); item->setLinearInterpolation(true); item->setMipmapping(true); - item->setMaxSize(mItemSize * mItemRelativeScale); + if (mItemFit == ItemFit::CONTAIN) + item->setMaxSize(mItemSize * mItemRelativeScale); + else if (mItemFit == ItemFit::FILL) + item->setResize(mItemSize * mItemRelativeScale); + else if (mItemFit == ItemFit::COVER) + item->setCroppedSize(mItemSize * mItemRelativeScale); item->setImage(entry.data.itemPath); item->applyTheme(theme, "system", "", ThemeFlags::ALL); if (mItemColor != 0xFFFFFFFF) @@ -745,6 +768,25 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("itemRelativeScale")) mItemRelativeScale = glm::clamp(elem->get("itemRelativeScale"), 0.2f, 1.0f); + if (elem->has("itemFit")) { + const std::string& itemFit {elem->get("itemFit")}; + if (itemFit == "contain") { + mItemFit = ItemFit::CONTAIN; + } + else if (itemFit == "fill") { + mItemFit = ItemFit::FILL; + } + else if (itemFit == "cover") { + mItemFit = ItemFit::COVER; + } + else { + mItemFit = ItemFit::CONTAIN; + LOG(LogWarning) << "GridComponent: Invalid theme configuration, property " + "\"itemFit\" for element \"" + << element.substr(5) << "\" defined as \"" << itemFit << "\""; + } + } + if (elem->has("backgroundRelativeScale")) mBackgroundRelativeScale = glm::clamp(elem->get("backgroundRelativeScale"), 0.2f, 1.0f);