antoyo / relm

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

Separation between GUI and logic #237

Closed paulolieuthier closed 4 years ago

paulolieuthier commented 4 years ago

How would you go about separating GUI from application logic? I'm trying to use channels but I'm having a hard time. It would be nice to see an example like a simple chat application with a separate modules for storing messages, configuration etc.

antoyo commented 4 years ago

(Sorry for the late reply.)

I'm not sure exactly what you mean by separating GUI from application logic as the update() method is the application logic and the view! macro is the GUI, so they are already separated.

If you want to know how to better organize your application, I suggest you create multiple relm widgets and send messages between them. See the communication example for an example of how to do that.

paulolieuthier commented 4 years ago

Hey, don't worry! I really enjoyed the project.

I mean separating into different modules in a way that the core module would not depend on relm or even gtk. Channels could be used to communicate events in a frontend-agnostic way.

antoyo commented 4 years ago

You can still use the same way as in the communication example, sending messages using a handle to a widget.

If you want to send a message from another thread, there's a Channel in relm. See this example for usage.

paulolieuthier commented 4 years ago

I saw the examples and relm's Channel, but still struggled. I will revisit it soon and create more specific issues if needed.

paulolieuthier commented 4 years ago

A more elaborate example would still be nice. :smile:

antoyo commented 4 years ago

Yep. There's already an issue for that ;) .