mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-05-13 05:40:42 +01:00
Merge f0141ebf0d
into e588351d1d
This commit is contained in:
commit
87bd64d18b
3 changed files with 92 additions and 3 deletions
|
@ -14,6 +14,7 @@ enum eConfigValueDataTypes {
|
||||||
CVD_TYPE_INVALID = -1,
|
CVD_TYPE_INVALID = -1,
|
||||||
CVD_TYPE_LAYOUT = 0,
|
CVD_TYPE_LAYOUT = 0,
|
||||||
CVD_TYPE_GRADIENT = 1,
|
CVD_TYPE_GRADIENT = 1,
|
||||||
|
CVD_TYPE_FONT_SIZE = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
class ICustomConfigValueData {
|
class ICustomConfigValueData {
|
||||||
|
@ -131,3 +132,57 @@ class CGradientValueData : public ICustomConfigValueData {
|
||||||
return P;
|
return P;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum eFontRelativeTypes {
|
||||||
|
FR_TYPE_ABSOLUTE = 0,
|
||||||
|
FR_TYPE_VIEW_WIDTH = 1,
|
||||||
|
FR_TYPE_VIEW_HEIGHT = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
class CFontSizeValueData : public ICustomConfigValueData {
|
||||||
|
public:
|
||||||
|
CFontSizeValueData() {}
|
||||||
|
virtual ~CFontSizeValueData() {};
|
||||||
|
|
||||||
|
virtual eConfigValueDataTypes getDataType() {
|
||||||
|
return CVD_TYPE_FONT_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static CFontSizeValueData* fromAnyPv(const std::any& v) {
|
||||||
|
RASSERT(v.type() == typeid(void*), "Invalid config value type");
|
||||||
|
const auto P = (CFontSizeValueData*)std::any_cast<void*>(v);
|
||||||
|
RASSERT(P, "Empty config value");
|
||||||
|
return P;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string toString() {
|
||||||
|
return std::format("{}{}", m_size, valueSuffix());
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *valueSuffix() {
|
||||||
|
switch (m_relativeTo) {
|
||||||
|
case FR_TYPE_VIEW_WIDTH:
|
||||||
|
return "vw";
|
||||||
|
case FR_TYPE_VIEW_HEIGHT:
|
||||||
|
return "vh";
|
||||||
|
case FR_TYPE_ABSOLUTE:
|
||||||
|
default:
|
||||||
|
return "px";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getAbsolute(const Hyprutils::Math::Vector2D& viewport) {
|
||||||
|
switch (m_relativeTo) {
|
||||||
|
case FR_TYPE_VIEW_WIDTH:
|
||||||
|
return std::round((m_size / 100) * viewport.x);
|
||||||
|
case FR_TYPE_VIEW_HEIGHT:
|
||||||
|
return std::round((m_size / 100) * viewport.y);
|
||||||
|
case FR_TYPE_ABSOLUTE:
|
||||||
|
default:
|
||||||
|
return std::round(m_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float m_size;
|
||||||
|
eFontRelativeTypes m_relativeTo = FR_TYPE_ABSOLUTE;
|
||||||
|
};
|
||||||
|
|
|
@ -94,11 +94,41 @@ static Hyprlang::CParseResult configHandleLayoutOption(const char* v, void** dat
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Hyprlang::CParseResult configHandleFontSizeOption(const char* v, void** data) {
|
||||||
|
const std::string VALUE = v;
|
||||||
|
Hyprlang::CParseResult result;
|
||||||
|
|
||||||
|
if (!*data)
|
||||||
|
*data = new CFontSizeValueData();
|
||||||
|
|
||||||
|
const auto DATA = (CFontSizeValueData*)(*data);
|
||||||
|
|
||||||
|
std::string stripped;
|
||||||
|
if (VALUE.ends_with("vw")) {
|
||||||
|
DATA->m_relativeTo = FR_TYPE_VIEW_WIDTH;
|
||||||
|
stripped = VALUE.substr(0, VALUE.size() - 3);
|
||||||
|
} else if (VALUE.ends_with("vh")) {
|
||||||
|
DATA->m_relativeTo = FR_TYPE_VIEW_HEIGHT;
|
||||||
|
stripped = VALUE.substr(0, VALUE.size() - 3);
|
||||||
|
} else {
|
||||||
|
stripped = VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DATA->m_size = std::stof(VALUE);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static void configHandleLayoutOptionDestroy(void** data) {
|
static void configHandleLayoutOptionDestroy(void** data) {
|
||||||
if (*data)
|
if (*data)
|
||||||
delete reinterpret_cast<CLayoutValueData*>(*data);
|
delete reinterpret_cast<CLayoutValueData*>(*data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void configHandleFontSizeOptionDestroy(void** data) {
|
||||||
|
if (*data)
|
||||||
|
delete reinterpret_cast<CFontSizeValueData*>(*data);
|
||||||
|
}
|
||||||
|
|
||||||
static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) {
|
static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) {
|
||||||
const std::string V = VALUE;
|
const std::string V = VALUE;
|
||||||
|
|
||||||
|
@ -202,6 +232,10 @@ inline static constexpr auto LAYOUTCONFIG = [](const char* default_value) -> Hyp
|
||||||
return Hyprlang::CUSTOMTYPE{&configHandleLayoutOption, configHandleLayoutOptionDestroy, default_value};
|
return Hyprlang::CUSTOMTYPE{&configHandleLayoutOption, configHandleLayoutOptionDestroy, default_value};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline static constexpr auto FONTSIZECONFIG = [](const char* default_value) -> Hyprlang::CUSTOMTYPE {
|
||||||
|
return Hyprlang::CUSTOMTYPE{&configHandleFontSizeOption, configHandleFontSizeOptionDestroy, default_value};
|
||||||
|
};
|
||||||
|
|
||||||
void CConfigManager::init() {
|
void CConfigManager::init() {
|
||||||
|
|
||||||
#define SHADOWABLE(name) \
|
#define SHADOWABLE(name) \
|
||||||
|
@ -311,7 +345,7 @@ void CConfigManager::init() {
|
||||||
m_config.addSpecialConfigValue("label", "monitor", Hyprlang::STRING{""});
|
m_config.addSpecialConfigValue("label", "monitor", Hyprlang::STRING{""});
|
||||||
m_config.addSpecialConfigValue("label", "position", LAYOUTCONFIG("0,0"));
|
m_config.addSpecialConfigValue("label", "position", LAYOUTCONFIG("0,0"));
|
||||||
m_config.addSpecialConfigValue("label", "color", Hyprlang::INT{0xFFFFFFFF});
|
m_config.addSpecialConfigValue("label", "color", Hyprlang::INT{0xFFFFFFFF});
|
||||||
m_config.addSpecialConfigValue("label", "font_size", Hyprlang::INT{16});
|
m_config.addSpecialConfigValue("label", "font_size", FONTSIZECONFIG("16"));
|
||||||
m_config.addSpecialConfigValue("label", "text", Hyprlang::STRING{"Sample Text"});
|
m_config.addSpecialConfigValue("label", "text", Hyprlang::STRING{"Sample Text"});
|
||||||
m_config.addSpecialConfigValue("label", "font_family", Hyprlang::STRING{"Sans"});
|
m_config.addSpecialConfigValue("label", "font_family", Hyprlang::STRING{"Sans"});
|
||||||
m_config.addSpecialConfigValue("label", "halign", Hyprlang::STRING{"none"});
|
m_config.addSpecialConfigValue("label", "halign", Hyprlang::STRING{"none"});
|
||||||
|
|
|
@ -82,8 +82,8 @@ CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string,
|
||||||
|
|
||||||
std::string textAlign = std::any_cast<Hyprlang::STRING>(props.at("text_align"));
|
std::string textAlign = std::any_cast<Hyprlang::STRING>(props.at("text_align"));
|
||||||
std::string fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
|
std::string fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
|
||||||
CHyprColor labelColor = std::any_cast<Hyprlang::INT>(props.at("color"));
|
CHyprColor labelColor = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||||
int fontSize = std::any_cast<Hyprlang::INT>(props.at("font_size"));
|
int fontSize = CFontSizeValueData::fromAnyPv(props.at("font_size"))->getAbsolute(viewport_);
|
||||||
|
|
||||||
label = formatString(labelPreFormat);
|
label = formatString(labelPreFormat);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue