Add separate longclick retrigger delay#86
Closed
eternicode wants to merge 1 commit intoLennartHennigs:masterfrom
Closed
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.
LennartHennigs
added a commit
that referenced
this pull request
Mar 17, 2026
Decouples the initial long-press threshold from the continuous retrigger interval, taking the API style of PR #86 with the cleaner implementation approach of PR #90. - New overload: setLongClickDetectedRetriggerable(bool, unsigned int retrigger_ms) - New getter: getLongClickInterval() - bool-only overload delegates to the two-arg overload (resets interval to 0) - _checkForLongClick: first fire at longclick_time_ms, subsequent fires every retrigger_ms (falls back to longclick_time_ms if not set, preserving backward compatibility) - reset() now clears longclick_retriggerable and longclick_interval_ms - New example: LongpressRetriggerInterval - New tests: getLongClickInterval getter, retrigger timing with custom interval - test_helpers: pressAndHold() helper extracted; click() delegates to it Closes #86, Closes #90 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5 tasks
Owner
|
Thanks for this PR! The bundled API approach here ( I've opened #91 as a hybrid — it takes your API style from this PR and combines it with the cleaner sentinel-based implementation from #90 (no extra bool flag, |
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.