-
Notifications
You must be signed in to change notification settings - Fork 699
live-reload of .slint file for rust compiled app #8837
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
base: master
Are you sure you want to change the base?
Conversation
Looks good at first glance (just glanced because it's still a draft). Quite elegant and minimal. One missing item is perhaps to run the test driver with this also in the CI, so that we catch any accidentally regressions in the new code generator. |
Because i want to be able to hold componetns that do not directly implement ItemTreeVTable, but only forward to it
This fixes the test on tests/cases/model/models when using the rust interpreter, as the second test has a "broken" model, the data is left uninitialized, and this causes a data of the wrong type which causes panic when it is being used.
9f8fb86
to
10a4564
Compare
When the SLINT_LIVE_RELOAD env variable is set, generate a component that will forward everything to the interpreter instead of generating everything. Fix running the test driver rust with the SLINT_LIVE_RELOAD ``` SLINT_LIVE_RELOAD=1 cargo test -p test-driver-rust --all-features --features=slint/live-reload ```
10a4564
to
9b5c1cb
Compare
} else if live_reload && module_name.contains("write_to_model") { | ||
"#[ignore = \"Interpreted model don't forward to underlying models for anonymous structs\"]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code here is something like that:
property<[{name: string, account: string, score: float}]> model: [
// ...
];
for person[i] in model: TouchArea {
// ...
clicked => {
person.score += 1;
//...
The test does set a ModelRc<(slint::SharedString, slint::SharedString, f32)>
to the property, then click, then expect the model to be changed.
But the ModelRc needs to be mapped. Since Value doesn't implement From<>
for tuples (it can't, really, how would they know the names of the fields), Then the code generated there do the conversion:
https://github.com/slint-ui/slint/pull/8837/files#diff-70fcd8b8c35cc6705d940dbda1e7664aa8d23a78c32de31466c66d2ece515011R370-R372
let sp::live_reload::Value::Model(model) = v else { return sp::Err(()) };
sp::Ok(sp::ModelRc::new(model.map(|x| #conf_fn(x).unwrap_or_default())))
But model.map returns a MappedModel that doesn't implement set_row_data. Cf #5290
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to also add the run-if-changed
for the env variable to trigger rebuilds correctly.
## This feature allow to reload the .slint files at runtime, and reload it whenever the files are modified on disk. | ||
## In order to use this, you will also need to define the `SLINT_LIVE_RELOAD` environment variable while | ||
## doing the slint compilation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## This feature allow to reload the .slint files at runtime, and reload it whenever the files are modified on disk. | |
## In order to use this, you will also need to define the `SLINT_LIVE_RELOAD` environment variable while | |
## doing the slint compilation. | |
## Enable this feature to reload the .slint files at runtime and reload it whenever the files are modified on disk. | |
## For this feature to work, it's also required to set the `SLINT_LIVE_RELOAD` environment variable during | |
## application compilation. |
## Since this is a debug-only feature, it is not recommanded to add this feature to your Cargo.toml. | ||
## Instead, you can use the `--features` command line argument like so when building your app: | ||
## ```bash | ||
## SLINT_LIVE_RELOAD=1 cargo build --features slint/live-reload | ||
## ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Since this is a debug-only feature, it is not recommanded to add this feature to your Cargo.toml. | |
## Instead, you can use the `--features` command line argument like so when building your app: | |
## ```bash | |
## SLINT_LIVE_RELOAD=1 cargo build --features slint/live-reload | |
## ``` | |
## This is a feature for debugging and development. It's not recommended to add this feature to your Cargo.toml. | |
## Instead, use the `--features` command line argument like so when building your app: | |
## ```bash | |
## SLINT_LIVE_RELOAD=1 cargo build --features slint/live-reload | |
## ``` |
This will generate API that calls the interpreter behind the scene.
And it will set a file system watcher so reload automatically
Can be tested by running an app like so:
SLINT_LIVE_RELOAD=1
is needed at build time so the rust compiler generate the right thing, theslint/live-reload
feature will be used to enable the runtime for the live-reloadingRust part of #4128