From b1ffd735348038cd4fb29e728a58052330793b01 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 21 Feb 2024 11:42:18 +0000 Subject: [PATCH] input-field: add dots_center --- src/config/ConfigManager.cpp | 2 ++ src/renderer/widgets/PasswordInputField.cpp | 7 +++++-- src/renderer/widgets/PasswordInputField.hpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 7342127..517e776 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -34,6 +34,7 @@ void CConfigManager::init() { m_config.addSpecialConfigValue("input-field", "outer_color", Hyprlang::INT{0xFF111111}); m_config.addSpecialConfigValue("input-field", "outline_thickness", Hyprlang::INT{4}); m_config.addSpecialConfigValue("input-field", "dots_size", Hyprlang::FLOAT{0.25}); + m_config.addSpecialConfigValue("input-field", "dots_center", Hyprlang::INT{1}); m_config.addSpecialConfigValue("input-field", "dots_spacing", Hyprlang::FLOAT{0.2}); m_config.addSpecialConfigValue("input-field", "fade_on_empty", Hyprlang::INT{1}); m_config.addSpecialConfigValue("input-field", "font_color", Hyprlang::INT{0xFF000000}); @@ -99,6 +100,7 @@ std::vector CConfigManager::getWidgetConfigs() { {"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", k.c_str())}, {"dots_size", m_config.getSpecialConfigValue("input-field", "dots_size", k.c_str())}, {"dots_spacing", m_config.getSpecialConfigValue("input-field", "dots_spacing", k.c_str())}, + {"dots_center", m_config.getSpecialConfigValue("input-field", "dots_center", 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())}, {"halign", m_config.getSpecialConfigValue("input-field", "halign", k.c_str())}, diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index 056c803..df2042c 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -10,6 +10,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u out_thick = std::any_cast(props.at("outline_thickness")); dt_size = std::any_cast(props.at("dots_size")); dt_space = std::any_cast(props.at("dots_spacing")); + dots.center = std::any_cast(props.at("dots_center")); fadeOnEmpty = std::any_cast(props.at("fade_on_empty")); font = std::any_cast(props.at("font_color")); pos = std::any_cast(props.at("position")); @@ -138,14 +139,16 @@ bool CPasswordInputField::draw(const SRenderData& data) { const int PASS_SPACING = std::floor(PASS_SIZE * dt_space); if (!hiddenInputState.enabled) { + int xback = dots.center ? (PASS_SIZE + PASS_SPACING) * std::ceil(dots.currentAmount) / 2.0 - inputFieldBox.w / 2.0 + PASS_SPACING * 2 : 0; + for (size_t i = 0; i < std::floor(dots.currentAmount); ++i) { - Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 2, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * i, 0}; + Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 2 - xback, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * i, 0}; CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}}; g_pRenderer->renderRect(box, fontCol, PASS_SIZE / 2.0); } if (dots.currentAmount != std::floor(dots.currentAmount)) { - Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 2, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + + Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 2 - xback, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * std::floor(dots.currentAmount), 0}; CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}}; fontCol.a *= (dots.currentAmount - std::floor(dots.currentAmount)) * data.opacity; diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index 5369a97..ae4e8c1 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -36,6 +36,7 @@ class CPasswordInputField : public IWidget { float currentAmount = 0; float speedPerSecond = 5; // actually per... something. I am unsure xD std::chrono::system_clock::time_point lastFrame; + bool center = false; } dots; struct {