mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
input-field: dots improvements (#84)
* input-field: dots improvements * fix stuff
This commit is contained in:
parent
146965e7fb
commit
94ac7fef1a
1 changed files with 22 additions and 8 deletions
|
@ -135,24 +135,38 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
||||||
|
|
||||||
g_pRenderer->renderRect(inputFieldBox, innerCol, inputFieldBox.h / 2.0);
|
g_pRenderer->renderRect(inputFieldBox, innerCol, inputFieldBox.h / 2.0);
|
||||||
|
|
||||||
const int PASS_SIZE = std::nearbyint(inputFieldBox.h * dt_size * 0.5f) * 2.f;
|
const int PASS_SIZE = std::nearbyint(inputFieldBox.h * dt_size * 0.5f) * 2.f;
|
||||||
const int PASS_SPACING = std::floor(PASS_SIZE * dt_space);
|
const int PASS_SPACING = std::floor(PASS_SIZE * dt_space);
|
||||||
const int DOT_AREA_WIDTH = inputFieldBox.w - PASS_SPACING * 2; // avail width for dots
|
const int DOT_PAD = (inputFieldBox.h - PASS_SIZE) / 2;
|
||||||
const int MAX_DOTS = DOT_AREA_WIDTH / (PASS_SIZE + PASS_SPACING); // max amount of dots that can fit in the area
|
const int DOT_AREA_WIDTH = inputFieldBox.w - DOT_PAD * 2; // avail width for dots
|
||||||
|
const int MAX_DOTS = std::round(DOT_AREA_WIDTH * 1.0 / (PASS_SIZE + PASS_SPACING)); // max amount of dots that can fit in the area
|
||||||
|
const int DOT_FLOORED = std::floor(dots.currentAmount);
|
||||||
|
const float DOT_ALPHA = fontCol.a;
|
||||||
// Calculate the total width required for all dots including spaces between them
|
// Calculate the total width required for all dots including spaces between them
|
||||||
const int TOTAL_DOTS_WIDTH = (PASS_SIZE + PASS_SPACING) * dots.currentAmount - PASS_SPACING;
|
const int TOTAL_DOTS_WIDTH = (PASS_SIZE + PASS_SPACING) * dots.currentAmount - PASS_SPACING;
|
||||||
|
|
||||||
if (!hiddenInputState.enabled) {
|
if (!hiddenInputState.enabled) {
|
||||||
// Calculate starting x-position to ensure dots stay centered within the input field
|
// Calculate starting x-position to ensure dots stay centered within the input field
|
||||||
int xstart = dots.center ? (DOT_AREA_WIDTH - TOTAL_DOTS_WIDTH) / 2 : PASS_SPACING;
|
int xstart = dots.center ? (DOT_AREA_WIDTH - TOTAL_DOTS_WIDTH) / 2 + DOT_PAD : DOT_PAD;
|
||||||
|
|
||||||
// Clamp xstart to be no less than PASS_SPACING to avoid drawing outside
|
if (dots.currentAmount > MAX_DOTS)
|
||||||
xstart = std::max(xstart, PASS_SPACING);
|
xstart = (inputFieldBox.w + MAX_DOTS * (PASS_SIZE + PASS_SPACING) - PASS_SPACING - 2 * TOTAL_DOTS_WIDTH) / 2;
|
||||||
|
|
||||||
|
for (int i = 0; i < dots.currentAmount; ++i) {
|
||||||
|
if (i < DOT_FLOORED - MAX_DOTS)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (dots.currentAmount != DOT_FLOORED) {
|
||||||
|
if (i == DOT_FLOORED)
|
||||||
|
fontCol.a *= (dots.currentAmount - DOT_FLOORED) * data.opacity;
|
||||||
|
else if (i == DOT_FLOORED - MAX_DOTS)
|
||||||
|
fontCol.a *= (1 - dots.currentAmount + DOT_FLOORED) * data.opacity;
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < dots.currentAmount && i < MAX_DOTS; ++i) {
|
|
||||||
Vector2D dotPosition = inputFieldBox.pos() + Vector2D{xstart + i * (PASS_SIZE + PASS_SPACING), inputFieldBox.h / 2.f - PASS_SIZE / 2.f};
|
Vector2D dotPosition = inputFieldBox.pos() + Vector2D{xstart + i * (PASS_SIZE + PASS_SPACING), inputFieldBox.h / 2.f - PASS_SIZE / 2.f};
|
||||||
CBox box{dotPosition, Vector2D{PASS_SIZE, PASS_SIZE}};
|
CBox box{dotPosition, Vector2D{PASS_SIZE, PASS_SIZE}};
|
||||||
g_pRenderer->renderRect(box, fontCol, PASS_SIZE / 2.0);
|
g_pRenderer->renderRect(box, fontCol, PASS_SIZE / 2.0);
|
||||||
|
fontCol.a = DOT_ALPHA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue