mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
input-field: add placeholder
This commit is contained in:
parent
3585324e4f
commit
c60b7b8aef
3 changed files with 34 additions and 0 deletions
|
@ -37,6 +37,7 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("input-field", "halign", Hyprlang::STRING{"center"});
|
||||
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.addSpecialCategory("label", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||
m_config.addSpecialConfigValue("label", "monitor", Hyprlang::STRING{""});
|
||||
|
@ -97,6 +98,7 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
|||
{"halign", m_config.getSpecialConfigValue("input-field", "halign", k.c_str())},
|
||||
{"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())},
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
|
|
|
@ -13,6 +13,19 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport, const std::un
|
|||
pos = std::any_cast<Hyprlang::VEC2>(props.at("position"));
|
||||
|
||||
pos = posFromHVAlign(viewport, size, pos, std::any_cast<Hyprlang::STRING>(props.at("halign")), std::any_cast<Hyprlang::STRING>(props.at("valign")));
|
||||
|
||||
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["font_size"] = 12;
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
}
|
||||
|
||||
void CPasswordInputField::updateFade() {
|
||||
|
@ -105,5 +118,17 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
|
||||
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
||||
|
||||
if (PASSLEN == 0 && !placeholder.resourceID.empty()) {
|
||||
if (!placeholder.asset)
|
||||
placeholder.asset = g_pRenderer->asyncResourceGatherer->getAssetByID(placeholder.resourceID);
|
||||
|
||||
if (placeholder.asset) {
|
||||
Vector2D pos = outerBox.pos() + outerBox.size() / 2.f;
|
||||
pos = pos - placeholder.asset->texture.m_vSize / 2.f;
|
||||
CBox textbox{pos, placeholder.asset->texture.m_vSize};
|
||||
g_pRenderer->renderTexture(textbox, placeholder.asset->texture, data.opacity * fade.a, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return dots.currentAmount != PASSLEN || data.opacity < 1.0 || fade.a < 1.0;
|
||||
}
|
|
@ -8,6 +8,8 @@
|
|||
#include <any>
|
||||
#include <unordered_map>
|
||||
|
||||
struct SPreloadedAsset;
|
||||
|
||||
class CPasswordInputField : public IWidget {
|
||||
public:
|
||||
CPasswordInputField(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props);
|
||||
|
@ -38,5 +40,10 @@ class CPasswordInputField : public IWidget {
|
|||
bool animated = false;
|
||||
} fade;
|
||||
|
||||
struct {
|
||||
std::string resourceID = "";
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
} placeholder;
|
||||
|
||||
bool fadeOnEmpty;
|
||||
};
|
Loading…
Reference in a new issue