Added a 'selectedBackgroundMargins' property to the textlist element

This commit is contained in:
Leon Styhre 2024-06-02 22:36:52 +02:00
parent f1642393a4
commit 87dc77ceaa
2 changed files with 26 additions and 6 deletions

View file

@ -265,6 +265,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"selectedSecondaryColor", COLOR}, {"selectedSecondaryColor", COLOR},
{"selectedBackgroundColor", COLOR}, {"selectedBackgroundColor", COLOR},
{"selectedSecondaryBackgroundColor", COLOR}, {"selectedSecondaryBackgroundColor", COLOR},
{"selectedBackgroundMargins", NORMALIZED_PAIR},
{"textHorizontalScrolling", BOOLEAN}, {"textHorizontalScrolling", BOOLEAN},
{"textHorizontalScrollSpeed", FLOAT}, {"textHorizontalScrollSpeed", FLOAT},
{"textHorizontalScrollDelay", FLOAT}, {"textHorizontalScrollDelay", FLOAT},

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// ES-DE // ES-DE Frontend
// TextListComponent.h // TextListComponent.h
// //
// Text list, usable in both the system and gamelist views. // Text list, usable in both the system and gamelist views.
@ -137,6 +137,7 @@ private:
unsigned int mSelectedSecondaryColor; unsigned int mSelectedSecondaryColor;
unsigned int mSelectedBackgroundColor; unsigned int mSelectedBackgroundColor;
unsigned int mSelectedSecondaryBackgroundColor; unsigned int mSelectedSecondaryBackgroundColor;
glm::vec2 mSelectedBackgroundMargins;
bool mHorizontalScrolling; bool mHorizontalScrolling;
float mHorizontalScrollSpeed; float mHorizontalScrollSpeed;
float mHorizontalScrollDelay; float mHorizontalScrollDelay;
@ -176,6 +177,7 @@ TextListComponent<T>::TextListComponent()
, mSelectedSecondaryColor {0x00FF00FF} , mSelectedSecondaryColor {0x00FF00FF}
, mSelectedBackgroundColor {0x00000000} , mSelectedBackgroundColor {0x00000000}
, mSelectedSecondaryBackgroundColor {0x00000000} , mSelectedSecondaryBackgroundColor {0x00000000}
, mSelectedBackgroundMargins {0.0f, 0.0f}
, mHorizontalScrolling {true} , mHorizontalScrolling {true}
, mHorizontalScrollSpeed {1.0f} , mHorizontalScrollSpeed {1.0f}
, mHorizontalScrollDelay {3000.0f} , mHorizontalScrollDelay {3000.0f}
@ -349,10 +351,19 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x; dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x;
dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y; dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
float horizontalOffset {0.0f};
if (mAlignment == PrimaryAlignment::ALIGN_LEFT && mSelectorHorizontalOffset < 0.0f)
horizontalOffset = mSelectorHorizontalOffset;
else if (mAlignment == PrimaryAlignment::ALIGN_RIGHT && mSelectorHorizontalOffset > 0.0f)
horizontalOffset = mSelectorHorizontalOffset;
mRenderer->pushClipRect( mRenderer->pushClipRect(
glm::ivec2 {static_cast<int>(std::round(trans[3].x + mHorizontalMargin)), glm::ivec2 {static_cast<int>(std::round(trans[3].x + horizontalOffset + mHorizontalMargin +
-mSelectedBackgroundMargins.x)),
static_cast<int>(std::round(trans[3].y))}, static_cast<int>(std::round(trans[3].y))},
glm::ivec2 {static_cast<int>(std::round(dim.x - mHorizontalMargin * 2.0f)), glm::ivec2 {static_cast<int>(std::round((dim.x - mHorizontalMargin * 2.0f) +
mSelectedBackgroundMargins.x +
mSelectedBackgroundMargins.y)),
static_cast<int>(std::round(dim.y))}); static_cast<int>(std::round(dim.y))});
for (int i {startEntry}; i < listCutoff; ++i) { for (int i {startEntry}; i < listCutoff; ++i) {
@ -409,9 +420,11 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
mRenderer->setMatrix(drawTrans); mRenderer->setMatrix(drawTrans);
if (i == mCursor && backgroundColor != 0x00000000) { if (i == mCursor && backgroundColor != 0x00000000) {
mRenderer->drawRect(mSelectorHorizontalOffset, mSelectorVerticalOffset, mRenderer->drawRect(mSelectorHorizontalOffset + -mSelectedBackgroundMargins.x,
entry.data.entryName->getSize().x, mSelectorHeight, backgroundColor, mSelectorVerticalOffset,
backgroundColor); entry.data.entryName->getSize().x + mSelectedBackgroundMargins.x +
mSelectedBackgroundMargins.y,
mSelectorHeight, backgroundColor, backgroundColor);
} }
entry.data.entryName->render(drawTrans); entry.data.entryName->render(drawTrans);
@ -487,6 +500,12 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
mSelectedSecondaryBackgroundColor = mSelectedBackgroundColor; mSelectedSecondaryBackgroundColor = mSelectedBackgroundColor;
} }
if (elem->has("selectedBackgroundMargins")) {
const glm::vec2 selectedBackgroundMargins {
glm::clamp(elem->get<glm::vec2>("selectedBackgroundMargins"), 0.0f, 0.5f)};
mSelectedBackgroundMargins = selectedBackgroundMargins * Renderer::getScreenWidth();
}
if (elem->has("textHorizontalScrolling")) if (elem->has("textHorizontalScrolling"))
mHorizontalScrolling = elem->get<bool>("textHorizontalScrolling"); mHorizontalScrolling = elem->get<bool>("textHorizontalScrolling");