From 87dc77ceaa1c249d0d12514ace93f1144723b39f Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 2 Jun 2024 22:36:52 +0200 Subject: [PATCH] Added a 'selectedBackgroundMargins' property to the textlist element --- es-core/src/ThemeData.cpp | 1 + .../components/primary/TextListComponent.h | 31 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 63ec61972..ca8857c5d 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -265,6 +265,7 @@ std::map> {"selectedSecondaryColor", COLOR}, {"selectedBackgroundColor", COLOR}, {"selectedSecondaryBackgroundColor", COLOR}, + {"selectedBackgroundMargins", NORMALIZED_PAIR}, {"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 069b5663d..ef117a0c2 100644 --- a/es-core/src/components/primary/TextListComponent.h +++ b/es-core/src/components/primary/TextListComponent.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// ES-DE +// ES-DE Frontend // TextListComponent.h // // Text list, usable in both the system and gamelist views. @@ -137,6 +137,7 @@ private: unsigned int mSelectedSecondaryColor; unsigned int mSelectedBackgroundColor; unsigned int mSelectedSecondaryBackgroundColor; + glm::vec2 mSelectedBackgroundMargins; bool mHorizontalScrolling; float mHorizontalScrollSpeed; float mHorizontalScrollDelay; @@ -176,6 +177,7 @@ TextListComponent::TextListComponent() , mSelectedSecondaryColor {0x00FF00FF} , mSelectedBackgroundColor {0x00000000} , mSelectedSecondaryBackgroundColor {0x00000000} + , mSelectedBackgroundMargins {0.0f, 0.0f} , mHorizontalScrolling {true} , mHorizontalScrollSpeed {1.0f} , mHorizontalScrollDelay {3000.0f} @@ -349,10 +351,19 @@ template void TextListComponent::render(const glm::mat4& parentT 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; + 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( - glm::ivec2 {static_cast(std::round(trans[3].x + mHorizontalMargin)), + glm::ivec2 {static_cast(std::round(trans[3].x + horizontalOffset + mHorizontalMargin + + -mSelectedBackgroundMargins.x)), static_cast(std::round(trans[3].y))}, - glm::ivec2 {static_cast(std::round(dim.x - mHorizontalMargin * 2.0f)), + glm::ivec2 {static_cast(std::round((dim.x - mHorizontalMargin * 2.0f) + + mSelectedBackgroundMargins.x + + mSelectedBackgroundMargins.y)), static_cast(std::round(dim.y))}); for (int i {startEntry}; i < listCutoff; ++i) { @@ -409,9 +420,11 @@ template void TextListComponent::render(const glm::mat4& parentT mRenderer->setMatrix(drawTrans); if (i == mCursor && backgroundColor != 0x00000000) { - mRenderer->drawRect(mSelectorHorizontalOffset, mSelectorVerticalOffset, - entry.data.entryName->getSize().x, mSelectorHeight, backgroundColor, - backgroundColor); + mRenderer->drawRect(mSelectorHorizontalOffset + -mSelectedBackgroundMargins.x, + mSelectorVerticalOffset, + entry.data.entryName->getSize().x + mSelectedBackgroundMargins.x + + mSelectedBackgroundMargins.y, + mSelectorHeight, backgroundColor, backgroundColor); } entry.data.entryName->render(drawTrans); @@ -487,6 +500,12 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, mSelectedSecondaryBackgroundColor = mSelectedBackgroundColor; } + if (elem->has("selectedBackgroundMargins")) { + const glm::vec2 selectedBackgroundMargins { + glm::clamp(elem->get("selectedBackgroundMargins"), 0.0f, 0.5f)}; + mSelectedBackgroundMargins = selectedBackgroundMargins * Renderer::getScreenWidth(); + } + if (elem->has("textHorizontalScrolling")) mHorizontalScrolling = elem->get("textHorizontalScrolling");