Added a 'selectorWidth' property to the textlist element

This commit is contained in:
Leon Styhre 2024-01-27 14:50:32 +01:00
parent 6dff5ac75c
commit 99c80e389a
2 changed files with 17 additions and 8 deletions

View file

@ -249,6 +249,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{{"pos", NORMALIZED_PAIR}, {{"pos", NORMALIZED_PAIR},
{"size", NORMALIZED_PAIR}, {"size", NORMALIZED_PAIR},
{"origin", NORMALIZED_PAIR}, {"origin", NORMALIZED_PAIR},
{"selectorWidth", FLOAT},
{"selectorHeight", FLOAT}, {"selectorHeight", FLOAT},
{"selectorHorizontalOffset", FLOAT}, {"selectorHorizontalOffset", FLOAT},
{"selectorVerticalOffset", FLOAT}, {"selectorVerticalOffset", FLOAT},

View file

@ -123,6 +123,7 @@ private:
bool mGamelistView; bool mGamelistView;
std::shared_ptr<Font> mFont; std::shared_ptr<Font> mFont;
float mSelectorWidth;
float mSelectorHeight; float mSelectorHeight;
float mSelectorHorizontalOffset; float mSelectorHorizontalOffset;
float mSelectorVerticalOffset; float mSelectorVerticalOffset;
@ -162,6 +163,7 @@ TextListComponent<T>::TextListComponent()
, mPreviousScrollVelocity {0} , mPreviousScrollVelocity {0}
, mGamelistView {std::is_same_v<T, FileData*> ? true : false} , mGamelistView {std::is_same_v<T, FileData*> ? true : false}
, mFont {Font::get(FONT_SIZE_MEDIUM_FIXED)} , mFont {Font::get(FONT_SIZE_MEDIUM_FIXED)}
, mSelectorWidth {mSize.x}
, mSelectorHeight {mFont->getSize() * 1.5f} , mSelectorHeight {mFont->getSize() * 1.5f}
, mSelectorHorizontalOffset {0.0f} , mSelectorHorizontalOffset {0.0f}
, mSelectorVerticalOffset {0.0f} , mSelectorVerticalOffset {0.0f}
@ -330,7 +332,7 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
mRenderer->setMatrix(trans); mRenderer->setMatrix(trans);
mRenderer->drawRect(mSelectorHorizontalOffset, mRenderer->drawRect(mSelectorHorizontalOffset,
(mCursor - startEntry) * entrySize + mSelectorVerticalOffset, (mCursor - startEntry) * entrySize + mSelectorVerticalOffset,
mSize.x, mSelectorHeight, mSelectorColor, mSelectorColorEnd, mSelectorWidth, mSelectorHeight, mSelectorColor, mSelectorColorEnd,
mSelectorColorGradientHorizontal); mSelectorColorGradientHorizontal);
} }
} }
@ -670,12 +672,23 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
} }
mSize.x = glm::clamp(mSize.x, mRenderer->getScreenWidth() * 0.05f,
mRenderer->getScreenWidth() * 1.0f);
mSize.y = glm::clamp(mSize.y, mRenderer->getScreenHeight() * 0.05f,
mRenderer->getScreenHeight() * 1.0f);
if (elem->has("selectorWidth"))
mSelectorWidth =
glm::clamp(elem->get<float>("selectorWidth"), 0.0f, 1.0f) * Renderer::getScreenWidth();
else
mSelectorWidth = mSize.x;
if (elem->has("selectorImagePath")) { if (elem->has("selectorImagePath")) {
const std::string& path {elem->get<std::string>("selectorImagePath")}; const std::string& path {elem->get<std::string>("selectorImagePath")};
bool tile {elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile")}; bool tile {elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile")};
mSelectorImage.setImage(path, tile); mSelectorImage.setImage(path, tile);
mSelectorImage.setSize(mSize.x, mSelectorHeight); mSelectorImage.setSize(mSelectorWidth, mSelectorHeight);
mSelectorImage.setResize(mSize.x, mSelectorHeight); mSelectorImage.setResize(mSelectorWidth, mSelectorHeight);
mSelectorImage.setColorShift(mSelectorColor); mSelectorImage.setColorShift(mSelectorColor);
mSelectorImage.setColorShiftEnd(mSelectorColorEnd); mSelectorImage.setColorShiftEnd(mSelectorColorEnd);
} }
@ -685,11 +698,6 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("fadeAbovePrimary")) if (elem->has("fadeAbovePrimary"))
mFadeAbovePrimary = elem->get<bool>("fadeAbovePrimary"); mFadeAbovePrimary = elem->get<bool>("fadeAbovePrimary");
mSize.x = glm::clamp(mSize.x, mRenderer->getScreenWidth() * 0.05f,
mRenderer->getScreenWidth() * 1.0f);
mSize.y = glm::clamp(mSize.y, mRenderer->getScreenHeight() * 0.05f,
mRenderer->getScreenHeight() * 1.0f);
} }
template <typename T> void TextListComponent<T>::onCursorChanged(const CursorState& state) template <typename T> void TextListComponent<T>::onCursorChanged(const CursorState& state)