Added carousel theme support for offsetting items to achieve a diagonal layout.

This commit is contained in:
Leon Styhre 2023-02-14 17:56:27 +01:00
parent 7b2dda0807
commit 7b47d2e4d6
2 changed files with 26 additions and 0 deletions

View file

@ -158,6 +158,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"imageBrightness", FLOAT}, {"imageBrightness", FLOAT},
{"imageSaturation", FLOAT}, {"imageSaturation", FLOAT},
{"itemTransitions", STRING}, {"itemTransitions", STRING},
{"itemDiagonalOffset", FLOAT},
{"itemHorizontalAlignment", STRING}, {"itemHorizontalAlignment", STRING},
{"itemVerticalAlignment", STRING}, {"itemVerticalAlignment", STRING},
{"wheelHorizontalAlignment", STRING}, {"wheelHorizontalAlignment", STRING},

View file

@ -167,6 +167,7 @@ private:
bool mHasImageSelectedColor; bool mHasImageSelectedColor;
float mImageBrightness; float mImageBrightness;
float mImageSaturation; float mImageSaturation;
float mItemDiagonalOffset;
bool mInstantItemTransitions; bool mInstantItemTransitions;
Alignment mItemHorizontalAlignment; Alignment mItemHorizontalAlignment;
Alignment mItemVerticalAlignment; Alignment mItemVerticalAlignment;
@ -233,6 +234,7 @@ CarouselComponent<T>::CarouselComponent()
, mHasImageSelectedColor {false} , mHasImageSelectedColor {false}
, mImageBrightness {0.0f} , mImageBrightness {0.0f}
, mImageSaturation {1.0f} , mImageSaturation {1.0f}
, mItemDiagonalOffset {0.0f}
, mInstantItemTransitions {false} , mInstantItemTransitions {false}
, mItemHorizontalAlignment {ALIGN_CENTER} , mItemHorizontalAlignment {ALIGN_CENTER}
, mItemVerticalAlignment {ALIGN_CENTER} , mItemVerticalAlignment {ALIGN_CENTER}
@ -1109,6 +1111,16 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
metadataOpacity = 0.7f; metadataOpacity = 0.7f;
} }
const glm::vec3 origPos {comp->getPosition()};
if (mItemDiagonalOffset != 0.0f) {
if (mType == CarouselType::HORIZONTAL)
comp->setPosition(
origPos.x, origPos.y - (mItemDiagonalOffset * renderItem.distance), origPos.z);
else
comp->setPosition(origPos.x - (mItemDiagonalOffset * renderItem.distance),
origPos.y, origPos.z);
}
comp->setScale(renderItem.scale); comp->setScale(renderItem.scale);
comp->setOpacity(renderItem.opacity * metadataOpacity); comp->setOpacity(renderItem.opacity * metadataOpacity);
if (renderItem.index == mCursor && (mHasImageSelectedColor || mHasTextSelectedColor)) { if (renderItem.index == mCursor && (mHasImageSelectedColor || mHasTextSelectedColor)) {
@ -1143,6 +1155,9 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
comp->render(renderItem.trans); comp->render(renderItem.trans);
} }
if (mItemDiagonalOffset != 0.0f)
comp->setPosition(origPos);
// TODO: Rewrite to use "real" reflections instead of this hack. // TODO: Rewrite to use "real" reflections instead of this hack.
// Don't attempt to add reflections for text entries. // Don't attempt to add reflections for text entries.
if (mReflections && (mEntries.at(renderItem.index).data.imagePath != "" || if (mReflections && (mEntries.at(renderItem.index).data.imagePath != "" ||
@ -1415,6 +1430,16 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("imageSaturation")) if (elem->has("imageSaturation"))
mImageSaturation = glm::clamp(elem->get<float>("imageSaturation"), 0.0f, 1.0f); mImageSaturation = glm::clamp(elem->get<float>("imageSaturation"), 0.0f, 1.0f);
if (elem->has("itemDiagonalOffset") &&
(mType == CarouselType::HORIZONTAL || mType == CarouselType::VERTICAL)) {
const float diagonalOffset {
glm::clamp(elem->get<float>("itemDiagonalOffset"), -0.5f, 0.5f)};
if (mType == CarouselType::HORIZONTAL)
mItemDiagonalOffset = diagonalOffset * Renderer::getScreenHeight();
else
mItemDiagonalOffset = diagonalOffset * Renderer::getScreenWidth();
}
if (elem->has("imageInterpolation")) { if (elem->has("imageInterpolation")) {
const std::string& imageInterpolation {elem->get<std::string>("imageInterpolation")}; const std::string& imageInterpolation {elem->get<std::string>("imageInterpolation")};
if (imageInterpolation == "linear") { if (imageInterpolation == "linear") {