Emulate Debounce with wxTextCtrl  [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.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2090
Joined: Wed Jan 28, 2009 11:57 am
Location: Dar es Salaam, United Republic of Tanzania
Contact:

Emulate Debounce with wxTextCtrl

Postby evstevemd » Sat Jun 16, 2018 11:50 am

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?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

User avatar
doublemax
Moderator
Moderator
Posts: 12425
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Emulate Debounce with wxTextCtrl  [SOLVED]

Postby doublemax » Sat Jun 16, 2018 11:53 am

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: 2090
Joined: Wed Jan 28, 2009 11:57 am
Location: Dar es Salaam, United Republic of Tanzania
Contact:

Re: Emulate Debounce with wxTextCtrl

Postby evstevemd » Sun Jun 17, 2018 6:27 am

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?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2090
Joined: Wed Jan 28, 2009 11:57 am
Location: Dar es Salaam, United Republic of Tanzania
Contact:

Re: Emulate Debounce with wxTextCtrl

Postby evstevemd » Sun Jun 17, 2018 6:30 am

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?
[Ubuntu 15.04/Windows 10 Pro - GCC/MinGW, CodeLite IDE et al]


Return to “C++ Development”

Who is online

Users browsing this forum: DavidHart, Google [Bot] and 9 guests