Skip to content

Commit

Permalink
input-field: check_color + some fixes (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvr-yr authored Mar 11, 2024
1 parent 21d9efe commit 6c9d6f0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 25 deletions.
7 changes: 7 additions & 0 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ in {
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 {
description = "If authentication failed, changes outer color and fail message color";
type = str;
Expand Down Expand Up @@ -432,6 +438,7 @@ in {
shadow_size = ${toString input-field.shadow_size}
shadow_color = ${input-field.shadow_color}
shadow_boost = ${toString input-field.shadow_boost}
check_color = ${input-field.check_color}
fail_color = ${input-field.fail_color}
fail_text = ${input-field.fail_text}
fail_transition = ${toString input-field.fail_transition}
Expand Down
3 changes: 3 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", "hide_input", Hyprlang::INT{0});
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_text", Hyprlang::STRING{"<i>$FAIL</i>"});
m_config.addSpecialConfigValue("input-field", "fail_transition", Hyprlang::INT{300});
Expand Down Expand Up @@ -168,6 +169,8 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
{"placeholder_text", m_config.getSpecialConfigValue("input-field", "placeholder_text", 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())},
{"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_text", m_config.getSpecialConfigValue("input-field", "fail_text", k.c_str())},
{"fail_transition", m_config.getSpecialConfigValue("input-field", "fail_transition", k.c_str())},
Expand Down
68 changes: 44 additions & 24 deletions src/renderer/widgets/PasswordInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
placeholder.failColor = std::any_cast<Hyprlang::INT>(props.at("fail_color"));
placeholder.failTransitionMs = std::any_cast<Hyprlang::INT>(props.at("fail_transition"));
configFailText = std::any_cast<Hyprlang::STRING>(props.at("fail_text"));
checkColor = std::any_cast<Hyprlang::INT>(props.at("check_color"));
viewport = viewport_;

auto POS__ = std::any_cast<Hyprlang::VEC2>(props.at("position"));
Expand Down Expand Up @@ -113,10 +114,10 @@ void CPasswordInputField::updateFade() {
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);

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;
redrawShadow = true;
}

redrawShadow = true;
}
}

Expand Down Expand Up @@ -168,13 +169,25 @@ bool CPasswordInputField::draw(const SRenderData& data) {

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);
TIMER = std::chrono::system_clock::now();
forceReload = true;

size.x += (TARGETSIZEX - ORIGSIZEX) * DELTA / 100000.0;

if (placeholder.failAsset && placeholder.failAsset->texture.m_vSize.x > ORIGSIZEX) {
if (placeholder.failAsset->texture.m_vSize.x > size.x)
redrawShadow = true;
if (size.x > TARGETSIZEX) {
size.x = TARGETSIZEX;
redrawShadow = true;
}
}

size.x = placeholder.failAsset->texture.m_vSize.x + inputFieldBox.h;
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
} else {
size.x = ORIGSIZEX;
pos = ORIGPOS;
Expand Down Expand Up @@ -283,12 +296,14 @@ bool CPasswordInputField::draw(const SRenderData& data) {
}

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;

if (g_pHyprlock->getPasswordBufferLen() != 0) {
if (PASSLEN != 0 || (WAITING && PASSLEN == 0)) {
if (placeholder.failAsset) {
g_pRenderer->asyncResourceGatherer->unloadAsset(placeholder.failAsset);
placeholder.failAsset = nullptr;
Expand Down Expand Up @@ -350,31 +365,36 @@ void CPasswordInputField::updateOuter() {
if (outThick == 0)
return;

static auto OUTERCOL = outer;
static auto TIMER = std::chrono::system_clock::now();
bool changeToOuter = placeholder.failID.empty();
static auto OUTERCOL = outer, CHANGETO = OUTERCOL;
static auto TIMER = std::chrono::system_clock::now();
const auto WAITING = g_pHyprlock->passwordCheckWaiting();
bool emptyFail = placeholder.failID.empty();

outerAnimated = false;

if (changeToOuter) {
if (outer == OUTERCOL)
if (emptyFail) {
CHANGETO = WAITING ? checkColor : OUTERCOL;

if (outer == CHANGETO)
return;

if (outer == placeholder.failColor)
if (outer == placeholder.failColor || (outer == OUTERCOL && WAITING))
TIMER = std::chrono::system_clock::now();
} else if (!changeToOuter) {
if (fade.animated || fade.a < 1.0)
changeToOuter = true;
} else if (!emptyFail) {
if (fade.animated || fade.a < 1.0) {
emptyFail = true;
CHANGETO = OUTERCOL;
}

if (outer == OUTERCOL)
if (outer == CHANGETO)
TIMER = std::chrono::system_clock::now();
}

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);
const auto DELTA = changeToOuter ? OUTERCOL - placeholder.failColor : placeholder.failColor - OUTERCOL;
const auto TARGET = changeToOuter ? OUTERCOL : placeholder.failColor;
const auto SOURCE = changeToOuter ? placeholder.failColor : OUTERCOL;
const auto DELTA = emptyFail ? CHANGETO - (WAITING ? OUTERCOL : placeholder.failColor) : placeholder.failColor - CHANGETO;
const auto TARGET = emptyFail ? CHANGETO : placeholder.failColor;
const auto SOURCE = emptyFail ? (WAITING ? OUTERCOL : placeholder.failColor) : CHANGETO;

if (outer.r != TARGET.r) {
outer.r += DELTA.r * MULTI;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/widgets/PasswordInputField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CPasswordInputField : public IWidget {

int outThick, rounding;

CColor inner, outer, font;
CColor inner, outer, font, checkColor;

struct {
float currentAmount = 0;
Expand Down

0 comments on commit 6c9d6f0

Please sign in to comment.