Hi,
I have this TextCtrl that I bind to observe text changes. When Text changes, it runs resource intense search and I would not like to keep searching as user types in. I want to put some delay to take user Text only in certain intervals. I have put times to check when user last typed and ignore if it is less than debounce delay time. This works fine except in case the last user typed in the delay time wasn't reached so the event was ignored and not searched.
Another alternative am thinking of is using Timers. This would solve this problem as it will run the search each dt interval. But this will keep searching even when the user have stopped searching.
I can make complex combination of this, but wanted to know if there is a way to delay receiving events for a given time. If not is it possible to know user have stopped typing? I know there is no single event for that, but am Okay with multiple combination!
Cheers!
Emulate Debounce with wxTextCtrl Topic is solved
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Emulate Debounce with wxTextCtrl
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: Emulate Debounce with wxTextCtrl
No. We have no mind-reading API yet. But i'm sure Google is working on thatIf not is it possible to know user have stopped typing?
But you're on the right track:
a) Each time the user presses a key, start a one-shot timer, e.g. with 1 second delay
b) When the timer is fired, perform the search.
This means that as long as the user types, there won't be an event, because the timer gets re-started before it fires.
Use the source, Luke!
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Emulate Debounce with wxTextCtrl
Google at it againdoublemax wrote:No. We have no mind-reading API yet. But i'm sure Google is working on thatIf not is it possible to know user have stopped typing?
Priceless! I forgot about one-shot timer. Perfect answer, Thanks!doublemax wrote:But you're on the right track:
a) Each time the user presses a key, start a one-shot timer, e.g. with 1 second delay
b) When the timer is fired, perform the search.
This means that as long as the user types, there won't be an event, because the timer gets re-started before it fires.
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Emulate Debounce with wxTextCtrl
By the way, Debounce in other platforms that supports Rx like RxJava library is a breeze. Only one function in the chain and you are debounce-ed
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?