mirror of
https://github.com/hyprwm/hyprlock.git
synced 2026-05-09 06:18:01 +02:00
add pendingResourceID to enable smoother input
copied from Label
This commit is contained in:
parent
1ab3582ec7
commit
190bd64c8d
2 changed files with 28 additions and 1 deletions
|
|
@ -176,6 +176,29 @@ void CPasswordInputField::updateDots() {
|
|||
*dots.currentAmount = passwordLength;
|
||||
}
|
||||
|
||||
static void onAssetCallback(WP<CPasswordInputField> ref) {
|
||||
if (auto PINPUT = ref.lock(); PINPUT)
|
||||
PINPUT->renderPasswordUpdate();
|
||||
}
|
||||
|
||||
void CPasswordInputField::renderPasswordUpdate() {
|
||||
auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(password.pendingResourceID);
|
||||
if (newAsset) {
|
||||
// new asset is ready :D
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(password.asset);
|
||||
password.asset = newAsset;
|
||||
password.resourceID = password.pendingResourceID;
|
||||
password.pendingResourceID = "";
|
||||
} else {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", password.pendingResourceID);
|
||||
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(outputStringPort);
|
||||
}
|
||||
|
||||
void CPasswordInputField::updatePassword() {
|
||||
std::string passwordContent = g_pHyprlock->getPasswordBuffer();
|
||||
if (passwordContent == password.content) {
|
||||
|
|
@ -191,8 +214,9 @@ void CPasswordInputField::updatePassword() {
|
|||
request.props["font_family"] = fontFamily;
|
||||
request.props["color"] = colorConfig.font;
|
||||
request.props["font_size"] = (int)(std::nearbyint(configSize.y * password.size * 0.5f) * 2.f);
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
password.resourceID = textResourceID;
|
||||
password.pendingResourceID = textResourceID;
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ class CPasswordInputField : public IWidget {
|
|||
void reset();
|
||||
void onFadeOutTimer();
|
||||
|
||||
void renderPasswordUpdate();
|
||||
|
||||
private:
|
||||
WP<CPasswordInputField> m_self;
|
||||
|
||||
|
|
@ -76,6 +78,7 @@ class CPasswordInputField : public IWidget {
|
|||
float size = 0;
|
||||
std::string content;
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
} password;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue