From 5dd7a371feff4b474d8331d32c04316bd77c519e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 3 Jun 2024 17:34:07 +0200 Subject: [PATCH] Added a 'selectedBackgroundCornerRadius' property to the textlist element --- es-core/src/ThemeData.cpp | 1 + .../components/primary/TextListComponent.h | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index b22a06178..3eb548d72 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -266,6 +266,7 @@ std::map> {"selectedBackgroundColor", COLOR}, {"selectedSecondaryBackgroundColor", COLOR}, {"selectedBackgroundMargins", NORMALIZED_PAIR}, + {"selectedBackgroundCornerRadius", FLOAT}, {"textHorizontalScrolling", BOOLEAN}, {"textHorizontalScrollSpeed", FLOAT}, {"textHorizontalScrollDelay", FLOAT}, diff --git a/es-core/src/components/primary/TextListComponent.h b/es-core/src/components/primary/TextListComponent.h index ef117a0c2..4be5d0a0f 100644 --- a/es-core/src/components/primary/TextListComponent.h +++ b/es-core/src/components/primary/TextListComponent.h @@ -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::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 void TextListComponent::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::applyTheme(const std::shared_ptr& theme, mSelectedBackgroundMargins = selectedBackgroundMargins * Renderer::getScreenWidth(); } + if (elem->has("selectedBackgroundCornerRadius")) { + mSelectedBackgroundCornerRadius = + glm::clamp(elem->get("selectedBackgroundCornerRadius"), 0.0f, 0.5f) * + mRenderer->getScreenWidth(); + } + if (elem->has("textHorizontalScrolling")) mHorizontalScrolling = elem->get("textHorizontalScrolling");