Split the backgroundPadding property into backgroundHorizontalPadding and backgroundVerticalPadding properties for the helpsystem, systemstatus and clock elements

This commit is contained in:
Leon Styhre 2025-03-16 11:10:09 +01:00
parent 668d4626b5
commit 8feda8d372
7 changed files with 85 additions and 40 deletions

View file

@ -575,7 +575,8 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"backgroundColor", COLOR},
{"backgroundColorEnd", COLOR},
{"backgroundGradientType", STRING},
{"backgroundPadding", NORMALIZED_PAIR},
{"backgroundHorizontalPadding", NORMALIZED_PAIR},
{"backgroundVerticalPadding", NORMALIZED_PAIR},
{"backgroundCornerRadius", FLOAT},
{"opacity", FLOAT},
{"opacityDimmed", FLOAT},
@ -593,7 +594,8 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"backgroundColor", COLOR},
{"backgroundColorEnd", COLOR},
{"backgroundGradientType", STRING},
{"backgroundPadding", NORMALIZED_PAIR},
{"backgroundHorizontalPadding", NORMALIZED_PAIR},
{"backgroundVerticalPadding", NORMALIZED_PAIR},
{"backgroundCornerRadius", FLOAT},
{"entries", STRING},
{"entrySpacing", FLOAT},
@ -614,7 +616,8 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"backgroundColor", COLOR},
{"backgroundColorEnd", COLOR},
{"backgroundGradientType", STRING},
{"backgroundPadding", NORMALIZED_PAIR},
{"backgroundHorizontalPadding", NORMALIZED_PAIR},
{"backgroundVerticalPadding", NORMALIZED_PAIR},
{"backgroundCornerRadius", FLOAT},
{"format", STRING},
{"opacity", FLOAT}}},

View file

@ -20,7 +20,8 @@ DateTimeComponent::DateTimeComponent()
, mClockAccumulator {0}
, mClockMode {false}
, mDisplayRelative {false}
, mBackgroundPadding {0.0f, 0.0f}
, mBackgroundHorizontalPadding {0.0f, 0.0f}
, mBackgroundVerticalPadding {0.0f, 0.0f}
, mClockBgColor {0x00000000}
, mClockBgColorEnd {0x00000000}
, mClockColorGradientHorizontal {true}
@ -42,7 +43,8 @@ DateTimeComponent::DateTimeComponent(const std::string& text,
, mClockAccumulator {0}
, mClockMode {false}
, mDisplayRelative {false}
, mBackgroundPadding {0.0f, 0.0f}
, mBackgroundHorizontalPadding {0.0f, 0.0f}
, mBackgroundVerticalPadding {0.0f, 0.0f}
, mClockBgColor {0x00000000}
, mClockBgColorEnd {0x00000000}
, mClockColorGradientHorizontal {true}
@ -160,15 +162,16 @@ void DateTimeComponent::render(const glm::mat4& parentTrans)
if (mClockMode && mClockBgColor != 0x00000000) {
glm::mat4 trans {parentTrans * getTransform()};
trans = glm::translate(
trans, glm::vec3 {-mBackgroundPadding.x / 2.0f, -mBackgroundPadding.y / 2.0f, 0.0f});
trans = glm::translate(trans, glm::vec3 {-mBackgroundHorizontalPadding.x,
-mBackgroundVerticalPadding.x, 0.0f});
mRenderer->setMatrix(trans);
mRenderer->drawRect(0.0f, 0.0f, mSize.x + mBackgroundPadding.x,
mSize.y + mBackgroundPadding.y, mClockBgColor, mClockBgColorEnd,
mClockColorGradientHorizontal, mThemeOpacity, 1.0f,
Renderer::BlendFactor::SRC_ALPHA,
Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA, mBackgroundCornerRadius);
mRenderer->drawRect(
0.0f, 0.0f, mSize.x + mBackgroundHorizontalPadding.x + mBackgroundHorizontalPadding.y,
mSize.y + mBackgroundVerticalPadding.x + mBackgroundVerticalPadding.y, mClockBgColor,
mClockBgColorEnd, mClockColorGradientHorizontal, mThemeOpacity, 1.0f,
Renderer::BlendFactor::SRC_ALPHA, Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA,
mBackgroundCornerRadius);
}
// Render the component.
@ -288,11 +291,20 @@ void DateTimeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mRenderer->getScreenWidth());
}
if (mClockMode && elem->has("backgroundPadding")) {
const glm::vec2 backgroundPadding {
glm::clamp(elem->get<glm::vec2>("backgroundPadding"), 0.0f, 0.2f)};
mBackgroundPadding.x = backgroundPadding.x * mRenderer->getScreenWidth();
mBackgroundPadding.y = backgroundPadding.y * mRenderer->getScreenHeight();
if (mClockMode && elem->has("backgroundHorizontalPadding")) {
const glm::vec2 backgroundHorizontalPadding {
glm::clamp(elem->get<glm::vec2>("backgroundHorizontalPadding"), 0.0f, 0.2f)};
mBackgroundHorizontalPadding.x =
backgroundHorizontalPadding.x * mRenderer->getScreenWidth();
mBackgroundHorizontalPadding.y =
backgroundHorizontalPadding.y * mRenderer->getScreenWidth();
}
if (mClockMode && elem->has("backgroundVerticalPadding")) {
const glm::vec2 backgroundVerticalPadding {
glm::clamp(elem->get<glm::vec2>("backgroundVerticalPadding"), 0.0f, 0.2f)};
mBackgroundVerticalPadding.x = backgroundVerticalPadding.x * mRenderer->getScreenHeight();
mBackgroundVerticalPadding.y = backgroundVerticalPadding.y * mRenderer->getScreenHeight();
}
if (elem->has("backgroundCornerRadius")) {

View file

@ -56,7 +56,8 @@ private:
std::string mFormat;
bool mClockMode;
bool mDisplayRelative;
glm::vec2 mBackgroundPadding;
glm::vec2 mBackgroundHorizontalPadding;
glm::vec2 mBackgroundVerticalPadding;
unsigned int mClockBgColor;
unsigned int mClockBgColorEnd;
bool mClockColorGradientHorizontal;

View file

@ -33,7 +33,8 @@ HelpComponent::HelpComponent(std::shared_ptr<Font> font)
, mStyleIconColorDimmed {0x777777FF}
, mStyleBackgroundColor {0x00000000}
, mStyleBackgroundColorEnd {0x00000000}
, mStyleBackgroundPadding {0.0f, 0.0f}
, mStyleBackgroundHorizontalPadding {0.0f, 0.0f}
, mStyleBackgroundVerticalPadding {0.0f, 0.0f}
, mStyleBackgroundCornerRadius {0.0f}
, mStyleColorGradientHorizontal {true}
, mStyleEntryLayout {EntryLayout::ICON_FIRST}
@ -156,11 +157,22 @@ void HelpComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("backgroundPadding")) {
const glm::vec2 backgroundPadding {
glm::clamp(elem->get<glm::vec2>("backgroundPadding"), 0.0f, 0.2f)};
mStyleBackgroundPadding.x = backgroundPadding.x * mRenderer->getScreenWidth();
mStyleBackgroundPadding.y = backgroundPadding.y * mRenderer->getScreenHeight();
if (elem->has("backgroundHorizontalPadding")) {
const glm::vec2 backgroundHorizontalPadding {
glm::clamp(elem->get<glm::vec2>("backgroundHorizontalPadding"), 0.0f, 0.2f)};
mStyleBackgroundHorizontalPadding.x =
backgroundHorizontalPadding.x * mRenderer->getScreenWidth();
mStyleBackgroundHorizontalPadding.y =
backgroundHorizontalPadding.y * mRenderer->getScreenWidth();
}
if (elem->has("backgroundVerticalPadding")) {
const glm::vec2 backgroundVerticalPadding {
glm::clamp(elem->get<glm::vec2>("backgroundVerticalPadding"), 0.0f, 0.2f)};
mStyleBackgroundVerticalPadding.x =
backgroundVerticalPadding.x * mRenderer->getScreenHeight();
mStyleBackgroundVerticalPadding.y =
backgroundVerticalPadding.y * mRenderer->getScreenHeight();
}
if (elem->has("backgroundCornerRadius")) {
@ -395,16 +407,17 @@ void HelpComponent::render(const glm::mat4& parentTrans)
mRotationOrigin = mStyleRotationOrigin;
glm::mat4 trans {parentTrans * getTransform()};
trans = glm::translate(trans, glm::vec3 {-mStyleBackgroundPadding.x / 2.0f,
-mStyleBackgroundPadding.y / 2.0f, 0.0f});
trans = glm::translate(trans, glm::vec3 {-mStyleBackgroundHorizontalPadding.x,
-mStyleBackgroundVerticalPadding.x, 0.0f});
mRenderer->setMatrix(trans);
mRenderer->drawRect(
0.0f, 0.0f,
mSize.x + mStyleBackgroundPadding.x -
mSize.x + mStyleBackgroundHorizontalPadding.x + mStyleBackgroundHorizontalPadding.y -
(mStyleEntrySpacing * mRenderer->getScreenWidth()),
mSize.y + mStyleBackgroundPadding.y, mStyleBackgroundColor, mStyleBackgroundColorEnd,
mStyleColorGradientHorizontal, mThemeOpacity, 1.0f, Renderer::BlendFactor::SRC_ALPHA,
mSize.y + mStyleBackgroundVerticalPadding.x + mStyleBackgroundVerticalPadding.y,
mStyleBackgroundColor, mStyleBackgroundColorEnd, mStyleColorGradientHorizontal,
mThemeOpacity, 1.0f, Renderer::BlendFactor::SRC_ALPHA,
Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA, mStyleBackgroundCornerRadius);
mPosition = {0.0f, 0.0f, 0.0f};

View file

@ -87,7 +87,8 @@ private:
unsigned int mStyleIconColorDimmed;
unsigned int mStyleBackgroundColor;
unsigned int mStyleBackgroundColorEnd;
glm::vec2 mStyleBackgroundPadding;
glm::vec2 mStyleBackgroundHorizontalPadding;
glm::vec2 mStyleBackgroundVerticalPadding;
float mStyleBackgroundCornerRadius;
bool mStyleColorGradientHorizontal;
EntryLayout mStyleEntryLayout;

View file

@ -30,7 +30,8 @@ SystemStatusComponent::SystemStatusComponent()
, mBackgroundColorEnd {0x00000000}
, mAccumulator {0}
, mAccumulatorAndroid {0}
, mBackgroundPadding {0.0f, 0.0f}
, mBackgroundHorizontalPadding {0.0f, 0.0f}
, mBackgroundVerticalPadding {0.0f, 0.0f}
, mBackgroundCornerRadius {0.0f}
, mColorGradientHorizontal {true}
, mEntrySpacing {0.005f * mRenderer->getScreenWidth()}
@ -255,11 +256,22 @@ void SystemStatusComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("backgroundPadding")) {
const glm::vec2 backgroundPadding {
glm::clamp(elem->get<glm::vec2>("backgroundPadding"), 0.0f, 0.2f)};
mBackgroundPadding.x = backgroundPadding.x * mRenderer->getScreenWidth();
mBackgroundPadding.y = backgroundPadding.y * mRenderer->getScreenHeight();
if (elem->has("backgroundHorizontalPadding")) {
const glm::vec2 backgroundHorizontalPadding {
glm::clamp(elem->get<glm::vec2>("backgroundHorizontalPadding"), 0.0f, 0.2f)};
mBackgroundHorizontalPadding.x =
backgroundHorizontalPadding.x * mRenderer->getScreenWidth();
mBackgroundHorizontalPadding.y =
backgroundHorizontalPadding.y * mRenderer->getScreenWidth();
}
if (elem->has("backgroundVerticalPadding")) {
const glm::vec2 backgroundVerticalPadding {
glm::clamp(elem->get<glm::vec2>("backgroundVerticalPadding"), 0.0f, 0.2f)};
mBackgroundVerticalPadding.x =
backgroundVerticalPadding.x * mRenderer->getScreenHeight();
mBackgroundVerticalPadding.y =
backgroundVerticalPadding.y * mRenderer->getScreenHeight();
}
if (elem->has("backgroundCornerRadius")) {
@ -432,12 +444,14 @@ void SystemStatusComponent::render(const glm::mat4& parentTrans)
mRotationOrigin = mRotationOrigin;
glm::mat4 trans {parentTrans * getTransform()};
trans = glm::translate(trans, glm::vec3 {-mBackgroundPadding.x / 2.0f,
-mBackgroundPadding.y / 2.0f, 0.0f});
trans = glm::translate(trans, glm::vec3 {-mBackgroundHorizontalPadding.x,
-mBackgroundVerticalPadding.x, 0.0f});
mRenderer->setMatrix(trans);
mRenderer->drawRect(
0.0f, 0.0f, mSize.x + mBackgroundPadding.x, mSize.y + mBackgroundPadding.y,
0.0f, 0.0f,
mSize.x + mBackgroundHorizontalPadding.x + mBackgroundHorizontalPadding.y,
mSize.y + mBackgroundVerticalPadding.x + mBackgroundVerticalPadding.y,
mBackgroundColor, mBackgroundColorEnd, mColorGradientHorizontal, mThemeOpacity,
1.0f, Renderer::BlendFactor::SRC_ALPHA, Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA,
mBackgroundCornerRadius);

View file

@ -59,7 +59,8 @@ private:
unsigned int mBackgroundColorEnd;
int mAccumulator;
int mAccumulatorAndroid;
glm::vec2 mBackgroundPadding;
glm::vec2 mBackgroundHorizontalPadding;
glm::vec2 mBackgroundVerticalPadding;
float mBackgroundCornerRadius;
bool mColorGradientHorizontal;
float mEntrySpacing;