mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-12-22 05:19:48 +01:00
input-field: add hide_input
This commit is contained in:
parent
843695b0b0
commit
6ff808cebf
3 changed files with 79 additions and 21 deletions
|
@ -39,6 +39,7 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("input-field", "valign", Hyprlang::STRING{"center"});
|
||||
m_config.addSpecialConfigValue("input-field", "position", Hyprlang::VEC2{0, -20});
|
||||
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.addSpecialCategory("label", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||
m_config.addSpecialConfigValue("label", "monitor", Hyprlang::STRING{""});
|
||||
|
@ -100,6 +101,7 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
{"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())},
|
||||
{"position", m_config.getSpecialConfigValue("input-field", "position", 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())},
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
|
|
|
@ -3,14 +3,16 @@
|
|||
#include "../../core/hyprlock.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props) {
|
||||
size = std::any_cast<Hyprlang::VEC2>(props.at("size"));
|
||||
inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
|
||||
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
|
||||
out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
|
||||
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
|
||||
font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
|
||||
pos = std::any_cast<Hyprlang::VEC2>(props.at("position"));
|
||||
CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props) {
|
||||
size = std::any_cast<Hyprlang::VEC2>(props.at("size"));
|
||||
inner = std::any_cast<Hyprlang::INT>(props.at("inner_color"));
|
||||
outer = std::any_cast<Hyprlang::INT>(props.at("outer_color"));
|
||||
out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
|
||||
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
|
||||
font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
|
||||
pos = std::any_cast<Hyprlang::VEC2>(props.at("position"));
|
||||
hiddenInputState.enabled = std::any_cast<Hyprlang::INT>(props.at("hide_input"));
|
||||
viewport = viewport_;
|
||||
|
||||
pos = posFromHVAlign(viewport, size, pos, std::any_cast<Hyprlang::STRING>(props.at("halign")), std::any_cast<Hyprlang::STRING>(props.at("valign")));
|
||||
|
||||
|
@ -96,6 +98,7 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
updateFade();
|
||||
updateDots();
|
||||
updateFailTex();
|
||||
updateHiddenInputState();
|
||||
|
||||
float passAlpha = g_pHyprlock->passwordCheckWaiting() ? 0.5 : 1.0;
|
||||
|
||||
|
@ -107,27 +110,45 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
fontCol.a *= fade.a * data.opacity * passAlpha;
|
||||
|
||||
g_pRenderer->renderRect(outerBox, outerCol, outerBox.h / 2.0);
|
||||
|
||||
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
||||
|
||||
if (PASSLEN != 0 && hiddenInputState.enabled) {
|
||||
CBox outerBoxScaled = outerBox;
|
||||
Vector2D p = outerBox.pos();
|
||||
outerBoxScaled.translate(-p).scale(0.5).translate(p);
|
||||
if (hiddenInputState.lastQuadrant > 1)
|
||||
outerBoxScaled.y += outerBoxScaled.h;
|
||||
if (hiddenInputState.lastQuadrant % 2 == 1)
|
||||
outerBoxScaled.x += outerBoxScaled.w;
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(outerBoxScaled.x, outerBoxScaled.y, outerBoxScaled.w, outerBoxScaled.h);
|
||||
g_pRenderer->renderRect(outerBox, hiddenInputState.lastColor, outerBox.h / 2.0);
|
||||
glScissor(0, 0, viewport.x, viewport.y);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
g_pRenderer->renderRect(inputFieldBox, innerCol, inputFieldBox.h / 2.0);
|
||||
|
||||
constexpr int PASS_SPACING = 3;
|
||||
constexpr int PASS_SIZE = 8;
|
||||
|
||||
for (size_t i = 0; i < std::floor(dots.currentAmount); ++i) {
|
||||
Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 4, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * i, 0};
|
||||
CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}};
|
||||
g_pRenderer->renderRect(box, fontCol, PASS_SIZE / 2.0);
|
||||
}
|
||||
if (!hiddenInputState.enabled) {
|
||||
for (size_t i = 0; i < std::floor(dots.currentAmount); ++i) {
|
||||
Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 4, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * i, 0};
|
||||
CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}};
|
||||
g_pRenderer->renderRect(box, fontCol, PASS_SIZE / 2.0);
|
||||
}
|
||||
|
||||
if (dots.currentAmount != std::floor(dots.currentAmount)) {
|
||||
Vector2D currentPos =
|
||||
inputFieldBox.pos() + Vector2D{PASS_SPACING * 4, 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}};
|
||||
fontCol.a = (dots.currentAmount - std::floor(dots.currentAmount)) * data.opacity;
|
||||
g_pRenderer->renderRect(box, fontCol, PASS_SIZE / 2.0);
|
||||
if (dots.currentAmount != std::floor(dots.currentAmount)) {
|
||||
Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 4, 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}};
|
||||
fontCol.a = (dots.currentAmount - std::floor(dots.currentAmount)) * data.opacity;
|
||||
g_pRenderer->renderRect(box, fontCol, PASS_SIZE / 2.0);
|
||||
}
|
||||
}
|
||||
|
||||
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
||||
|
||||
if (PASSLEN == 0 && !placeholder.resourceID.empty()) {
|
||||
SPreloadedAsset* currAsset = nullptr;
|
||||
|
||||
|
@ -186,3 +207,29 @@ void CPasswordInputField::updateFailTex() {
|
|||
|
||||
placeholder.canGetNewFail = false;
|
||||
}
|
||||
|
||||
void CPasswordInputField::updateHiddenInputState() {
|
||||
if (!hiddenInputState.enabled || (size_t)hiddenInputState.lastPasswordLength == g_pHyprlock->getPasswordBufferLen())
|
||||
return;
|
||||
|
||||
// randomize new thang
|
||||
hiddenInputState.lastPasswordLength = g_pHyprlock->getPasswordBufferLen();
|
||||
|
||||
float r1 = (rand() % 100) / 255.0;
|
||||
float r2 = (rand() % 100) / 255.0;
|
||||
int r3 = rand() % 3;
|
||||
int r4 = rand() % 2;
|
||||
int r5 = rand() % 2;
|
||||
|
||||
((float*)&hiddenInputState.lastColor.r)[r3] = r1 + 155 / 255.0;
|
||||
((float*)&hiddenInputState.lastColor.r)[(r3 + r4) % 3] = r2 + 155 / 255.0;
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (i != r3 && i != ((r3 + r4) % 3)) {
|
||||
((float*)&hiddenInputState.lastColor.r)[i] = 1.0 - ((float*)&hiddenInputState.lastColor.r)[r5 ? r3 : ((r3 + r4) % 3)];
|
||||
}
|
||||
}
|
||||
|
||||
hiddenInputState.lastColor.a = 1.0;
|
||||
hiddenInputState.lastQuadrant = (hiddenInputState.lastQuadrant + rand() % 3 + 1) % 4;
|
||||
}
|
||||
|
|
|
@ -20,9 +20,11 @@ class CPasswordInputField : public IWidget {
|
|||
void updateDots();
|
||||
void updateFade();
|
||||
void updateFailTex();
|
||||
void updateHiddenInputState();
|
||||
|
||||
Vector2D size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
|
||||
int out_thick;
|
||||
|
||||
|
@ -50,5 +52,12 @@ class CPasswordInputField : public IWidget {
|
|||
bool canGetNewFail = true;
|
||||
} placeholder;
|
||||
|
||||
struct {
|
||||
CColor lastColor;
|
||||
int lastQuadrant = 0;
|
||||
int lastPasswordLength = 0;
|
||||
bool enabled = false;
|
||||
} hiddenInputState;
|
||||
|
||||
bool fadeOnEmpty;
|
||||
};
|
Loading…
Reference in a new issue