input-field: cleanup props in constructor

This commit is contained in:
Vaxry 2024-02-19 22:39:13 +00:00
parent 05cd68e17d
commit 80e6970e33
4 changed files with 19 additions and 15 deletions

View file

@ -2,11 +2,16 @@
#include <cmath> #include <cmath>
#include <format> #include <format>
#include <hyprlang.hpp>
class Vector2D { class Vector2D {
public: public:
Vector2D(double, double); Vector2D(double, double);
Vector2D(); Vector2D();
Vector2D(const Hyprlang::VEC2& v) {
x = v.x;
y = v.y;
}
~Vector2D(); ~Vector2D();
double x = 0; double x = 0;

View file

@ -256,10 +256,7 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
widgets[surf].emplace_back( widgets[surf].emplace_back(
std::make_unique<CBackground>(surf->size, PATH.empty() ? "" : std::string{"background:"} + PATH, std::any_cast<Hyprlang::INT>(c.values.at("color")))); std::make_unique<CBackground>(surf->size, PATH.empty() ? "" : std::string{"background:"} + PATH, std::any_cast<Hyprlang::INT>(c.values.at("color"))));
} else if (c.type == "input-field") { } else if (c.type == "input-field") {
const auto SIZE = std::any_cast<Hyprlang::VEC2>(c.values.at("size")); widgets[surf].emplace_back(std::make_unique<CPasswordInputField>(surf->size, c.values));
widgets[surf].emplace_back(std::make_unique<CPasswordInputField>(
surf->size, Vector2D{SIZE.x, SIZE.y}, std::any_cast<Hyprlang::INT>(c.values.at("outer_color")), std::any_cast<Hyprlang::INT>(c.values.at("inner_color")),
std::any_cast<Hyprlang::INT>(c.values.at("outline_thickness")), std::any_cast<Hyprlang::INT>(c.values.at("fade_on_empty")), std::any_cast<Hyprlang::INT>(c.values.at("font_color"))));
} else if (c.type == "label") { } else if (c.type == "label") {
widgets[surf].emplace_back(std::make_unique<CLabel>(surf->size, c.values)); widgets[surf].emplace_back(std::make_unique<CLabel>(surf->size, c.values));
} }

View file

@ -3,14 +3,14 @@
#include "../../core/hyprlock.hpp" #include "../../core/hyprlock.hpp"
#include <algorithm> #include <algorithm>
CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const Vector2D& size_, const CColor& outer_, const CColor& inner_, int out_thick_, bool fadeEmpty, const CColor& font_) { CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props) {
size = size_; size = std::any_cast<Hyprlang::VEC2>(props.at("size"));
pos = viewport / 2.f - size_ / 2.f; pos = viewport / 2.f - size / 2.f;
inner = inner_; inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
outer = outer_; outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
out_thick = out_thick_; out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
fadeOnEmpty = fadeEmpty; fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
font = font_; font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
} }
void CPasswordInputField::updateFade() { void CPasswordInputField::updateFade() {

View file

@ -5,10 +5,12 @@
#include "../../helpers/Color.hpp" #include "../../helpers/Color.hpp"
#include <chrono> #include <chrono>
#include <vector> #include <vector>
#include <any>
#include <unordered_map>
class CPasswordInputField : public IWidget { class CPasswordInputField : public IWidget {
public: 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<std::string, std::any>& props);
virtual bool draw(const SRenderData& data); virtual bool draw(const SRenderData& data);