Add placeholder color

This commit is contained in:
luyu-wu 2024-02-20 18:03:46 -05:00
parent 7b15d34f0a
commit 8f55ec8b41
4 changed files with 12 additions and 3 deletions

View file

@ -116,10 +116,15 @@ in {
};
placeholder_text = mkOption {
description = "The placeholder text of the input field";
description = "The placeholder text color of the input field";
type = str;
default = "<i>Input Password...</i>";
};
font_color = mkOption {
description = "The font color of the input field";
type = str;
default = "rgb(120, 120, 120)";
};
hide_input = mkOption {
description = "Hide input typed into the input field";

View file

@ -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});
@ -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())},
}
});

View file

@ -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_;
@ -21,6 +22,7 @@ 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;
@ -28,7 +30,7 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
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.r,placeholder_color.g,placeholder_color.b,0.5};
request.props["font_size"] = (int)size.y / 4;
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
}

View file

@ -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;