Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add placeholder_color #35

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ in {
default = "<i>Input Password...</i>";
};

placeholder_color = mkOption {
description = "The placeholder text color of the input field";
type = str;
default = "rgba(120, 120, 120,0.5)";
};

hide_input = mkOption {
description = "Hide input typed into the input field";
type = bool;
Expand Down
2 changes: 2 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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", "placeholder_color", Hyprlang::INT{0xFF000000});
m_config.addSpecialConfigValue("input-field", "hide_input", Hyprlang::INT{0});

m_config.addSpecialCategory("label", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
Expand Down Expand Up @@ -105,6 +106,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())},
{"placeholder_color", m_config.getSpecialConfigValue("input-field", "placeholder_color", k.c_str())},
{"hide_input", m_config.getSpecialConfigValue("input-field", "hide_input", k.c_str())},
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/widgets/PasswordInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
dt_space = std::any_cast<Hyprlang::FLOAT>(props.at("dots_spacing"));
fadeOnEmpty = std::any_cast<Hyprlang::INT>(props.at("fade_on_empty"));
font = std::any_cast<Hyprlang::INT>(props.at("font_color"));
placeholder_color = std::any_cast<Hyprlang::INT>(props.at("placeholder_color"));
pos = std::any_cast<Hyprlang::VEC2>(props.at("position"));
hiddenInputState.enabled = std::any_cast<Hyprlang::INT>(props.at("hide_input"));
viewport = viewport_;
Expand All @@ -21,14 +22,15 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
dt_space = std::clamp(dt_space, 0.f, 1.f);

std::string placeholderText = std::any_cast<Hyprlang::STRING>(props.at("placeholder_text"));

if (!placeholderText.empty()) {
placeholder.resourceID = "placeholder:" + std::to_string((uintptr_t)this);
CAsyncResourceGatherer::SPreloadRequest request;
request.id = placeholder.resourceID;
request.asset = placeholderText;
request.type = CAsyncResourceGatherer::eTargetType::TARGET_TEXT;
request.props["font_family"] = std::string{"Sans"};
request.props["color"] = CColor{1.0 - font.r, 1.0 - font.g, 1.0 - font.b, 0.5};
request.props["color"] = CColor(placeholder_color);
request.props["font_size"] = (int)size.y / 4;
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
}
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 @@ -30,7 +30,7 @@ class CPasswordInputField : public IWidget {

int out_thick;

CColor inner, outer, font;
CColor inner, outer, font, placeholder_color;

struct {
float currentAmount = 0;
Expand Down