Added an 'entryRelativeScale' property to the helpsystem element

This commit is contained in:
Leon Styhre 2025-03-15 13:19:58 +01:00
parent da11140626
commit fa503fef7a
5 changed files with 58 additions and 10 deletions

View file

@ -566,6 +566,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"scope", STRING}, {"scope", STRING},
{"entries", STRING}, {"entries", STRING},
{"entryLayout", STRING}, {"entryLayout", STRING},
{"entryRelativeScale", FLOAT},
{"entrySpacing", FLOAT}, {"entrySpacing", FLOAT},
{"entrySpacingDimmed", FLOAT}, {"entrySpacingDimmed", FLOAT},
{"iconTextSpacing", FLOAT}, {"iconTextSpacing", FLOAT},

View file

@ -37,6 +37,9 @@ HelpComponent::HelpComponent(std::shared_ptr<Font> font)
, mStyleBackgroundCornerRadius {0.0f} , mStyleBackgroundCornerRadius {0.0f}
, mStyleColorGradientHorizontal {true} , mStyleColorGradientHorizontal {true}
, mStyleEntryLayout {EntryLayout::ICON_FIRST} , mStyleEntryLayout {EntryLayout::ICON_FIRST}
, mEntryRelativeScale {1.0f}
, mLetterHeight {mStyleFont->getLetterHeight() * 1.25f}
, mLetterHeightDimmed {mLetterHeight}
, mStyleRotation {0.0f} , mStyleRotation {0.0f}
, mStyleEntrySpacing {0.00833f} , mStyleEntrySpacing {0.00833f}
, mStyleEntrySpacingDimmed {mStyleEntrySpacing} , mStyleEntrySpacingDimmed {mStyleEntrySpacing}
@ -166,14 +169,38 @@ void HelpComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mRenderer->getScreenWidth(); mRenderer->getScreenWidth();
} }
if (elem->has("entryRelativeScale"))
mEntryRelativeScale = glm::clamp(elem->get<float>("entryRelativeScale"), 0.2f, 3.0f);
if (elem->has("fontPath") || elem->has("fontSize")) { if (elem->has("fontPath") || elem->has("fontSize")) {
mStyleFont = Font::getFromTheme(elem, ThemeFlags::ALL, mStyleFont); mStyleFont = Font::getFromTheme(elem, ThemeFlags::ALL, mStyleFont, 0.0f, 1.0f, false, true);
if (!elem->has("fontSizeDimmed")) mLetterHeight = mStyleFont->getLetterHeight() * 1.25f;
mStyleFontDimmed = Font::getFromTheme(elem, ThemeFlags::ALL, mStyleFont); if (!elem->has("fontSizeDimmed")) {
mStyleFontDimmed = Font::getFromTheme(
elem, ThemeFlags::ALL, mStyleFont, 0.0f,
(mEntryRelativeScale < 1.0f ? mEntryRelativeScale : 1.0f), true, true);
mLetterHeightDimmed = mLetterHeight;
}
if (mEntryRelativeScale < 1.0f)
mStyleFont = Font::getFromTheme(elem, ThemeFlags::ALL, mStyleFont, 0.0f,
mEntryRelativeScale, false, true);
}
else if (mEntryRelativeScale < 1.0f) {
mStyleFont = Font::getFromTheme(elem, ThemeFlags::ALL, mStyleFont, 0.0f,
mEntryRelativeScale, false, true);
} }
if (elem->has("fontSizeDimmed")) if (elem->has("fontSizeDimmed")) {
mStyleFontDimmed = Font::getFromTheme(elem, ThemeFlags::ALL, mStyleFont, 0.0f, 1.0f, true); mStyleFontDimmed =
Font::getFromTheme(elem, ThemeFlags::ALL, mStyleFont, 0.0f, 1.0f, true, true);
mLetterHeightDimmed = mStyleFontDimmed->getLetterHeight() * 1.25f;
if (mEntryRelativeScale < 1.0f)
mStyleFontDimmed = Font::getFromTheme(elem, ThemeFlags::ALL, mStyleFont, 0.0f,
mEntryRelativeScale, true, true);
}
else if (mEntryRelativeScale < 1.0f && !elem->has("fontPath") && !elem->has("fontSize")) {
mStyleFontDimmed = mStyleFont;
}
if (elem->has("scope")) { if (elem->has("scope")) {
const std::string& scope {elem->get<std::string>("scope")}; const std::string& scope {elem->get<std::string>("scope")};
@ -604,7 +631,7 @@ void HelpComponent::updateGrid()
std::vector<std::shared_ptr<TextComponent>> labels; std::vector<std::shared_ptr<TextComponent>> labels;
float width {0.0f}; float width {0.0f};
float height {font->getLetterHeight() * 1.25f}; const float height {isDimmed ? mLetterHeightDimmed : mLetterHeight};
for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); ++it) { for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); ++it) {
if (!mEntries.empty() && if (!mEntries.empty() &&
@ -624,7 +651,12 @@ void HelpComponent::updateGrid()
} }
icon->setColorShift(isDimmed ? mStyleIconColorDimmed : mStyleIconColor); icon->setColorShift(isDimmed ? mStyleIconColorDimmed : mStyleIconColor);
if (mEntryRelativeScale < 1.0f)
icon->setResize(0, height); icon->setResize(0, height);
else
icon->setResize(0, height / mEntryRelativeScale);
icon->setOpacity(isDimmed ? mStyleOpacityDimmed : mStyleOpacity); icon->setOpacity(isDimmed ? mStyleOpacityDimmed : mStyleOpacity);
icons.push_back(icon); icons.push_back(icon);

View file

@ -91,6 +91,9 @@ private:
float mStyleBackgroundCornerRadius; float mStyleBackgroundCornerRadius;
bool mStyleColorGradientHorizontal; bool mStyleColorGradientHorizontal;
EntryLayout mStyleEntryLayout; EntryLayout mStyleEntryLayout;
float mEntryRelativeScale;
float mLetterHeight;
float mLetterHeightDimmed;
float mStyleRotation; float mStyleRotation;
float mStyleEntrySpacing; float mStyleEntrySpacing;
float mStyleEntrySpacingDimmed; float mStyleEntrySpacingDimmed;

View file

@ -204,7 +204,8 @@ std::shared_ptr<Font> Font::getFromTheme(const ThemeData::ThemeElement* elem,
const std::shared_ptr<Font>& orig, const std::shared_ptr<Font>& orig,
const float maxHeight, const float maxHeight,
const float sizeMultiplier, const float sizeMultiplier,
const bool fontSizeDimmed) const bool fontSizeDimmed,
const bool helpComponent)
{ {
using namespace ThemeFlags; using namespace ThemeFlags;
if (!(properties & FONT_PATH) && !(properties & FONT_SIZE)) if (!(properties & FONT_PATH) && !(properties & FONT_SIZE))
@ -220,11 +221,21 @@ std::shared_ptr<Font> Font::getFromTheme(const ThemeData::ThemeElement* elem,
if (fontSizeDimmed && properties & FONT_SIZE && elem->has("fontSizeDimmed")) { if (fontSizeDimmed && properties & FONT_SIZE && elem->has("fontSizeDimmed")) {
size = glm::clamp(screenSize * elem->get<float>("fontSizeDimmed"), screenSize * 0.001f, size = glm::clamp(screenSize * elem->get<float>("fontSizeDimmed"), screenSize * 0.001f,
screenSize * 1.5f); screenSize * 1.5f);
// This is used by HelpComponent to set the relative size of the font compared to the icons.
size *= sizeMultiplier;
} }
else if (properties & FONT_SIZE && elem->has("fontSize")) { else if (properties & FONT_SIZE && elem->has("fontSize")) {
size = glm::clamp(screenSize * elem->get<float>("fontSize"), screenSize * 0.001f, size = glm::clamp(screenSize * elem->get<float>("fontSize"), screenSize * 0.001f,
screenSize * 1.5f); screenSize * 1.5f);
// This is used by the carousel where the itemScale property also scales the font size. // This is used by the carousel where the itemScale property also scales the font size, as
// well as by HelpComponent to set the relative size of the font compared to the icons.
size *= sizeMultiplier;
}
else if (helpComponent && sizeMultiplier != 1.0f && fontSizeDimmed &&
!elem->has("fontSizeDimmed")) {
size *= sizeMultiplier;
}
else if (helpComponent && sizeMultiplier != 1.0f && !fontSizeDimmed && !elem->has("fontSize")) {
size *= sizeMultiplier; size *= sizeMultiplier;
} }

View file

@ -122,7 +122,8 @@ public:
const std::shared_ptr<Font>& orig, const std::shared_ptr<Font>& orig,
const float maxHeight = 0.0f, const float maxHeight = 0.0f,
const float sizeMultiplier = 1.0f, const float sizeMultiplier = 1.0f,
const bool fontSizeDimmed = false); const bool fontSizeDimmed = false,
const bool helpComponent = false);
// Returns an approximation of VRAM used by the glyph atlas textures for this font object. // Returns an approximation of VRAM used by the glyph atlas textures for this font object.
size_t getMemUsage() const; size_t getMemUsage() const;