Skip to content

Commit

Permalink
input-field: fix alignment on multi-monitors (#175)
Browse files Browse the repository at this point in the history
* input-field: fix alignment on multi-monitors

* clang-format

* remove redundant
  • Loading branch information
bvr-yr authored Mar 11, 2024
1 parent ed26a6b commit 6027f12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/renderer/widgets/PasswordInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ 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"));
pos = {POS__.x, POS__.y};
configPos = pos;
auto POS__ = std::any_cast<Hyprlang::VEC2>(props.at("position"));
pos = {POS__.x, POS__.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 +168,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();
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 +187,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 6027f12

Please sign in to comment.