From 6027f12d3be3ffa5c60edfedebe8abb6836161f4 Mon Sep 17 00:00:00 2001 From: bvr-yr <130279855+bvr-yr@users.noreply.github.com> Date: Mon, 11 Mar 2024 21:14:12 +0300 Subject: [PATCH] input-field: fix alignment on multi-monitors (#175) * input-field: fix alignment on multi-monitors * clang-format * remove redundant --- src/renderer/widgets/PasswordInputField.cpp | 21 ++++++++++----------- src/renderer/widgets/PasswordInputField.hpp | 1 + 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index c76d88b..658249f 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -23,9 +23,10 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u checkColor = std::any_cast(props.at("check_color")); viewport = viewport_; - auto POS__ = std::any_cast(props.at("position")); - pos = {POS__.x, POS__.y}; - configPos = pos; + auto POS__ = std::any_cast(props.at("position")); + pos = {POS__.x, POS__.y}; + configPos = pos; + configSize = size; halign = std::any_cast(props.at("halign")); valign = std::any_cast(props.at("valign")); @@ -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::system_clock::now() - TIMER).count(), 1000, 20000); + const auto DELTA = std::clamp((int)std::chrono::duration_cast(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; @@ -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; diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index 62d1365..45d636a 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -34,6 +34,7 @@ class CPasswordInputField : public IWidget { Vector2D pos; Vector2D viewport; Vector2D configPos; + Vector2D configSize; std::string halign, valign, configFailText;