Added a 'selectedBackgroundCornerRadius' property to the textlist element

This commit is contained in:
Leon Styhre 2024-06-03 17:34:07 +02:00
parent c8c601bcc9
commit 5dd7a371fe
2 changed files with 28 additions and 3 deletions

View file

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

View file

@ -138,6 +138,7 @@ private:
unsigned int mSelectedBackgroundColor;
unsigned int mSelectedSecondaryBackgroundColor;
glm::vec2 mSelectedBackgroundMargins;
float mSelectedBackgroundCornerRadius;
bool mHorizontalScrolling;
float mHorizontalScrollSpeed;
float mHorizontalScrollDelay;
@ -178,6 +179,7 @@ TextListComponent<T>::TextListComponent()
, mSelectedBackgroundColor {0x00000000}
, mSelectedSecondaryBackgroundColor {0x00000000}
, mSelectedBackgroundMargins {0.0f, 0.0f}
, mSelectedBackgroundCornerRadius {0.0f}
, mHorizontalScrolling {true}
, mHorizontalScrollSpeed {1.0f}
, mHorizontalScrollDelay {3000.0f}
@ -420,11 +422,27 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
mRenderer->setMatrix(drawTrans);
if (i == mCursor && backgroundColor != 0x00000000) {
mRenderer->drawRect(mSelectorHorizontalOffset + -mSelectedBackgroundMargins.x,
mSelectorVerticalOffset,
if (mSelectorHorizontalOffset != 0.0f || mSelectedBackgroundMargins.x != 0.0f) {
drawTrans = glm::translate(
drawTrans, glm::vec3 {mSelectorHorizontalOffset - mSelectedBackgroundMargins.x,
0.0f, 0.0f});
mRenderer->setMatrix(drawTrans);
}
mRenderer->drawRect(0.0f, mSelectorVerticalOffset,
entry.data.entryName->getSize().x + mSelectedBackgroundMargins.x +
mSelectedBackgroundMargins.y,
mSelectorHeight, backgroundColor, backgroundColor);
mSelectorHeight, backgroundColor, backgroundColor, false, 1.0f,
1.0f, Renderer::BlendFactor::SRC_ALPHA,
Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA,
mSelectedBackgroundCornerRadius);
if (mSelectorHorizontalOffset != 0.0f || mSelectedBackgroundMargins.x != 0.0f) {
drawTrans = glm::translate(
drawTrans, glm::vec3 {-mSelectorHorizontalOffset + mSelectedBackgroundMargins.x,
0.0f, 0.0f});
mRenderer->setMatrix(drawTrans);
}
}
entry.data.entryName->render(drawTrans);
@ -506,6 +524,12 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
mSelectedBackgroundMargins = selectedBackgroundMargins * Renderer::getScreenWidth();
}
if (elem->has("selectedBackgroundCornerRadius")) {
mSelectedBackgroundCornerRadius =
glm::clamp(elem->get<float>("selectedBackgroundCornerRadius"), 0.0f, 0.5f) *
mRenderer->getScreenWidth();
}
if (elem->has("textHorizontalScrolling"))
mHorizontalScrolling = elem->get<bool>("textHorizontalScrolling");