From 49ef1d306c92bbfef057272ae0bdefe8aea8d0c7 Mon Sep 17 00:00:00 2001 From: matteo4375 <160355435+matteo4375@users.noreply.github.com> Date: Sun, 3 Mar 2024 20:54:27 -0500 Subject: [PATCH] input-field: Add rounding option (#127) * input-field: add rounding option * add rounding option to nix home manager module --- nix/hm-module.nix | 6 ++++++ src/config/ConfigManager.cpp | 2 ++ src/renderer/widgets/PasswordInputField.cpp | 7 ++++--- src/renderer/widgets/PasswordInputField.hpp | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/nix/hm-module.nix b/nix/hm-module.nix index fb80028..02fd10e 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -217,6 +217,12 @@ in { default = false; }; + rounding = mkOption { + description = "The rounding of the input field"; + type = int; + default = -1; + }; + position = { x = mkOption { description = "X position of the label"; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 6486410..7761a7d 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -68,6 +68,7 @@ void CConfigManager::init() { 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", "hide_input", Hyprlang::INT{0}); + m_config.addSpecialConfigValue("input-field", "rounding", Hyprlang::INT{-1}); m_config.addSpecialCategory("label", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true}); m_config.addSpecialConfigValue("label", "monitor", Hyprlang::STRING{""}); @@ -142,6 +143,7 @@ std::vector CConfigManager::getWidgetConfigs() { {"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())}, {"placeholder_text", m_config.getSpecialConfigValue("input-field", "placeholder_text", k.c_str())}, {"hide_input", m_config.getSpecialConfigValue("input-field", "hide_input", k.c_str())}, + {"rounding", m_config.getSpecialConfigValue("input-field", "rounding", k.c_str())}, } }); // clang-format on diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index c5c33e5..208b84c 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -15,6 +15,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u font = std::any_cast(props.at("font_color")); pos = std::any_cast(props.at("position")); hiddenInputState.enabled = std::any_cast(props.at("hide_input")); + rounding = std::any_cast(props.at("rounding")); viewport = viewport_; pos = posFromHVAlign(viewport, size, pos, std::any_cast(props.at("halign")), std::any_cast(props.at("valign"))); @@ -119,7 +120,7 @@ bool CPasswordInputField::draw(const SRenderData& data) { CColor fontCol = font; fontCol.a *= fade.a * data.opacity * passAlpha; - g_pRenderer->renderRect(outerBox, outerCol, outerBox.h / 2.0); + g_pRenderer->renderRect(outerBox, outerCol, rounding == -1 ? outerBox.h / 2.0 : rounding); const auto PASSLEN = g_pHyprlock->getPasswordBufferLen(); @@ -133,12 +134,12 @@ bool CPasswordInputField::draw(const SRenderData& data) { outerBoxScaled.x += outerBoxScaled.w; glEnable(GL_SCISSOR_TEST); glScissor(outerBoxScaled.x, outerBoxScaled.y, outerBoxScaled.w, outerBoxScaled.h); - g_pRenderer->renderRect(outerBox, hiddenInputState.lastColor, outerBox.h / 2.0); + g_pRenderer->renderRect(outerBox, hiddenInputState.lastColor, rounding == -1 ? outerBox.h / 2.0 : rounding); glScissor(0, 0, viewport.x, viewport.y); glDisable(GL_SCISSOR_TEST); } - g_pRenderer->renderRect(inputFieldBox, innerCol, inputFieldBox.h / 2.0); + g_pRenderer->renderRect(inputFieldBox, innerCol, rounding == -1 ? inputFieldBox.h / 2.0 : rounding - out_thick); const int PASS_SIZE = std::nearbyint(inputFieldBox.h * dt_size * 0.5f) * 2.f; const int PASS_SPACING = std::floor(PASS_SIZE * dt_space); diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index ae4e8c1..6ec548b 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -63,4 +63,5 @@ class CPasswordInputField : public IWidget { } hiddenInputState; bool fadeOnEmpty; + int rounding; };