From 05cd68e17da36042ebccb4fb73be648e84b3dda9 Mon Sep 17 00:00:00 2001 From: LOSEARDES77 <84414230+LOSEARDES77@users.noreply.github.com> Date: Mon, 19 Feb 2024 23:35:13 +0100 Subject: [PATCH] input-field: add font color config option (#11) --- src/config/ConfigManager.cpp | 2 ++ src/renderer/Renderer.cpp | 2 +- src/renderer/widgets/PasswordInputField.cpp | 10 +++++++--- src/renderer/widgets/PasswordInputField.hpp | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 5aa63ae..634cf62 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -33,6 +33,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", "fade_on_empty", Hyprlang::INT{1}); + m_config.addSpecialConfigValue("input-field", "font_color", Hyprlang::INT{0xFF000000}); m_config.addSpecialCategory("label", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true}); m_config.addSpecialConfigValue("label", "monitor", Hyprlang::STRING{""}); @@ -89,6 +90,7 @@ std::vector CConfigManager::getWidgetConfigs() { {"outer_color", m_config.getSpecialConfigValue("input-field", "outer_color", k.c_str())}, {"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", 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())}, } }); // clang-format on diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index 7884802..b95ddc1 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -259,7 +259,7 @@ std::vector>* CRenderer::getOrCreateWidgetsFor(const CS const auto SIZE = std::any_cast(c.values.at("size")); widgets[surf].emplace_back(std::make_unique( surf->size, Vector2D{SIZE.x, SIZE.y}, std::any_cast(c.values.at("outer_color")), std::any_cast(c.values.at("inner_color")), - std::any_cast(c.values.at("outline_thickness")), std::any_cast(c.values.at("fade_on_empty")))); + std::any_cast(c.values.at("outline_thickness")), std::any_cast(c.values.at("fade_on_empty")), std::any_cast(c.values.at("font_color")))); } else if (c.type == "label") { widgets[surf].emplace_back(std::make_unique(surf->size, c.values)); } diff --git a/src/renderer/widgets/PasswordInputField.cpp b/src/renderer/widgets/PasswordInputField.cpp index c53a9da..b8627a4 100644 --- a/src/renderer/widgets/PasswordInputField.cpp +++ b/src/renderer/widgets/PasswordInputField.cpp @@ -3,13 +3,14 @@ #include "../../core/hyprlock.hpp" #include -CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const Vector2D& size_, const CColor& outer_, const CColor& inner_, int out_thick_, bool fadeEmpty) { +CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const Vector2D& size_, const CColor& outer_, const CColor& inner_, int out_thick_, bool fadeEmpty, const CColor& font_) { size = size_; pos = viewport / 2.f - size_ / 2.f; inner = inner_; outer = outer_; out_thick = out_thick_; fadeOnEmpty = fadeEmpty; + font = font_; } void CPasswordInputField::updateFade() { @@ -87,14 +88,17 @@ bool CPasswordInputField::draw(const SRenderData& data) { 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}; CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}}; - g_pRenderer->renderRect(box, CColor{0, 0, 0, data.opacity}, PASS_SIZE / 2.0); + CColor fontCol = font; + 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{(PASS_SIZE + PASS_SPACING) * std::floor(dots.currentAmount), 0}; CBox box{currentPos, Vector2D{PASS_SIZE, PASS_SIZE}}; - g_pRenderer->renderRect(box, CColor{0, 0, 0, (dots.currentAmount - std::floor(dots.currentAmount)) * data.opacity}, PASS_SIZE / 2.0); + CColor fontCol = font; + 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(); diff --git a/src/renderer/widgets/PasswordInputField.hpp b/src/renderer/widgets/PasswordInputField.hpp index ecce39a..942e1e7 100644 --- a/src/renderer/widgets/PasswordInputField.hpp +++ b/src/renderer/widgets/PasswordInputField.hpp @@ -8,7 +8,7 @@ class CPasswordInputField : public IWidget { public: - CPasswordInputField(const Vector2D& viewport, const Vector2D& size, const CColor& outer, const CColor& inner, int out_thick, bool fade_empty); + CPasswordInputField(const Vector2D& viewport, const Vector2D& size, const CColor& outer, const CColor& inner, int out_thick, bool fade_empty, const CColor& font); virtual bool draw(const SRenderData& data); @@ -21,7 +21,7 @@ class CPasswordInputField : public IWidget { int out_thick; - CColor inner, outer; + CColor inner, outer, font; struct { float currentAmount = 0;