From 1f2913f90cc14ce1339d1f2c4c995051cd59b1dd Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 20 Apr 2026 23:12:08 +1000 Subject: [PATCH] feat: add font builder --- plugin/src/Caelestia/Config/CMakeLists.txt | 1 + plugin/src/Caelestia/Config/fontbuilder.cpp | 42 +++++++++++++++++++++ plugin/src/Caelestia/Config/fontbuilder.hpp | 27 +++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 plugin/src/Caelestia/Config/fontbuilder.cpp create mode 100644 plugin/src/Caelestia/Config/fontbuilder.hpp diff --git a/plugin/src/Caelestia/Config/CMakeLists.txt b/plugin/src/Caelestia/Config/CMakeLists.txt index 4b26ea02..05008965 100644 --- a/plugin/src/Caelestia/Config/CMakeLists.txt +++ b/plugin/src/Caelestia/Config/CMakeLists.txt @@ -6,6 +6,7 @@ qml_module(caelestia-config configobject.cpp rootconfig.cpp appearanceconfig.cpp + fontbuilder.cpp tokens.cpp tokensattached.cpp anim.cpp diff --git a/plugin/src/Caelestia/Config/fontbuilder.cpp b/plugin/src/Caelestia/Config/fontbuilder.cpp new file mode 100644 index 00000000..7e1bbb0e --- /dev/null +++ b/plugin/src/Caelestia/Config/fontbuilder.cpp @@ -0,0 +1,42 @@ +#include "fontbuilder.hpp" + +#include +#include + +namespace caelestia::config { + +FontBuilder::FontBuilder(QFont font) + : m_font(std::move(font)) {} + +FontBuilder FontBuilder::family(const QString& family) { + m_font.setFamily(family); + return *this; +} + +FontBuilder FontBuilder::size(int pointSize) { + m_font.setPointSize(pointSize); + m_font.setVariableAxis("opsz", static_cast(pointSize)); + return *this; +} + +FontBuilder FontBuilder::weight(QFont::Weight weight) { + m_font.setWeight(weight); + m_font.setVariableAxis("wght", weight); + return *this; +} + +FontBuilder FontBuilder::italic(bool on) { + m_font.setItalic(on); + return *this; +} + +FontBuilder FontBuilder::vaxis(QFont::Tag tag, float value) { + m_font.setVariableAxis(tag, value); + return *this; +} + +QFont FontBuilder::build() const { + return m_font; +} + +} // namespace caelestia::config diff --git a/plugin/src/Caelestia/Config/fontbuilder.hpp b/plugin/src/Caelestia/Config/fontbuilder.hpp new file mode 100644 index 00000000..38178dfb --- /dev/null +++ b/plugin/src/Caelestia/Config/fontbuilder.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace caelestia::config { + +class FontBuilder { + Q_GADGET + QML_ANONYMOUS + +public: + FontBuilder() = default; + explicit FontBuilder(QFont font); + + [[nodiscard]] Q_INVOKABLE FontBuilder family(const QString& family); + [[nodiscard]] Q_INVOKABLE FontBuilder size(int pointSize); + [[nodiscard]] Q_INVOKABLE FontBuilder weight(QFont::Weight weight); + [[nodiscard]] Q_INVOKABLE FontBuilder italic(bool on = true); + [[nodiscard]] Q_INVOKABLE FontBuilder vaxis(QFont::Tag tag, float value); + [[nodiscard]] Q_INVOKABLE QFont build() const; + +private: + QFont m_font; +}; + +} // namespace caelestia::config