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 <format>
#include <hyprlang.hpp>
class Vector2D {
public:
Vector2D(double, double);
Vector2D();
Vector2D(const Hyprlang::VEC2& v) {
x = v.x;
y = v.y;
}
~Vector2D();
double x = 0;

View file

@ -256,10 +256,7 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
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"))));
} 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, 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"))));
widgets[surf].emplace_back(std::make_unique<CPasswordInputField>(surf->size, c.values));
} else if (c.type == "label") {
widgets[surf].emplace_back(std::make_unique<CLabel>(surf->size, c.values));
}

View file

@ -3,14 +3,14 @@
#include "../../core/hyprlock.hpp"
#include <algorithm>
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<std::string, std::any>& props) {
size = std::any_cast<Hyprlang::VEC2>(props.at("size"));
pos = viewport / 2.f - size / 2.f;
inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
}
void CPasswordInputField::updateFade() {

View file

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