antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.43k stars 78 forks source link

How to trigger an update without user interaction? #312

Closed bistace closed 1 year ago

bistace commented 1 year ago

Hello, I am trying to create a chess engine that will be used to train an AI to play chess against other engines. I am trying to use relm to display the state of the board.

Here's what I did so far:

I have some difficulties seeing how to mutate the board and trigger an update without the user interacting with the window (there is no button or anything, it is just used to display the state of the board). I have looked at components and workers but it seems that they still need an input message to trigger some actions.

Could you please point me in the right direction?

antoyo commented 1 year ago

Hi. I guess the engine will run in another thread, right? If that's the case, you could use a Channel for inter-thread communication: https://github.com/antoyo/relm/blob/master/relm-examples/examples/multithread.rs#L53-L62

It provides a send() method that you can use whenever your engine has a new move to play and the Channel callback can be used to send a message to the chessboard widget.

bistace commented 1 year ago

Thank you for the fast reply and pointers, I will look into it!