What is the idomatic way to get and set structs from the UI to a Rust backend? #6165
Unanswered
PanCakeConnaisseur
asked this question in
Q&A
Replies: 1 comment 2 replies
-
You can take a look at how our Live-Preview works. The slint side of the API is in You can definitely pass structs back and models back and forth. You can use the slint structs on the rust side, but you might prefer to have a different set of structs for rust as slint uses e.g. I hope this helps. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I struggle to find the idiomatic way to transfer several groups (structs) of values from and to the UI when using Rust. I know that I can read single values using
but what is the idiomatic way to handle many values that can be grouped into structs (product type)?
Let's say I have a UI for a movie encoder and I have a set of values for the audio options and a set of values for the video options. Both sets are configured by the user, using widgets. Then the user clicks "Start Encoding". Now I need to get all these values into Rust. Let's just consider the simplified video options here:
I defined the struct in my .slint file:
then in Rust I have something like
and then implement a
From
trait to build aVideoSettings
fromVideoSettingsUi
?VideoSettingsUi
? I also foundModel::slint
but it seems to be for something else entirely.export struct VideoSettingsUi
?slint_build::compile("ui/main.slint").unwrap();
in build.rs will generate the code forVideoSettingsUi
andslint::include_modules!();
will include it. Is this the idiomatic way to do it? Are there others?in-out property <VideoSettingsUi> videoSettings;
, to write the options into the UI through it on application startup?I know that you have an open issue where a feature related to this is tracked. But if I develop the UI today, what do I do?
AFAICS, the examples in this repository never read/write a struct (multiple grouped values) between Rust and the UI. For beginners like me, it would be very helpful to have an authoritative answer that shows the idiomatic way.
Beta Was this translation helpful? Give feedback.
All reactions