From 8f55ec8b413b341b9fe215a30d04c8c88700838e Mon Sep 17 00:00:00 2001 From: luyu-wu Date: Tue, 20 Feb 2024 18:03:46 -0500 Subject: [PATCH] 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 13564b8..0353dbd 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 7342127..854cf3f 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 056c803..b9ae813 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 5369a97..bcdfb19 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;