Skip to content

Commit

Permalink
input-field: fix alignment on multi-monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
bvr-yr committed Mar 11, 2024
1 parent ed26a6b commit 369ffe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/renderer/widgets/PasswordInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <algorithm>

CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props) : shadow(this, props, viewport_) {
size = std::any_cast<Hyprlang::VEC2>(props.at("size"));
inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
outThick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
Expand All @@ -23,9 +22,12 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
checkColor = std::any_cast<Hyprlang::INT>(props.at("check_color"));
viewport = viewport_;

auto POS__ = std::any_cast<Hyprlang::VEC2>(props.at("position"));
auto POS__ = std::any_cast<Hyprlang::VEC2>(props.at("position"));
auto SIZE__ = std::any_cast<Hyprlang::VEC2>(props.at("size"));
pos = {POS__.x, POS__.y};
size = {SIZE__.x, SIZE__.y};
configPos = pos;
configSize = size;

halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
Expand Down Expand Up @@ -167,19 +169,17 @@ bool CPasswordInputField::draw(const SRenderData& data) {
updateOuter();
updateHiddenInputState();

static auto ORIGSIZEX = size.x;
static auto ORIGPOS = pos;
static auto TIMER = std::chrono::system_clock::now();

if (placeholder.failAsset) {
const auto TARGETSIZEX = placeholder.failAsset->texture.m_vSize.x + inputFieldBox.h;

if (size.x < TARGETSIZEX) {
const auto DELTA = std::clamp((int)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - TIMER).count(), 1000, 20000);
const auto DELTA = std::clamp((int)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - TIMER).count(), 8000, 20000);
TIMER = std::chrono::system_clock::now();
forceReload = true;

size.x += (TARGETSIZEX - ORIGSIZEX) * DELTA / 100000.0;
size.x += std::clamp((TARGETSIZEX - size.x) * DELTA / 100000.0, 1.0, 1000.0);

if (size.x > TARGETSIZEX) {
size.x = TARGETSIZEX;
Expand All @@ -188,9 +188,9 @@ bool CPasswordInputField::draw(const SRenderData& data) {
}

pos = posFromHVAlign(viewport, size, configPos, halign, valign);
} else {
size.x = ORIGSIZEX;
pos = ORIGPOS;
} else if (size.x != configSize.x) {
size.x = configSize.x;
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
}

SRenderData shadowData = data;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/widgets/PasswordInputField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CPasswordInputField : public IWidget {
Vector2D pos;
Vector2D viewport;
Vector2D configPos;
Vector2D configSize;

std::string halign, valign, configFailText;

Expand Down

0 comments on commit 369ffe3

Please sign in to comment.