Emulate Debounce with wxTextCtrl Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Emulate Debounce with wxTextCtrl

Post by evstevemd »

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!
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?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Emulate Debounce with wxTextCtrl

Post by doublemax »

If not is it possible to know user have stopped typing?
No. We have no mind-reading API yet. But i'm sure Google is working on that ;)

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!
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Emulate Debounce with wxTextCtrl

Post by evstevemd »

doublemax wrote:
If not is it possible to know user have stopped typing?
No. We have no mind-reading API yet. But i'm sure Google is working on that ;)
Google at it again :lol:
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.
Priceless! I forgot about one-shot timer. Perfect answer, Thanks! =D>
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?
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Emulate Debounce with wxTextCtrl

Post by evstevemd »

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?
Post Reply