From 1cbc2b9c22c13b6cb41437fcab1db001acd0151f Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 20 Feb 2024 16:28:02 +0200 Subject: [PATCH] input_field: add font_color, font_size, font_family --- src/config/ConfigManager.cpp | 6 +++++- src/renderer/widgets/PasswordInputField.cpp | 18 ++++++++++-------- src/renderer/widgets/PasswordInputField.hpp | 18 ++++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 7be3c8b..a4a2d54 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -35,6 +35,8 @@ void CConfigManager::init() { m_config.addSpecialConfigValue("input-field", "outline_thickness", Hyprlang::INT{4}); m_config.addSpecialConfigValue("input-field", "fade_on_empty", Hyprlang::INT{1}); m_config.addSpecialConfigValue("input-field", "font_color", Hyprlang::INT{0xFF000000}); + m_config.addSpecialConfigValue("input-field", "font_family", Hyprlang::STRING{"Sans"}); + m_config.addSpecialConfigValue("input-field", "font_size", Hyprlang::INT{12}); m_config.addSpecialConfigValue("input-field", "halign", Hyprlang::STRING{"center"}); m_config.addSpecialConfigValue("input-field", "valign", Hyprlang::STRING{"center"}); m_config.addSpecialConfigValue("input-field", "position", Hyprlang::VEC2{0, -20}); @@ -96,6 +98,8 @@ std::vector CConfigManager::getWidgetConfigs() { {"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", k.c_str())}, {"fade_on_empty", m_config.getSpecialConfigValue("input-field", "fade_on_empty", k.c_str())}, {"font_color", m_config.getSpecialConfigValue("input-field", "font_color", k.c_str())}, + {"font_family", m_config.getSpecialConfigValue("input-field", "font_family", k.c_str())}, + {"font_size", m_config.getSpecialConfigValue("input-field", "font_size", k.c_str())}, {"halign", m_config.getSpecialConfigValue("input-field", "halign", k.c_str())}, {"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())}, {"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())}, @@ -125,4 +129,4 @@ std::vector CConfigManager::getWidgetConfigs() { } return result; -} \ No newline at end of file +} diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index 5214c89..1b75427 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -9,7 +9,9 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::un outer = std::any_cast(props.at("outer_color")); out_thick = std::any_cast(props.at("outline_thickness")); fadeOnEmpty = std::any_cast(props.at("fade_on_empty")); - font = std::any_cast(props.at("font_color")); + font_color = std::any_cast(props.at("font_color")); + font_family = std::any_cast(props.at("font_family")); + font_size = std::any_cast(props.at("font_size")); pos = std::any_cast(props.at("position")); pos = posFromHVAlign(viewport, size, pos, std::any_cast(props.at("halign")), std::any_cast(props.at("valign"))); @@ -21,9 +23,9 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::un request.id = placeholder.resourceID; request.asset = placeholderText; request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT; - request.props["font_family"] = std::string{"Sans"}; - request.props["color"] = CColor{1.0 - font.r, 1.0 - font.g, 1.0 - font.b, 0.5}; - request.props["font_size"] = (int)size.y / 4; + request.props["font_family"] = font_family; + request.props["color"] = CColor{1.0 - font_color.r, 1.0 - font_color.g, 1.0 - font_color.b, 0.5}; + request.props["font_size"] = font_size; g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); } } @@ -103,7 +105,7 @@ bool CPasswordInputField::draw(const SRenderData& data) { outer.a = fade.a * data.opacity; CColor innerCol = inner; innerCol.a = fade.a * data.opacity; - CColor fontCol = font; + CColor fontCol = font_color; fontCol.a *= fade.a * data.opacity * passAlpha; g_pRenderer->renderRect(outerBox, outerCol, outerBox.h / 2.0); @@ -179,9 +181,9 @@ void CPasswordInputField::updateFailTex() { placeholder.failID = request.id; request.asset = "" + FAIL.value() + ""; request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT; - request.props["font_family"] = std::string{"Sans"}; - request.props["color"] = CColor{1.0 - font.r, 1.0 - font.g, 1.0 - font.b, 0.5}; - request.props["font_size"] = (int)size.y / 4; + request.props["font_family"] = font_family; + request.props["color"] = CColor{1.0 - font_color.r, 1.0 - font_color.g, 1.0 - font_color.b, 0.5}; + request.props["font_size"] = font_size; g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); placeholder.canGetNewFail = false; diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index 2fa51ee..01b1258 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -17,16 +17,18 @@ class CPasswordInputField : public IWidget { virtual bool draw(const SRenderData& data); private: - void updateDots(); - void updateFade(); - void updateFailTex(); + void updateDots(); + void updateFade(); + void updateFailTex(); - Vector2D size; - Vector2D pos; + Vector2D size; + Vector2D pos; - int out_thick; + int out_thick, font_size; - CColor inner, outer, font; + CColor inner, outer, font_color; + + std::string font_family; struct { float currentAmount = 0; @@ -51,4 +53,4 @@ class CPasswordInputField : public IWidget { } placeholder; bool fadeOnEmpty; -}; \ No newline at end of file +};