Added itemSaturation properties to CarouselComponent and GridComponent.

This commit is contained in:
Leon Styhre 2022-12-13 21:35:21 +01:00
parent 16aacd5953
commit c260c929b5
3 changed files with 24 additions and 0 deletions

View file

@ -133,6 +133,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"imageColor", COLOR},
{"imageColorEnd", COLOR},
{"imageGradientType", STRING},
{"imageSaturation", FLOAT},
{"itemTransitions", STRING},
{"itemHorizontalAlignment", STRING},
{"itemVerticalAlignment", STRING},
@ -184,6 +185,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"imageColor", COLOR},
{"imageColorEnd", COLOR},
{"imageGradientType", STRING},
{"imageSaturation", FLOAT},
{"backgroundImage", PATH},
{"backgroundRelativeScale", FLOAT},
{"backgroundColor", COLOR},

View file

@ -147,6 +147,7 @@ private:
unsigned int mImageColorShift;
unsigned int mImageColorShiftEnd;
bool mImageColorGradientHorizontal;
float mImageSaturation;
bool mInstantItemTransitions;
Alignment mItemHorizontalAlignment;
Alignment mItemVerticalAlignment;
@ -199,6 +200,7 @@ CarouselComponent<T>::CarouselComponent()
, mImageColorShift {0xFFFFFFFF}
, mImageColorShiftEnd {0xFFFFFFFF}
, mImageColorGradientHorizontal {true}
, mImageSaturation {1.0f}
, mInstantItemTransitions {false}
, mItemHorizontalAlignment {ALIGN_CENTER}
, mItemVerticalAlignment {ALIGN_CENTER}
@ -263,6 +265,8 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
item->setImage(entry.data.imagePath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageSaturation != 1.0)
item->setSaturation(mImageSaturation);
if (mImageColorShift != 0xFFFFFFFF)
item->setColorShift(mImageColorShift);
if (mImageColorShiftEnd != mImageColorShift)
@ -281,6 +285,8 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
defaultImage->setImage(entry.data.defaultImagePath);
defaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageSaturation != 1.0)
defaultImage->setSaturation(mImageSaturation);
if (mImageColorShift != 0xFFFFFFFF)
defaultImage->setColorShift(mImageColorShift);
if (mImageColorShiftEnd != mImageColorShift)
@ -348,6 +354,8 @@ void CarouselComponent<T>::updateEntry(Entry& entry, const std::shared_ptr<Theme
item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
item->setImage(entry.data.imagePath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageSaturation != 1.0)
item->setSaturation(mImageSaturation);
if (mImageColorShift != 0xFFFFFFFF)
item->setColorShift(mImageColorShift);
if (mImageColorShiftEnd != mImageColorShift)
@ -1116,6 +1124,9 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("imageSaturation"))
mImageSaturation = glm::clamp(elem->get<float>("imageSaturation"), 0.0f, 1.0f);
if (elem->has("imageInterpolation")) {
const std::string& imageInterpolation {elem->get<std::string>("imageInterpolation")};
if (imageInterpolation == "linear") {

View file

@ -148,6 +148,7 @@ private:
unsigned int mImageColor;
unsigned int mImageColorEnd;
bool mImageColorGradientHorizontal;
float mImageSaturation;
std::unique_ptr<ImageComponent> mBackgroundImage;
std::string mBackgroundImagePath;
float mBackgroundRelativeScale;
@ -204,6 +205,7 @@ GridComponent<T>::GridComponent()
, mImageColor {0xFFFFFFFF}
, mImageColorEnd {0xFFFFFFFF}
, mImageColorGradientHorizontal {true}
, mImageSaturation {1.0f}
, mBackgroundRelativeScale {1.0f}
, mBackgroundColor {0xFFFFFFFF}
, mBackgroundColorEnd {0xFFFFFFFF}
@ -256,6 +258,8 @@ void GridComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeData>&
item->setCroppedSize(mItemSize * mImageRelativeScale);
item->setImage(entry.data.imagePath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageSaturation != 1.0)
item->setSaturation(mImageSaturation);
if (mImageColor != 0xFFFFFFFF)
item->setColorShift(mImageColor);
if (mImageColorEnd != mImageColor) {
@ -280,6 +284,8 @@ void GridComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeData>&
defaultImage->setCroppedSize(mItemSize * mImageRelativeScale);
defaultImage->setImage(entry.data.defaultImagePath);
defaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageSaturation != 1.0)
defaultImage->setSaturation(mImageSaturation);
if (mImageColor != 0xFFFFFFFF)
defaultImage->setColorShift(mImageColor);
if (mImageColorEnd != mImageColor) {
@ -329,6 +335,8 @@ void GridComponent<T>::updateEntry(Entry& entry, const std::shared_ptr<ThemeData
item->setCroppedSize(mItemSize * mImageRelativeScale);
item->setImage(entry.data.imagePath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageSaturation != 1.0)
item->setSaturation(mImageSaturation);
if (mImageColor != 0xFFFFFFFF)
item->setColorShift(mImageColor);
if (mImageColorEnd != mImageColor) {
@ -1019,6 +1027,9 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("imageSaturation"))
mImageSaturation = glm::clamp(elem->get<float>("imageSaturation"), 0.0f, 1.0f);
if (elem->has("unfocusedItemOpacity"))
mUnfocusedItemOpacity = glm::clamp(elem->get<float>("unfocusedItemOpacity"), 0.1f, 1.0f);