mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +00:00
Added an itemFit property to GridComponent.
This commit is contained in:
parent
c6981084e0
commit
c394e4ae8d
|
@ -110,6 +110,12 @@ private:
|
||||||
BOTTOM
|
BOTTOM
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ItemFit {
|
||||||
|
CONTAIN,
|
||||||
|
FILL,
|
||||||
|
COVER
|
||||||
|
};
|
||||||
|
|
||||||
Renderer* mRenderer;
|
Renderer* mRenderer;
|
||||||
std::function<void()> mCancelTransitionsCallback;
|
std::function<void()> mCancelTransitionsCallback;
|
||||||
std::function<void(CursorState state)> mCursorChangedCallback;
|
std::function<void(CursorState state)> mCursorChangedCallback;
|
||||||
|
@ -144,6 +150,7 @@ private:
|
||||||
glm::vec2 mItemSize;
|
glm::vec2 mItemSize;
|
||||||
float mItemScale;
|
float mItemScale;
|
||||||
float mItemRelativeScale;
|
float mItemRelativeScale;
|
||||||
|
ItemFit mItemFit;
|
||||||
glm::vec2 mItemSpacing;
|
glm::vec2 mItemSpacing;
|
||||||
unsigned int mItemColor;
|
unsigned int mItemColor;
|
||||||
unsigned int mItemColorEnd;
|
unsigned int mItemColorEnd;
|
||||||
|
@ -195,6 +202,7 @@ GridComponent<T>::GridComponent()
|
||||||
mRenderer->getScreenHeight() * 0.25f}}
|
mRenderer->getScreenHeight() * 0.25f}}
|
||||||
, mItemScale {1.05f}
|
, mItemScale {1.05f}
|
||||||
, mItemRelativeScale {1.0f}
|
, mItemRelativeScale {1.0f}
|
||||||
|
, mItemFit {ItemFit::CONTAIN}
|
||||||
, mItemSpacing {0.0f, 0.0f}
|
, mItemSpacing {0.0f, 0.0f}
|
||||||
, mItemColor {0xFFFFFFFF}
|
, mItemColor {0xFFFFFFFF}
|
||||||
, mItemColorEnd {0xFFFFFFFF}
|
, mItemColorEnd {0xFFFFFFFF}
|
||||||
|
@ -225,7 +233,12 @@ void GridComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeData>&
|
||||||
auto item = std::make_shared<ImageComponent>(false, dynamic);
|
auto item = std::make_shared<ImageComponent>(false, dynamic);
|
||||||
item->setLinearInterpolation(true);
|
item->setLinearInterpolation(true);
|
||||||
item->setMipmapping(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->setImage(entry.data.itemPath);
|
||||||
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
|
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
|
||||||
if (mItemColor != 0xFFFFFFFF)
|
if (mItemColor != 0xFFFFFFFF)
|
||||||
|
@ -244,7 +257,12 @@ void GridComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeData>&
|
||||||
auto defaultItem = std::make_shared<ImageComponent>(false, dynamic);
|
auto defaultItem = std::make_shared<ImageComponent>(false, dynamic);
|
||||||
defaultItem->setLinearInterpolation(true);
|
defaultItem->setLinearInterpolation(true);
|
||||||
defaultItem->setMipmapping(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->setImage(entry.data.defaultItemPath);
|
||||||
defaultItem->applyTheme(theme, "system", "", ThemeFlags::ALL);
|
defaultItem->applyTheme(theme, "system", "", ThemeFlags::ALL);
|
||||||
if (mItemColor != 0xFFFFFFFF)
|
if (mItemColor != 0xFFFFFFFF)
|
||||||
|
@ -286,7 +304,12 @@ void GridComponent<T>::updateEntry(Entry& entry, const std::shared_ptr<ThemeData
|
||||||
auto item = std::make_shared<ImageComponent>(false, true);
|
auto item = std::make_shared<ImageComponent>(false, true);
|
||||||
item->setLinearInterpolation(true);
|
item->setLinearInterpolation(true);
|
||||||
item->setMipmapping(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->setImage(entry.data.itemPath);
|
||||||
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
|
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
|
||||||
if (mItemColor != 0xFFFFFFFF)
|
if (mItemColor != 0xFFFFFFFF)
|
||||||
|
@ -745,6 +768,25 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
||||||
if (elem->has("itemRelativeScale"))
|
if (elem->has("itemRelativeScale"))
|
||||||
mItemRelativeScale = glm::clamp(elem->get<float>("itemRelativeScale"), 0.2f, 1.0f);
|
mItemRelativeScale = glm::clamp(elem->get<float>("itemRelativeScale"), 0.2f, 1.0f);
|
||||||
|
|
||||||
|
if (elem->has("itemFit")) {
|
||||||
|
const std::string& itemFit {elem->get<std::string>("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"))
|
if (elem->has("backgroundRelativeScale"))
|
||||||
mBackgroundRelativeScale =
|
mBackgroundRelativeScale =
|
||||||
glm::clamp(elem->get<float>("backgroundRelativeScale"), 0.2f, 1.0f);
|
glm::clamp(elem->get<float>("backgroundRelativeScale"), 0.2f, 1.0f);
|
||||||
|
|
Loading…
Reference in a new issue