input-field: add halign valign and pos

This commit is contained in:
Vaxry 2024-02-19 22:45:59 +00:00
parent 80e6970e33
commit 3585324e4f
4 changed files with 16 additions and 19 deletions

View file

@ -34,6 +34,9 @@ void CConfigManager::init() {
m_config.addSpecialConfigValue("input-field", "outline_thickness", Hyprlang::INT{4});
m_config.addSpecialConfigValue("input-field", "fade_on_empty", Hyprlang::INT{1});
m_config.addSpecialConfigValue("input-field", "font_color", Hyprlang::INT{0xFF000000});
m_config.addSpecialConfigValue("input-field", "halign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("input-field", "valign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("input-field", "position", Hyprlang::VEC2{0, -20});
m_config.addSpecialCategory("label", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
m_config.addSpecialConfigValue("label", "monitor", Hyprlang::STRING{""});
@ -91,6 +94,9 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
{"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", 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())},
{"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())},
{"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())},
}
});
// clang-format on

View file

@ -1,10 +1,15 @@
#pragma once
#include "../../helpers/Vector2D.hpp"
#include <string>
class IWidget {
public:
struct SRenderData {
float opacity = 1;
};
virtual bool draw(const SRenderData& data) = 0;
virtual bool draw(const SRenderData& data) = 0;
virtual Vector2D posFromHVAlign(const Vector2D& viewport, const Vector2D& size, const Vector2D& offset, const std::string& halign, const std::string& valign);
};

View file

@ -54,23 +54,7 @@ bool CLabel::draw(const SRenderData& data) {
return true;
// calc pos
if (halign == "center")
pos.x += viewport.x / 2.0 - asset->texture.m_vSize.x / 2.0;
else if (halign == "left")
pos.x += 0;
else if (halign == "right")
pos.x += viewport.x - asset->texture.m_vSize.x;
else if (halign != "none")
Debug::log(ERR, "Label: invalid halign {}", halign);
if (valign == "center")
pos.y += viewport.y / 2.0 - asset->texture.m_vSize.y / 2.0;
else if (valign == "top")
pos.y += viewport.y - asset->texture.m_vSize.y;
else if (valign == "bottom")
pos.y += asset->texture.m_vSize.y;
else if (valign != "none")
Debug::log(ERR, "Label: invalid halign {}", halign);
pos = posFromHVAlign(viewport, asset->texture.m_vSize, pos, halign, valign);
}
CBox box = {pos.x, pos.y, asset->texture.m_vSize.x, asset->texture.m_vSize.y};

View file

@ -5,12 +5,14 @@
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"));
pos = std::any_cast<Hyprlang::VEC2>(props.at("position"));
pos = posFromHVAlign(viewport, size, pos, std::any_cast<Hyprlang::STRING>(props.at("halign")), std::any_cast<Hyprlang::STRING>(props.at("valign")));
}
void CPasswordInputField::updateFade() {