Added a 'textBackgroundCornerRadius' property to the grid element

Also made the 'backgroundCornerRadius' and 'selectorCornerRadius' properties apply to colored rectangles
This commit is contained in:
Leon Styhre 2024-11-24 14:42:55 +01:00
parent 8c9d9d51fc
commit 487a842f36
2 changed files with 38 additions and 6 deletions

View file

@ -251,6 +251,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"selectorGradientType", STRING},
{"text", STRING},
{"textRelativeScale", FLOAT},
{"textBackgroundCornerRadius", FLOAT},
{"textColor", COLOR},
{"textBackgroundColor", COLOR},
{"textSelectedColor", COLOR},

View file

@ -177,6 +177,7 @@ private:
std::unique_ptr<ImageComponent> mBackgroundImage;
std::string mBackgroundImagePath;
float mBackgroundRelativeScale;
float mBackgroundCornerRadius;
unsigned int mBackgroundColor;
unsigned int mBackgroundColorEnd;
bool mBackgroundColorGradientHorizontal;
@ -185,11 +186,13 @@ private:
std::string mSelectorImagePath;
float mSelectorRelativeScale;
SelectorLayer mSelectorLayer;
float mSelectorCornerRadius;
unsigned int mSelectorColor;
unsigned int mSelectorColorEnd;
bool mSelectorColorGradientHorizontal;
bool mHasSelectorColor;
float mTextRelativeScale;
float mTextBackgroundCornerRadius;
unsigned int mTextColor;
unsigned int mTextBackgroundColor;
unsigned int mTextSelectedColor;
@ -254,17 +257,20 @@ GridComponent<T>::GridComponent()
, mImageBrightness {0.0f}
, mImageSaturation {1.0f}
, mBackgroundRelativeScale {1.0f}
, mBackgroundCornerRadius {0.0f}
, mBackgroundColor {0xFFFFFFFF}
, mBackgroundColorEnd {0xFFFFFFFF}
, mBackgroundColorGradientHorizontal {true}
, mHasBackgroundColor {false}
, mSelectorRelativeScale {1.0f}
, mSelectorLayer {SelectorLayer::TOP}
, mSelectorCornerRadius {0.0f}
, mSelectorColor {0xFFFFFFFF}
, mSelectorColorEnd {0xFFFFFFFF}
, mSelectorColorGradientHorizontal {true}
, mHasSelectorColor {false}
, mTextRelativeScale {1.0f}
, mTextBackgroundCornerRadius {0.0f}
, mTextColor {0x000000FF}
, mTextBackgroundColor {0xFFFFFF00}
, mTextSelectedColor {0x000000FF}
@ -385,6 +391,7 @@ void GridComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeData>&
0x00000000, mLineSpacing, 1.0f, mTextHorizontalScrolling, mTextHorizontalScrollSpeed,
mTextHorizontalScrollDelay, mTextHorizontalScrollGap);
text->setOrigin(0.5f, 0.5f);
text->setBackgroundCornerRadius(mTextBackgroundCornerRadius);
text->setColor(mTextColor);
text->setBackgroundColor(mTextBackgroundColor);
text->setRenderBackground(true);
@ -777,7 +784,9 @@ template <typename T> void GridComponent<T>::render(const glm::mat4& parentTrans
glm::translate(trans, glm::round(glm::vec3 {position.x, position.y, 0.0f}))};
mRenderer->setMatrix(drawTrans);
mRenderer->drawRect(0.0f, 0.0f, sizeX, sizeY, mSelectorColor, mSelectorColorEnd,
mSelectorColorGradientHorizontal, opacity);
mSelectorColorGradientHorizontal, opacity, 1.0f,
Renderer::BlendFactor::SRC_ALPHA,
Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA, mSelectorCornerRadius);
}
};
@ -887,9 +896,13 @@ template <typename T> void GridComponent<T>::render(const glm::mat4& parentTrans
// If a background color is set but no background image, then render a rectangle.
const float sizeX {mItemSize.x * scale * mBackgroundRelativeScale};
const float sizeY {mItemSize.y * scale * mBackgroundRelativeScale};
mRenderer->setMatrix(trans);
mRenderer->drawRect(backgroundPos.x, backgroundPos.y, sizeX, sizeY, mBackgroundColor,
mBackgroundColorEnd, mBackgroundColorGradientHorizontal, opacity);
const glm::mat4 drawTrans {glm::translate(
trans, glm::round(glm::vec3 {backgroundPos.x, backgroundPos.y, 0.0f}))};
mRenderer->setMatrix(drawTrans);
mRenderer->drawRect(
0.0f, 0.0f, sizeX, sizeY, mBackgroundColor, mBackgroundColorEnd,
mBackgroundColorGradientHorizontal, opacity, 1.0f, Renderer::BlendFactor::SRC_ALPHA,
Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA, mBackgroundCornerRadius);
}
if (cursorEntry && mSelectorLayer == SelectorLayer::MIDDLE)
@ -1162,10 +1175,11 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
float backgroundCornerRadius {0.0f};
if (elem->has("backgroundCornerRadius"))
if (elem->has("backgroundCornerRadius")) {
backgroundCornerRadius =
glm::clamp(elem->get<float>("backgroundCornerRadius"), 0.0f, 0.5f) *
(mItemScale >= 1.0f ? mItemScale : 1.0f) * mRenderer->getScreenWidth();
}
mBackgroundImage->setCornerRadius(backgroundCornerRadius);
mBackgroundImage->setImage(elem->get<std::string>("backgroundImage"));
mBackgroundImagePath = path;
@ -1176,6 +1190,11 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
<< element.substr(5) << "\", image does not exist: \"" << path << "\"";
}
}
else if (elem->has("backgroundCornerRadius")) {
mBackgroundCornerRadius =
glm::clamp(elem->get<float>("backgroundCornerRadius"), 0.0f, 0.5f) *
(mItemScale >= 1.0f ? mItemScale : 1.0f) * mRenderer->getScreenWidth();
}
if (elem->has("selectorImage")) {
const std::string& path {elem->get<std::string>("selectorImage")};
@ -1194,10 +1213,11 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
float selectorCornerRadius {0.0f};
if (elem->has("selectorCornerRadius"))
if (elem->has("selectorCornerRadius")) {
selectorCornerRadius =
glm::clamp(elem->get<float>("selectorCornerRadius"), 0.0f, 0.5f) *
(mItemScale >= 1.0f ? mItemScale : 1.0f) * mRenderer->getScreenWidth();
}
mSelectorImage->setCornerRadius(selectorCornerRadius);
mSelectorImage->setImage(elem->get<std::string>("selectorImage"));
mSelectorImagePath = path;
@ -1208,6 +1228,11 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
<< element.substr(5) << "\", image does not exist: \"" << path << "\"";
}
}
else if (elem->has("selectorCornerRadius")) {
mSelectorCornerRadius = glm::clamp(elem->get<float>("selectorCornerRadius"), 0.0f, 0.5f) *
(mItemScale >= 1.0f ? mItemScale : 1.0f) *
mRenderer->getScreenWidth();
}
if (elem->has("selectorLayer")) {
const std::string& selectorLayer {elem->get<std::string>("selectorLayer")};
@ -1367,6 +1392,12 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("textRelativeScale"))
mTextRelativeScale = glm::clamp(elem->get<float>("textRelativeScale"), 0.2f, 1.0f);
if (elem->has("textBackgroundCornerRadius")) {
mTextBackgroundCornerRadius =
glm::clamp(elem->get<float>("textBackgroundCornerRadius"), 0.0f, 0.5f) *
(mItemScale >= 1.0f ? mItemScale : 1.0f) * mRenderer->getScreenWidth();
}
if (elem->has("textColor"))
mTextColor = elem->get<unsigned int>("textColor");
if (elem->has("textBackgroundColor"))