From 8f55ec8b413b341b9fe215a30d04c8c88700838e Mon Sep 17 00:00:00 2001 From: luyu-wu Date: Tue, 20 Feb 2024 18:03:46 -0500 Subject: [PATCH 1/4] Add placeholder color --- nix/hm-module.nix | 7 ++++++- src/config/ConfigManager.cpp | 2 ++ src/renderer/widgets/PasswordInputField.cpp | 4 +++- src/renderer/widgets/PasswordInputField.hpp | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nix/hm-module.nix b/nix/hm-module.nix index 13564b8c..0353dbdb 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -116,10 +116,15 @@ in { }; placeholder_text = mkOption { - description = "The placeholder text of the input field"; + description = "The placeholder text color of the input field"; type = str; default = "Input Password..."; }; + font_color = mkOption { + description = "The font color of the input field"; + type = str; + default = "rgb(120, 120, 120)"; + }; hide_input = mkOption { description = "Hide input typed into the input field"; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 7342127b..854cf3fb 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -41,6 +41,7 @@ void CConfigManager::init() { m_config.addSpecialConfigValue("input-field", "valign", Hyprlang::STRING{"center"}); m_config.addSpecialConfigValue("input-field", "position", Hyprlang::VEC2{0, -20}); m_config.addSpecialConfigValue("input-field", "placeholder_text", Hyprlang::STRING{"Input Password"}); + m_config.addSpecialConfigValue("input-field", "placeholder_color", Hyprlang::INT{0xFF000000}); m_config.addSpecialConfigValue("input-field", "hide_input", Hyprlang::INT{0}); m_config.addSpecialCategory("label", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true}); @@ -105,6 +106,7 @@ std::vector CConfigManager::getWidgetConfigs() { {"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())}, {"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())}, {"placeholder_text", m_config.getSpecialConfigValue("input-field", "placeholder_text", k.c_str())}, + {"placeholder_color", m_config.getSpecialConfigValue("input-field", "placeholder_color", k.c_str())}, {"hide_input", m_config.getSpecialConfigValue("input-field", "hide_input", k.c_str())}, } }); diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index 056c8037..b9ae8138 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -12,6 +12,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u dt_space = std::any_cast(props.at("dots_spacing")); fadeOnEmpty = std::any_cast(props.at("fade_on_empty")); font = std::any_cast(props.at("font_color")); + placeholder_color = std::any_cast(props.at("placeholder_color")); pos = std::any_cast(props.at("position")); hiddenInputState.enabled = std::any_cast(props.at("hide_input")); viewport = viewport_; @@ -21,6 +22,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u dt_space = std::clamp(dt_space, 0.f, 1.f); std::string placeholderText = std::any_cast(props.at("placeholder_text")); + if (!placeholderText.empty()) { placeholder.resourceID = "placeholder:" + std::to_string((uintptr_t)this); CAsyncResourceGatherer::SPreloadRequest request; @@ -28,7 +30,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u 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["color"] = CColor{placeholder_color.r,placeholder_color.g,placeholder_color.b,0.5}; request.props["font_size"] = (int)size.y / 4; g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); } diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index 5369a972..bcdfb19c 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -30,7 +30,7 @@ class CPasswordInputField : public IWidget { int out_thick; - CColor inner, outer, font; + CColor inner, outer, font, placeholder_color; struct { float currentAmount = 0; From d30a5aa6c62591ac567a8a53ad3778f4443d494b Mon Sep 17 00:00:00 2001 From: luyu-wu Date: Tue, 20 Feb 2024 18:07:07 -0500 Subject: [PATCH 2/4] added alpha channel --- src/renderer/widgets/PasswordInputField.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index b9ae8138..a4dbd89d 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -30,7 +30,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u request.asset = placeholderText; request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT; request.props["font_family"] = std::string{"Sans"}; - request.props["color"] = CColor{placeholder_color.r,placeholder_color.g,placeholder_color.b,0.5}; + request.props["color"] = CColor{placeholder_color.r,placeholder_color.g,placeholder_color.b,placeholder_color.a}; request.props["font_size"] = (int)size.y / 4; g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); } From 759649031e074bb7f1ba2984af601b3b39461550 Mon Sep 17 00:00:00 2001 From: luyu-wu Date: Tue, 20 Feb 2024 18:12:28 -0500 Subject: [PATCH 3/4] fixed my mistakes in nix module --- nix/hm-module.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nix/hm-module.nix b/nix/hm-module.nix index 0353dbdb..738bf14d 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -116,14 +116,15 @@ in { }; placeholder_text = mkOption { - description = "The placeholder text color of the input field"; + description = "The placeholder text of the input field"; type = str; default = "Input Password..."; }; - font_color = mkOption { - description = "The font color of the input field"; + + placeholder_color = mkOption { + description = "The placeholder text color of the input field"; type = str; - default = "rgb(120, 120, 120)"; + default = "rgba(120, 120, 120,0.5)"; }; hide_input = mkOption { From c2066ce584403858cfa691b4fc2b69c46a458561 Mon Sep 17 00:00:00 2001 From: luyu-wu Date: Tue, 20 Feb 2024 19:58:24 -0500 Subject: [PATCH 4/4] fixed all my formatting mistakes i think --- src/renderer/widgets/PasswordInputField.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index a4dbd89d..52d34ba9 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -30,7 +30,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u request.asset = placeholderText; request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT; request.props["font_family"] = std::string{"Sans"}; - request.props["color"] = CColor{placeholder_color.r,placeholder_color.g,placeholder_color.b,placeholder_color.a}; + request.props["color"] = CColor(placeholder_color); request.props["font_size"] = (int)size.y / 4; g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request); }