mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
input-field: add halign valign and pos
This commit is contained in:
parent
80e6970e33
commit
3585324e4f
4 changed files with 16 additions and 19 deletions
|
@ -34,6 +34,9 @@ void CConfigManager::init() {
|
||||||
m_config.addSpecialConfigValue("input-field", "outline_thickness", Hyprlang::INT{4});
|
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", "fade_on_empty", Hyprlang::INT{1});
|
||||||
m_config.addSpecialConfigValue("input-field", "font_color", Hyprlang::INT{0xFF000000});
|
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.addSpecialCategory("label", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||||
m_config.addSpecialConfigValue("label", "monitor", Hyprlang::STRING{""});
|
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())},
|
{"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())},
|
{"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())},
|
{"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
|
// clang-format on
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../helpers/Vector2D.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class IWidget {
|
class IWidget {
|
||||||
public:
|
public:
|
||||||
struct SRenderData {
|
struct SRenderData {
|
||||||
float opacity = 1;
|
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);
|
||||||
};
|
};
|
|
@ -54,23 +54,7 @@ bool CLabel::draw(const SRenderData& data) {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// calc pos
|
// calc pos
|
||||||
if (halign == "center")
|
pos = posFromHVAlign(viewport, asset->texture.m_vSize, pos, halign, valign);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CBox box = {pos.x, pos.y, asset->texture.m_vSize.x, asset->texture.m_vSize.y};
|
CBox box = {pos.x, pos.y, asset->texture.m_vSize.x, asset->texture.m_vSize.y};
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
|
|
||||||
CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props) {
|
CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props) {
|
||||||
size = std::any_cast<Hyprlang::VEC2>(props.at("size"));
|
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"));
|
inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
|
||||||
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
|
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
|
||||||
out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
|
out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
|
||||||
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
|
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
|
||||||
font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
|
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() {
|
void CPasswordInputField::updateFade() {
|
||||||
|
|
Loading…
Reference in a new issue