Fixed an issue in CarouselComponent where setting itemScale to less than 1.0 did not work as expected.

Also fixed a problem where carousel text entries did not get multiplied by itemScale.
This commit is contained in:
Leon Styhre 2022-10-25 20:33:12 +02:00
parent 4513b20339
commit a8d1c4a2e1
3 changed files with 30 additions and 16 deletions

View file

@ -227,7 +227,7 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
auto item = std::make_shared<ImageComponent>(false, dynamic);
item->setLinearInterpolation(mLinearInterpolation);
item->setMipmapping(true);
item->setMaxSize(glm::round(mItemSize * mItemScale));
item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
item->applyTheme(theme, "system", "image_logo",
ThemeFlags::PATH | ThemeFlags::COLOR);
item->setRotateByTargetSize(true);
@ -241,7 +241,7 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
auto item = std::make_shared<ImageComponent>(false, dynamic);
item->setLinearInterpolation(mLinearInterpolation);
item->setMipmapping(true);
item->setMaxSize(glm::round(mItemSize * mItemScale));
item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
item->setImage(entry.data.itemPath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
item->setRotateByTargetSize(true);
@ -252,7 +252,8 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
auto defaultItem = std::make_shared<ImageComponent>(false, dynamic);
defaultItem->setLinearInterpolation(mLinearInterpolation);
defaultItem->setMipmapping(true);
defaultItem->setMaxSize(glm::round(mItemSize * mItemScale));
defaultItem->setMaxSize(
glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
defaultItem->setImage(entry.data.defaultItemPath);
defaultItem->applyTheme(theme, "system", "", ThemeFlags::ALL);
defaultItem->setRotateByTargetSize(true);
@ -276,7 +277,8 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
auto text = std::make_shared<TextComponent>(
nameEntry, mFont, 0x000000FF, mItemHorizontalAlignment, mItemVerticalAlignment,
glm::vec3 {0.0f, 0.0f, 0.0f}, glm::round(mItemSize * mItemScale), 0x00000000);
glm::vec3 {0.0f, 0.0f, 0.0f},
glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)), 0x00000000);
if (legacyMode) {
text->applyTheme(theme, "system", "text_logoText",
ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR |
@ -324,7 +326,7 @@ void CarouselComponent<T>::updateEntry(Entry& entry, const std::shared_ptr<Theme
auto item = std::make_shared<ImageComponent>(false, true);
item->setLinearInterpolation(mLinearInterpolation);
item->setMipmapping(true);
item->setMaxSize(glm::round(mItemSize * mItemScale));
item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
item->setImage(entry.data.itemPath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
item->setRotateByTargetSize(true);
@ -769,9 +771,17 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
if (singleEntry)
distance = 0.0f;
float scale {1.0f + ((mItemScale - 1.0f) * (1.0f - fabsf(distance)))};
scale = std::min(mItemScale, std::max(1.0f, scale));
scale /= mItemScale;
float scale {0.0f};
if (mItemScale >= 1.0f) {
scale = 1.0f + ((mItemScale - 1.0f) * (1.0f - fabsf(distance)));
scale = std::min(mItemScale, std::max(1.0f, scale));
scale /= mItemScale;
}
else {
scale = 1.0f + ((1.0f - mItemScale) * (fabsf(distance) - 1.0f));
scale = std::max(mItemScale, std::min(1.0f, scale));
}
glm::mat4 itemTrans {carouselTrans};
if (singleEntry)
@ -1012,7 +1022,7 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (elem->has("itemScale"))
mItemScale = glm::clamp(elem->get<float>("itemScale"), 0.5f, 3.0f);
mItemScale = glm::clamp(elem->get<float>("itemScale"), 0.2f, 3.0f);
if (elem->has("itemTransitions")) {
const std::string itemTransitions {elem->get<std::string>("itemTransitions")};
@ -1206,7 +1216,9 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
mFont = Font::getFromTheme(elem, properties, mFont, 0.0f, mLegacyMode);
// For non-legacy themes, scale the font size with the itemScale property value.
mFont = Font::getFromTheme(elem, properties, mFont, 0.0f, mLegacyMode,
(mLegacyMode ? 1.0f : (mItemScale >= 1.0f ? mItemScale : 1.0f)));
if (elem->has("textColor"))
mTextColor = elem->get<unsigned int>("textColor");

View file

@ -422,7 +422,8 @@ std::shared_ptr<Font> Font::getFromTheme(const ThemeData::ThemeElement* elem,
unsigned int properties,
const std::shared_ptr<Font>& orig,
const float maxHeight,
const bool legacyTheme)
const bool legacyTheme,
const float sizeMultiplier)
{
mLegacyTheme = legacyTheme;
@ -438,6 +439,8 @@ std::shared_ptr<Font> Font::getFromTheme(const ThemeData::ThemeElement* elem,
if (properties & FONT_SIZE && elem->has("fontSize")) {
size = glm::clamp(screenHeight * elem->get<float>("fontSize"), screenHeight * 0.001f,
screenHeight * 1.5f);
// This is used by the carousel where the itemScale property also scales the font size.
size *= sizeMultiplier;
}
if (maxHeight != 0.0f && size > maxHeight)
@ -741,10 +744,8 @@ Font::Glyph* Font::getGlyph(const unsigned int id)
}
// Use the letter 'S' as a size reference.
if (mLetterHeight == 0 && id == 'S') {
const float ratio {static_cast<float>(glyphSize.y) / std::round(mFontSize)};
mLetterHeight = mFontSize * ratio;
}
if (mLetterHeight == 0 && id == 'S')
mLetterHeight = static_cast<float>(glyphSize.y);
// Create glyph.
Glyph& glyph {mGlyphMap[id]};

View file

@ -94,7 +94,8 @@ public:
unsigned int properties,
const std::shared_ptr<Font>& orig,
const float maxHeight = 0.0f,
const bool legacyTheme = false);
const bool legacyTheme = false,
const float sizeMultiplier = 1.0f);
// Returns an approximation of VRAM used by this font's texture (in bytes).
size_t getMemUsage() const;