Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[usage] Externally trigger UI update #113

Open
EinDev opened this issue Apr 29, 2021 · 1 comment
Open

[usage] Externally trigger UI update #113

EinDev opened this issue Apr 29, 2021 · 1 comment

Comments

@EinDev
Copy link

EinDev commented Apr 29, 2021

How can i trigger a simple Label to update from another thread?
As soon as i enter the event loop the thread becomes blocking, until a event is called.
But as far as i can see these events are only internal events such as mouse move events.

If i want to use EventLoop#next_tick, i need the UI which is a Rc<iui::ui::UIToken which i can only call from the owning thread. If i want to update the Label, the same occurs. How can i change it?

Maybe i did understand something wrong, if so feel free to correct me :)

Also another question: The Label seems to flash quickly as i update it. Is this expected behaviour?

@duffrecords
Copy link

I use Tokio watch channels to communicate between tasks. I spawn an asynchronous task and pass the sender half of the channel as one of its arguments, and keep the receiver half in the UI event loop. In the loop, I use a Tokio select macro with a branch that checks the channel for changes (usually several of these, depending on the UI design) and a default branch that sleeps asynchronously for 5 ms and then executes the next tick in the event loop. The updated UI component will retain its value until something new is sent through the channel. I haven't had to use any reference counters with this pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants