mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
inputField: minor cleanup
still anim sucks a bit
This commit is contained in:
parent
6a31b2f182
commit
013dfadee7
3 changed files with 36 additions and 35 deletions
|
@ -298,6 +298,8 @@ void CHyprlock::onKey(uint32_t key) {
|
||||||
|
|
||||||
if (RESULT.success)
|
if (RESULT.success)
|
||||||
unlockSession();
|
unlockSession();
|
||||||
|
|
||||||
|
m_sPasswordState.passBuffer = "";
|
||||||
} else {
|
} else {
|
||||||
char buf[16] = {0};
|
char buf[16] = {0};
|
||||||
int len = xkb_keysym_to_utf8(SYM, buf, 16);
|
int len = xkb_keysym_to_utf8(SYM, buf, 16);
|
||||||
|
|
|
@ -46,30 +46,24 @@ void CPasswordInputField::updateFade() {
|
||||||
void CPasswordInputField::updateDots() {
|
void CPasswordInputField::updateDots() {
|
||||||
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
||||||
|
|
||||||
size_t dotsAppearingOrPresent = std::count_if(dots.begin(), dots.end(), [](const auto& dot) { return dot.appearing || !dot.animated; });
|
if (PASSLEN == dots.currentAmount)
|
||||||
|
return;
|
||||||
|
|
||||||
if (dotsAppearingOrPresent < PASSLEN) {
|
const auto DELTA = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - dots.lastFrame).count();
|
||||||
dots.push_back(dot{.idx = dotsAppearingOrPresent + 1, .appearing = true, .animated = true, .a = 0, .start = std::chrono::system_clock::now()});
|
|
||||||
} else if (dotsAppearingOrPresent > PASSLEN) {
|
const float TOADD = DELTA / 1000000.0 * (dots.speedPerSecond * std::clamp(std::abs(PASSLEN - dots.currentAmount), 0.5f, INFINITY));
|
||||||
dots[dots.size() - 1].animated = true;
|
|
||||||
dots[dots.size() - 1].appearing = false;
|
if (PASSLEN > dots.currentAmount) {
|
||||||
dots[dots.size() - 1].start = std::chrono::system_clock::now();
|
dots.currentAmount += TOADD;
|
||||||
|
if (dots.currentAmount > PASSLEN)
|
||||||
|
dots.currentAmount = PASSLEN;
|
||||||
|
} else if (PASSLEN < dots.currentAmount) {
|
||||||
|
dots.currentAmount -= TOADD;
|
||||||
|
if (dots.currentAmount < PASSLEN)
|
||||||
|
dots.currentAmount = PASSLEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& dot : dots) {
|
dots.lastFrame = std::chrono::system_clock::now();
|
||||||
if (dot.appearing) {
|
|
||||||
if (dot.a < 1.0)
|
|
||||||
dot.a = std::clamp(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - dot.start).count() / 100000.0, 0.0, 1.0);
|
|
||||||
} else {
|
|
||||||
if (dot.a > 0.0)
|
|
||||||
dot.a = std::clamp(1.0 - std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - dot.start).count() / 100000.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dot.appearing && dot.a == 1.0)
|
|
||||||
dot.animated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::erase_if(dots, [](const auto& dot) { return !dot.appearing && dot.a == 0.0; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPasswordInputField::draw(const SRenderData& data) {
|
bool CPasswordInputField::draw(const SRenderData& data) {
|
||||||
|
@ -90,11 +84,20 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
||||||
constexpr int PASS_SPACING = 3;
|
constexpr int PASS_SPACING = 3;
|
||||||
constexpr int PASS_SIZE = 8;
|
constexpr int PASS_SIZE = 8;
|
||||||
|
|
||||||
for (size_t i = 0; i < dots.size(); ++i) {
|
for (size_t i = 0; i < std::floor(dots.currentAmount); ++i) {
|
||||||
Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * dots[i].idx, 0};
|
Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 2, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * i, 0};
|
||||||
CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}};
|
CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}};
|
||||||
g_pRenderer->renderRect(box, CColor{0, 0, 0, dots[i].a * data.opacity}, PASS_SIZE / 2.0);
|
g_pRenderer->renderRect(box, CColor{0, 0, 0, data.opacity}, PASS_SIZE / 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::ranges::any_of(dots.begin(), dots.end(), [](const auto& dot) { return dot.animated; }) || fade.animated;
|
if (dots.currentAmount != std::floor(dots.currentAmount)) {
|
||||||
|
Vector2D currentPos =
|
||||||
|
inputFieldBox.pos() + Vector2D{PASS_SPACING * 2, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * std::floor(dots.currentAmount), 0};
|
||||||
|
CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}};
|
||||||
|
g_pRenderer->renderRect(box, CColor{0, 0, 0, (dots.currentAmount - std::floor(dots.currentAmount)) * data.opacity}, PASS_SIZE / 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
||||||
|
|
||||||
|
return dots.currentAmount != PASSLEN || data.opacity < 1.0 || fade.a < 1.0;
|
||||||
}
|
}
|
|
@ -23,13 +23,11 @@ class CPasswordInputField : public IWidget {
|
||||||
|
|
||||||
CColor inner, outer;
|
CColor inner, outer;
|
||||||
|
|
||||||
struct dot {
|
struct {
|
||||||
size_t idx = 0;
|
float currentAmount = 0;
|
||||||
bool appearing = false;
|
float speedPerSecond = 5; // actually per... something. I am unsure xD
|
||||||
bool animated = false;
|
std::chrono::system_clock::time_point lastFrame;
|
||||||
float a = 0;
|
} dots;
|
||||||
std::chrono::system_clock::time_point start;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
std::chrono::system_clock::time_point start;
|
std::chrono::system_clock::time_point start;
|
||||||
|
@ -39,6 +37,4 @@ class CPasswordInputField : public IWidget {
|
||||||
} fade;
|
} fade;
|
||||||
|
|
||||||
bool fadeOnEmpty;
|
bool fadeOnEmpty;
|
||||||
|
|
||||||
std::vector<dot> dots;
|
|
||||||
};
|
};
|
Loading…
Reference in a new issue