input-field: check_color + some fixes (#172)

This commit is contained in:
bvr-yr 2024-03-11 18:17:14 +03:00 committed by GitHub
parent 21d9efe5c9
commit 6c9d6f05a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 25 deletions

View file

@ -261,6 +261,12 @@ in {
default = -1; default = -1;
}; };
check_color = mkOption {
description = "The outer color of the input field while checking password";
type = str;
default = "rgb(204, 136, 34)";
};
fail_color = mkOption { fail_color = mkOption {
description = "If authentication failed, changes outer color and fail message color"; description = "If authentication failed, changes outer color and fail message color";
type = str; type = str;
@ -432,6 +438,7 @@ in {
shadow_size = ${toString input-field.shadow_size} shadow_size = ${toString input-field.shadow_size}
shadow_color = ${input-field.shadow_color} shadow_color = ${input-field.shadow_color}
shadow_boost = ${toString input-field.shadow_boost} shadow_boost = ${toString input-field.shadow_boost}
check_color = ${input-field.check_color}
fail_color = ${input-field.fail_color} fail_color = ${input-field.fail_color}
fail_text = ${input-field.fail_text} fail_text = ${input-field.fail_text}
fail_transition = ${toString input-field.fail_transition} fail_transition = ${toString input-field.fail_transition}

View file

@ -78,6 +78,7 @@ void CConfigManager::init() {
m_config.addSpecialConfigValue("input-field", "placeholder_text", Hyprlang::STRING{"<i>Input Password</i>"}); m_config.addSpecialConfigValue("input-field", "placeholder_text", Hyprlang::STRING{"<i>Input Password</i>"});
m_config.addSpecialConfigValue("input-field", "hide_input", Hyprlang::INT{0}); m_config.addSpecialConfigValue("input-field", "hide_input", Hyprlang::INT{0});
m_config.addSpecialConfigValue("input-field", "rounding", Hyprlang::INT{-1}); m_config.addSpecialConfigValue("input-field", "rounding", Hyprlang::INT{-1});
m_config.addSpecialConfigValue("input-field", "check_color", Hyprlang::INT{0xFFCC8822});
m_config.addSpecialConfigValue("input-field", "fail_color", Hyprlang::INT{0xFFCC2222}); m_config.addSpecialConfigValue("input-field", "fail_color", Hyprlang::INT{0xFFCC2222});
m_config.addSpecialConfigValue("input-field", "fail_text", Hyprlang::STRING{"<i>$FAIL</i>"}); m_config.addSpecialConfigValue("input-field", "fail_text", Hyprlang::STRING{"<i>$FAIL</i>"});
m_config.addSpecialConfigValue("input-field", "fail_transition", Hyprlang::INT{300}); m_config.addSpecialConfigValue("input-field", "fail_transition", Hyprlang::INT{300});
@ -168,6 +169,8 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
{"placeholder_text", m_config.getSpecialConfigValue("input-field", "placeholder_text", k.c_str())}, {"placeholder_text", m_config.getSpecialConfigValue("input-field", "placeholder_text", k.c_str())},
{"hide_input", m_config.getSpecialConfigValue("input-field", "hide_input", k.c_str())}, {"hide_input", m_config.getSpecialConfigValue("input-field", "hide_input", k.c_str())},
{"rounding", m_config.getSpecialConfigValue("input-field", "rounding", k.c_str())}, {"rounding", m_config.getSpecialConfigValue("input-field", "rounding", k.c_str())},
{"rounding", m_config.getSpecialConfigValue("input-field", "rounding", k.c_str())},
{"check_color", m_config.getSpecialConfigValue("input-field", "check_color", k.c_str())},
{"fail_color", m_config.getSpecialConfigValue("input-field", "fail_color", k.c_str())}, {"fail_color", m_config.getSpecialConfigValue("input-field", "fail_color", k.c_str())},
{"fail_text", m_config.getSpecialConfigValue("input-field", "fail_text", k.c_str())}, {"fail_text", m_config.getSpecialConfigValue("input-field", "fail_text", k.c_str())},
{"fail_transition", m_config.getSpecialConfigValue("input-field", "fail_transition", k.c_str())}, {"fail_transition", m_config.getSpecialConfigValue("input-field", "fail_transition", k.c_str())},

View file

@ -20,6 +20,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
placeholder.failColor = std::any_cast<Hyprlang::INT>(props.at("fail_color")); placeholder.failColor = std::any_cast<Hyprlang::INT>(props.at("fail_color"));
placeholder.failTransitionMs = std::any_cast<Hyprlang::INT>(props.at("fail_transition")); placeholder.failTransitionMs = std::any_cast<Hyprlang::INT>(props.at("fail_transition"));
configFailText = std::any_cast<Hyprlang::STRING>(props.at("fail_text")); configFailText = std::any_cast<Hyprlang::STRING>(props.at("fail_text"));
checkColor = std::any_cast<Hyprlang::INT>(props.at("check_color"));
viewport = viewport_; viewport = viewport_;
auto POS__ = std::any_cast<Hyprlang::VEC2>(props.at("position")); auto POS__ = std::any_cast<Hyprlang::VEC2>(props.at("position"));
@ -113,10 +114,10 @@ void CPasswordInputField::updateFade() {
else else
fade.a = std::clamp(1.0 - std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - fade.start).count() / 100000.0, 0.0, 1.0); fade.a = std::clamp(1.0 - std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - fade.start).count() / 100000.0, 0.0, 1.0);
if ((fade.appearing && fade.a == 1.0) || (!fade.appearing && fade.a == 0.0)) { if ((fade.appearing && fade.a == 1.0) || (!fade.appearing && fade.a == 0.0))
fade.animated = false; fade.animated = false;
redrawShadow = true;
} redrawShadow = true;
} }
} }
@ -168,13 +169,25 @@ bool CPasswordInputField::draw(const SRenderData& data) {
static auto ORIGSIZEX = size.x; static auto ORIGSIZEX = size.x;
static auto ORIGPOS = pos; static auto ORIGPOS = pos;
static auto TIMER = std::chrono::system_clock::now();
if (placeholder.failAsset && placeholder.failAsset->texture.m_vSize.x > ORIGSIZEX) { if (placeholder.failAsset) {
if (placeholder.failAsset->texture.m_vSize.x > size.x) const auto TARGETSIZEX = placeholder.failAsset->texture.m_vSize.x + inputFieldBox.h;
redrawShadow = true;
size.x = placeholder.failAsset->texture.m_vSize.x + inputFieldBox.h; if (size.x < TARGETSIZEX) {
pos = posFromHVAlign(viewport, size, configPos, halign, valign); const auto DELTA = std::clamp((int)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - TIMER).count(), 1000, 20000);
TIMER = std::chrono::system_clock::now();
forceReload = true;
size.x += (TARGETSIZEX - ORIGSIZEX) * DELTA / 100000.0;
if (size.x > TARGETSIZEX) {
size.x = TARGETSIZEX;
redrawShadow = true;
}
}
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
} else { } else {
size.x = ORIGSIZEX; size.x = ORIGSIZEX;
pos = ORIGPOS; pos = ORIGPOS;
@ -283,12 +296,14 @@ bool CPasswordInputField::draw(const SRenderData& data) {
} }
void CPasswordInputField::updateFailTex() { void CPasswordInputField::updateFailTex() {
const auto FAIL = g_pHyprlock->passwordLastFailReason(); const auto FAIL = g_pHyprlock->passwordLastFailReason();
const auto WAITING = g_pHyprlock->passwordCheckWaiting();
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
if (g_pHyprlock->passwordCheckWaiting()) if (WAITING)
placeholder.canGetNewFail = true; placeholder.canGetNewFail = true;
if (g_pHyprlock->getPasswordBufferLen() != 0) { if (PASSLEN != 0 || (WAITING && PASSLEN == 0)) {
if (placeholder.failAsset) { if (placeholder.failAsset) {
g_pRenderer->asyncResourceGatherer->unloadAsset(placeholder.failAsset); g_pRenderer->asyncResourceGatherer->unloadAsset(placeholder.failAsset);
placeholder.failAsset = nullptr; placeholder.failAsset = nullptr;
@ -350,31 +365,36 @@ void CPasswordInputField::updateOuter() {
if (outThick == 0) if (outThick == 0)
return; return;
static auto OUTERCOL = outer; static auto OUTERCOL = outer, CHANGETO = OUTERCOL;
static auto TIMER = std::chrono::system_clock::now(); static auto TIMER = std::chrono::system_clock::now();
bool changeToOuter = placeholder.failID.empty(); const auto WAITING = g_pHyprlock->passwordCheckWaiting();
bool emptyFail = placeholder.failID.empty();
outerAnimated = false; outerAnimated = false;
if (changeToOuter) { if (emptyFail) {
if (outer == OUTERCOL) CHANGETO = WAITING ? checkColor : OUTERCOL;
if (outer == CHANGETO)
return; return;
if (outer == placeholder.failColor) if (outer == placeholder.failColor || (outer == OUTERCOL && WAITING))
TIMER = std::chrono::system_clock::now(); TIMER = std::chrono::system_clock::now();
} else if (!changeToOuter) { } else if (!emptyFail) {
if (fade.animated || fade.a < 1.0) if (fade.animated || fade.a < 1.0) {
changeToOuter = true; emptyFail = true;
CHANGETO = OUTERCOL;
}
if (outer == OUTERCOL) if (outer == CHANGETO)
TIMER = std::chrono::system_clock::now(); TIMER = std::chrono::system_clock::now();
} }
const auto MULTI = std::clamp( const auto MULTI = std::clamp(
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - TIMER).count() / (double)placeholder.failTransitionMs, 0.001, 0.5); std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - TIMER).count() / (double)placeholder.failTransitionMs, 0.001, 0.5);
const auto DELTA = changeToOuter ? OUTERCOL - placeholder.failColor : placeholder.failColor - OUTERCOL; const auto DELTA = emptyFail ? CHANGETO - (WAITING ? OUTERCOL : placeholder.failColor) : placeholder.failColor - CHANGETO;
const auto TARGET = changeToOuter ? OUTERCOL : placeholder.failColor; const auto TARGET = emptyFail ? CHANGETO : placeholder.failColor;
const auto SOURCE = changeToOuter ? placeholder.failColor : OUTERCOL; const auto SOURCE = emptyFail ? (WAITING ? OUTERCOL : placeholder.failColor) : CHANGETO;
if (outer.r != TARGET.r) { if (outer.r != TARGET.r) {
outer.r += DELTA.r * MULTI; outer.r += DELTA.r * MULTI;

View file

@ -39,7 +39,7 @@ class CPasswordInputField : public IWidget {
int outThick, rounding; int outThick, rounding;
CColor inner, outer, font; CColor inner, outer, font, checkColor;
struct { struct {
float currentAmount = 0; float currentAmount = 0;