Skip to content

Commit

Permalink
input-field: add dots_center
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Feb 21, 2024
1 parent 5c7b23e commit b1ffd73
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void CConfigManager::init() {
m_config.addSpecialConfigValue("input-field", "outer_color", Hyprlang::INT{0xFF111111});
m_config.addSpecialConfigValue("input-field", "outline_thickness", Hyprlang::INT{4});
m_config.addSpecialConfigValue("input-field", "dots_size", Hyprlang::FLOAT{0.25});
m_config.addSpecialConfigValue("input-field", "dots_center", Hyprlang::INT{1});
m_config.addSpecialConfigValue("input-field", "dots_spacing", Hyprlang::FLOAT{0.2});
m_config.addSpecialConfigValue("input-field", "fade_on_empty", Hyprlang::INT{1});
m_config.addSpecialConfigValue("input-field", "font_color", Hyprlang::INT{0xFF000000});
Expand Down Expand Up @@ -99,6 +100,7 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
{"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", k.c_str())},
{"dots_size", m_config.getSpecialConfigValue("input-field", "dots_size", k.c_str())},
{"dots_spacing", m_config.getSpecialConfigValue("input-field", "dots_spacing", k.c_str())},
{"dots_center", m_config.getSpecialConfigValue("input-field", "dots_center", k.c_str())},
{"fade_on_empty", m_config.getSpecialConfigValue("input-field", "fade_on_empty", k.c_str())},
{"font_color", m_config.getSpecialConfigValue("input-field", "font_color", k.c_str())},
{"halign", m_config.getSpecialConfigValue("input-field", "halign", k.c_str())},
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/widgets/PasswordInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
out_thick = std::any_cast<Hyprlang::INT>(props.at("outline_thickness"));
dt_size = std::any_cast<Hyprlang::FLOAT>(props.at("dots_size"));
dt_space = std::any_cast<Hyprlang::FLOAT>(props.at("dots_spacing"));
dots.center = std::any_cast<Hyprlang::INT>(props.at("dots_center"));
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"));
Expand Down Expand Up @@ -138,14 +139,16 @@ bool CPasswordInputField::draw(const SRenderData& data) {
const int PASS_SPACING = std::floor(PASS_SIZE * dt_space);

if (!hiddenInputState.enabled) {
int xback = dots.center ? (PASS_SIZE + PASS_SPACING) * std::ceil(dots.currentAmount) / 2.0 - inputFieldBox.w / 2.0 + PASS_SPACING * 2 : 0;

for (size_t i = 0; i < std::floor(dots.currentAmount); ++i) {
Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 2, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} + Vector2D{(PASS_SIZE + PASS_SPACING) * i, 0};
Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 2 - xback, 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 * 2, inputFieldBox.h / 2.f - PASS_SIZE / 2.f} +
Vector2D currentPos = inputFieldBox.pos() + Vector2D{PASS_SPACING * 2 - xback, 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;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/widgets/PasswordInputField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CPasswordInputField : public IWidget {
float currentAmount = 0;
float speedPerSecond = 5; // actually per... something. I am unsure xD
std::chrono::system_clock::time_point lastFrame;
bool center = false;
} dots;

struct {
Expand Down

0 comments on commit b1ffd73

Please sign in to comment.