Skip to content

Commit

Permalink
live-preview: Update the live-preview data model (#7741)
Browse files Browse the repository at this point in the history
... on reloads. That is needed to make the UI aware
of the new data.

I tried to be clever and not update widgets on model
changes, but that is not a problem anymore as all
the property values are no longer passed through
the model. So the only reason to update the model now
is because the code was loaded fresh and we *need*
to refresh the entire UI in that case.
  • Loading branch information
hunger authored Feb 25, 2025
1 parent 9679657 commit 77f676d
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions tools/lsp/preview/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,32 +1142,7 @@ pub fn ui_set_preview_data(

let api = ui.global::<Api>();

let old_model = api.get_preview_data();

fn update_model(
old_model: &slint::ModelRc<PropertyContainer>,
new_model: &[PropertyContainer],
) -> bool {
if old_model.row_count() != new_model.len() {
return true;
}

for (oc, nc) in old_model.iter().zip(new_model.iter()) {
if oc.container_name != nc.container_name
|| oc.container_id != nc.container_id
|| oc.properties.row_count() != nc.properties.row_count()
|| oc.properties.iter().zip(nc.properties.iter()).any(|(o, n)| o != n)
{
return true;
}
}

false
}

if update_model(&old_model, &result) {
api.set_preview_data(Rc::new(VecModel::from(result)).into());
}
api.set_preview_data(Rc::new(VecModel::from(result)).into());
}

fn to_property_container(container: slint::SharedString) -> preview_data::PropertyContainer {
Expand Down

0 comments on commit 77f676d

Please sign in to comment.