How to deal with wanted delay on a string gadget?

Everything else that doesn't fall into one of the other PB categories.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

How to deal with wanted delay on a string gadget?

Post by jacdelad »

Hello,
I don't need code, just an info: Let's say I have a StringGadget which is used for filtering a list. Now, I don't want to update the list on every edited character, but let's say one second after the last change was made. Naturally I would start a timer when something changes (and restart it, if it was already started), then process it after it fires. So far so good (and easy).
But, just out of curiosity, is there a better way to do it? Or some different approach, that's more efficient?
Last edited by jacdelad on Mon May 22, 2023 5:03 pm, edited 1 time in total.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: How to deal with wanted dealy on a string gadget?

Post by Axolotl »

I would probably do it the same way....
1. Start timer with EventType Focus
2. count up counter variable, or reset if EventType Change
3. when count is reached, update the list
4. end timer with EventType LostFocus

maybe a bit different, but probably not more efficient

Waiting inside a thread and then a PostEvent() is probably not much better
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to deal with wanted dealy on a string gadget?

Post by Caronte3D »

If it's not absolutely essential, I'd rather not overload the system, so I don't do it by time, I just do it when the return button is pressed or when StringGadget losses focus.
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to deal with wanted delay on a string gadget?

Post by jacdelad »

Thanks you both.

@Caronte3D' Yes, that would be another way to do it. I am just curious about the specific problem I described. Like when showing tooltips, you don't to push a button for that.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply