From 80e6970e331ee10adc0acc4fa4d91fdb7e958700 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 19 Feb 2024 22:39:13 +0000 Subject: [PATCH] input-field: cleanup props in constructor --- src/helpers/Vector2D.hpp | 5 +++++ src/renderer/Renderer.cpp | 5 +---- src/renderer/widgets/PasswordInputField.cpp | 20 ++++++++++---------- src/renderer/widgets/PasswordInputField.hpp | 4 +++- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp index 0c2b9ce..cf551fb 100644 --- a/src/helpers/Vector2D.hpp +++ b/src/helpers/Vector2D.hpp @@ -2,11 +2,16 @@ #include #include +#include class Vector2D { public: Vector2D(double, double); Vector2D(); + Vector2D(const Hyprlang::VEC2& v) { + x = v.x; + y = v.y; + } ~Vector2D(); double x = 0; diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index b95ddc1..ae08d61 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -256,10 +256,7 @@ std::vector>* CRenderer::getOrCreateWidgetsFor(const CS widgets[surf].emplace_back( std::make_unique(surf->size, PATH.empty() ? "" : std::string{"background:"} + PATH, std::any_cast(c.values.at("color")))); } else if (c.type == "input-field") { - const auto SIZE = std::any_cast(c.values.at("size")); - widgets[surf].emplace_back(std::make_unique( - surf->size, Vector2D{SIZE.x, SIZE.y}, std::any_cast(c.values.at("outer_color")), std::any_cast(c.values.at("inner_color")), - std::any_cast(c.values.at("outline_thickness")), std::any_cast(c.values.at("fade_on_empty")), std::any_cast(c.values.at("font_color")))); + widgets[surf].emplace_back(std::make_unique(surf->size, c.values)); } else if (c.type == "label") { widgets[surf].emplace_back(std::make_unique(surf->size, c.values)); } diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index b8627a4..b544575 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -3,14 +3,14 @@ #include "../../core/hyprlock.hpp" #include -CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const Vector2D& size_, const CColor& outer_, const CColor& inner_, int out_thick_, bool fadeEmpty, const CColor& font_) { - size = size_; - pos = viewport / 2.f - size_ / 2.f; - inner = inner_; - outer = outer_; - out_thick = out_thick_; - fadeOnEmpty = fadeEmpty; - font = font_; +CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::unordered_map& props) { + size = std::any_cast(props.at("size")); + pos = viewport / 2.f - size / 2.f; + inner = std::any_cast(props.at("inner_color")); + 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")); } void CPasswordInputField::updateFade() { @@ -88,14 +88,14 @@ bool CPasswordInputField::draw(const SRenderData& data) { 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}; CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}}; - CColor fontCol = font; + CColor fontCol = font; 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{(PASS_SIZE + PASS_SPACING) * std::floor(dots.currentAmount), 0}; - CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}}; + CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}}; CColor fontCol = font; fontCol.a = (dots.currentAmount - std::floor(dots.currentAmount)) * data.opacity; g_pRenderer->renderRect(box, fontCol, PASS_SIZE / 2.0); diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index 942e1e7..de7ad7a 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -5,10 +5,12 @@ #include "../../helpers/Color.hpp" #include #include +#include +#include class CPasswordInputField : public IWidget { public: - CPasswordInputField(const Vector2D& viewport, const Vector2D& size, const CColor& outer, const CColor& inner, int out_thick, bool fade_empty, const CColor& font); + CPasswordInputField(const Vector2D& viewport, const std::unordered_map& props); virtual bool draw(const SRenderData& data);