From be6268a7ecea2ad50cdb78fb661884811a8a28e8 Mon Sep 17 00:00:00 2001 From: M Matthew Hydock Date: Thu, 24 Apr 2025 14:48:08 -0400 Subject: groupbar: Add options for setting group bar title font weight (and indicator gap) (#9617) --- src/config/ConfigDataValues.hpp | 46 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'src/config/ConfigDataValues.hpp') diff --git a/src/config/ConfigDataValues.hpp b/src/config/ConfigDataValues.hpp index 270f6880..2fad9277 100644 --- a/src/config/ConfigDataValues.hpp +++ b/src/config/ConfigDataValues.hpp @@ -2,11 +2,13 @@ #include "../defines.hpp" #include "../helpers/varlist/VarList.hpp" #include +#include enum eConfigValueDataTypes : int8_t { - CVD_TYPE_INVALID = -1, - CVD_TYPE_GRADIENT = 0, - CVD_TYPE_CSS_VALUE = 1 + CVD_TYPE_INVALID = -1, + CVD_TYPE_GRADIENT = 0, + CVD_TYPE_CSS_VALUE = 1, + CVD_TYPE_FONT_WEIGHT = 2, }; class ICustomConfigValueData { @@ -136,3 +138,41 @@ class CCssGapData : public ICustomConfigValueData { return std::format("{} {} {} {}", m_top, m_right, m_bottom, m_left); } }; + +class CFontWeightConfigValueData : public ICustomConfigValueData { + public: + CFontWeightConfigValueData() = default; + CFontWeightConfigValueData(const char* weight) { + parseWeight(weight); + } + + int64_t m_value = 400; // default to normal weight + + virtual eConfigValueDataTypes getDataType() { + return CVD_TYPE_FONT_WEIGHT; + } + + virtual std::string toString() { + return std::format("{}", m_value); + } + + void parseWeight(const std::string& strWeight) { + auto lcWeight{strWeight}; + transform(strWeight.begin(), strWeight.end(), lcWeight.begin(), ::tolower); + + // values taken from Pango weight enums + const auto WEIGHTS = std::map{ + {"thin", 100}, {"ultralight", 200}, {"light", 300}, {"semilight", 350}, {"book", 380}, {"normal", 400}, + {"medium", 500}, {"semibold", 600}, {"bold", 700}, {"ultrabold", 800}, {"heavy", 900}, {"ultraheavy", 1000}, + }; + + auto weight = WEIGHTS.find(lcWeight); + if (weight != WEIGHTS.end()) + m_value = weight->second; + else { + int w_i = std::stoi(strWeight); + if (w_i < 100 || w_i > 1000) + m_value = 400; + } + } +}; -- cgit v1.2.3