From 70ee7e754dc1f08a57ce2ebb36ffef69c1a848bd Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Tue, 21 Apr 2026 18:56:26 +1000 Subject: [PATCH] feat: add root font size scale --- .../src/Caelestia/Config/appearanceconfig.hpp | 1 + plugin/src/Caelestia/Config/font.cpp | 42 ++++++++++++++----- plugin/src/Caelestia/Config/font.hpp | 5 ++- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/plugin/src/Caelestia/Config/appearanceconfig.hpp b/plugin/src/Caelestia/Config/appearanceconfig.hpp index 8f591cf0..a624a206 100644 --- a/plugin/src/Caelestia/Config/appearanceconfig.hpp +++ b/plugin/src/Caelestia/Config/appearanceconfig.hpp @@ -180,6 +180,7 @@ class AppearanceFont : public ConfigObject { Q_OBJECT QML_ANONYMOUS + CONFIG_PROPERTY(qreal, scale, 1) CONFIG_SUBOBJECT(FontStyleConfig, headline) CONFIG_SUBOBJECT(FontStyleConfig, title) CONFIG_SUBOBJECT(FontStyleConfig, body) diff --git a/plugin/src/Caelestia/Config/font.cpp b/plugin/src/Caelestia/Config/font.cpp index ea50c168..edd75069 100644 --- a/plugin/src/Caelestia/Config/font.cpp +++ b/plugin/src/Caelestia/Config/font.cpp @@ -17,11 +17,13 @@ QFont FontStyleBase::small() const { return m_small; } -QFont FontStyleBase::buildFont(const FontConfig* cfg, const QString& fallbackFamily) { +QFont FontStyleBase::buildFont(const FontConfig* cfg, const QString& fallbackFamily, qreal scale) { QFont font; font.setFamily(cfg->family().isEmpty() ? fallbackFamily : cfg->family()); - font.setPointSize(cfg->size() > 0 ? cfg->size() : 1); - font.setVariableAxis("opsz", static_cast(font.pointSize())); + const int scaledSize = static_cast(cfg->size() * scale); + const int cappedSize = scaledSize > 0 ? scaledSize : 1; + font.setPointSize(cappedSize); + font.setVariableAxis("opsz", static_cast(cappedSize)); font.setWeight(QFont::Weight(cfg->weight())); font.setVariableAxis("wght", font.weight()); font.setItalic(cfg->italic()); @@ -61,9 +63,9 @@ void FontStyleBase::bind(FontStyleConfig* cfg) { void FontStyleBase::rebuild() { if (m_cfg) { const auto family = m_cfg->family(); - m_large = buildFont(m_cfg->large(), family); - m_medium = buildFont(m_cfg->medium(), family); - m_small = buildFont(m_cfg->small(), family); + m_large = buildFont(m_cfg->large(), family, m_scale); + m_medium = buildFont(m_cfg->medium(), family, m_scale); + m_small = buildFont(m_cfg->small(), family, m_scale); } else { m_large = QFont(); m_medium = QFont(); @@ -72,6 +74,13 @@ void FontStyleBase::rebuild() { emit fontsChanged(); } +void FontStyleBase::setScale(qreal scale) { + if (qFuzzyCompare(m_scale + 1.0, scale + 1.0)) + return; + m_scale = scale; + rebuild(); +} + // FontStyle FontStyle::FontStyle(QObject* parent) @@ -119,10 +128,10 @@ IconFontBuilders* IconFontStyle::builders() const { void IconFontStyle::rebuild() { if (auto* cfg = qobject_cast(m_cfg)) { const auto family = cfg->family(); - m_large = buildFont(cfg->large(), family); - m_medium = buildFont(cfg->medium(), family); - m_small = buildFont(cfg->small(), family); - m_extraLarge = buildFont(cfg->extraLarge(), family); + m_large = buildFont(cfg->large(), family, m_scale); + m_medium = buildFont(cfg->medium(), family, m_scale); + m_small = buildFont(cfg->small(), family, m_scale); + m_extraLarge = buildFont(cfg->extraLarge(), family, m_scale); } else { m_large = QFont(); m_medium = QFont(); @@ -210,6 +219,7 @@ void FontTokens::bindFont(AppearanceFont* font) { m_font = font; if (font) { + rebuildScale(); m_headline->bind(font->headline()); m_title->bind(font->title()); m_body->bind(font->body()); @@ -218,7 +228,9 @@ void FontTokens::bindFont(AppearanceFont* font) { m_icon->bind(font->icon()); connect(font, &AppearanceFont::clockChanged, this, &FontTokens::rebuildClock); + connect(font, &AppearanceFont::scaleChanged, this, &FontTokens::rebuildScale); } else { + rebuildScale(); m_headline->bind(nullptr); m_title->bind(nullptr); m_body->bind(nullptr); @@ -230,6 +242,16 @@ void FontTokens::bindFont(AppearanceFont* font) { rebuildClock(); } +void FontTokens::rebuildScale() { + const qreal s = m_font ? m_font->scale() : 1; + m_headline->setScale(s); + m_title->setScale(s); + m_body->setScale(s); + m_label->setScale(s); + m_mono->setScale(s); + m_icon->setScale(s); +} + void FontTokens::rebuildClock() { QFont f; if (m_font) diff --git a/plugin/src/Caelestia/Config/font.hpp b/plugin/src/Caelestia/Config/font.hpp index 4e6dc7e9..2cfbf341 100644 --- a/plugin/src/Caelestia/Config/font.hpp +++ b/plugin/src/Caelestia/Config/font.hpp @@ -59,6 +59,7 @@ public: : QObject(parent) {} void bind(FontStyleConfig* cfg); + void setScale(qreal scale); [[nodiscard]] QFont large() const; [[nodiscard]] QFont medium() const; @@ -70,9 +71,10 @@ signals: protected: virtual void rebuild(); - static QFont buildFont(const FontConfig* cfg, const QString& fallbackFamily); + static QFont buildFont(const FontConfig* cfg, const QString& fallbackFamily, qreal scale); FontStyleConfig* m_cfg = nullptr; + qreal m_scale = 1; QFont m_large; QFont m_medium; QFont m_small; @@ -148,6 +150,7 @@ signals: private: void rebuildClock(); + void rebuildScale(); AppearanceFont* m_font = nullptr; FontStyle* m_headline;