Add separate longclick retrigger delay#86
Open
eternicode wants to merge 1 commit intoLennartHennigs:masterfrom
Open
Add separate longclick retrigger delay#86eternicode wants to merge 1 commit intoLennartHennigs:masterfrom
eternicode wants to merge 1 commit intoLennartHennigs:masterfrom
Conversation
nielsnl68
suggested changes
Jan 23, 2026
|
|
||
| void Button2::setLongClickDetectedRetriggerable(bool retriggerable) { | ||
| longclick_retriggerable = retriggerable; | ||
| has_longclick_retrigger_ms = false; |
There was a problem hiding this comment.
Hi, i like your idea, not sure if the "has_longclick_retrigger_ms" is really needed you could just check if "longclick_retrigger_ms" has a value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
I was trying to implement a standard interaction pattern with long press:
Classic example would be long-pressing to quickly navigate a long list of items.
I had attempted this with (simplified and slightly pseudocode):
btn.setPressedHandler(pressAction); btn.setLongClickDetectedHandler( [this](Button2 &btn) { btn.setLongClickTime(100); pressAction(btn); } ); btn.setLongClickHandler([this](Button2 &btn) { btn.setLongClickTime(500); }); btn.setLongClickDetectedRetriggerable(true); btn.setLongClickTime(500);but this approach consistently caused the first 3-5 long click actions to execute with ~30ms delay. The exact timing is probably dependent on other factors, but the threshold was adjusted downward when
setLongClickTime(100)was called, so these 3-5 initial repeats were effectively immediately executed while the timer caught up to the adjustedlongclick_countermultiplier math.The MR produces cleaner behavior with cleaner code:
Considerations
I tried to come up with a clean way to avoid the
has_longclick_retrigger_msvariable. Cleanest way would be to have an invalid value forlongclick_retrigger_ms, ie-1, but uint to accommodate milliseconds precludes that option. Could default it tolongclick_time_ms's value at init and sync the two when they have the same value, but that felt like too much magic. Explicit flagging felt best.