Skip to content

Commit

Permalink
compiler: Add a ListResources option for resource embedding
Browse files Browse the repository at this point in the history
... which will list all resources that are not going to get embedded
as `None` in the Document's `embedded_file_reosurces`.

The idea is to use that field to find all used resources in the
live preview so that we know what we can watch.
  • Loading branch information
hunger committed Oct 11, 2024
1 parent ea82c62 commit 0d454bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/compiler/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub enum EmbedResourcesKind {
Nothing,
/// Only embed builtin resources
OnlyBuiltinResources,
/// Do not embed resources, but list them in the Document as it they were embedded
ListAllResources,
/// Embed all images resources (the content of their files)
EmbedAllResources,
#[cfg(feature = "software-renderer")]
Expand Down
6 changes: 5 additions & 1 deletion internal/compiler/passes/embed_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@ fn embed_images_from_expression(
&& (embed_files != EmbedResourcesKind::OnlyBuiltinResources
|| path.starts_with("builtin:/"))
{
*resource_ref = embed_image(
let image_ref = embed_image(
global_embedded_resources,
embed_files,
path,
scale_factor,
diag,
source_location,
);
if embed_files != EmbedResourcesKind::ListAllResources {
*resource_ref = image_ref;
}
}
}
};
Expand Down Expand Up @@ -161,6 +164,7 @@ fn embed_image(
}
}
};

match e.kind {
#[cfg(feature = "software-renderer")]
EmbeddedResourcesKind::TextureData { .. } => {
Expand Down
3 changes: 2 additions & 1 deletion tools/lsp/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::common::{
use crate::lsp_ext::Health;
use crate::preview::element_selection::ElementSelection;
use crate::util;
use i_slint_compiler::diagnostics;
use i_slint_compiler::object_tree::ElementRc;
use i_slint_compiler::parser::{syntax_nodes, TextSize};
use i_slint_compiler::{diagnostics, EmbedResourcesKind};
use i_slint_core::component_factory::FactoryContext;
use i_slint_core::lengths::{LogicalPoint, LogicalRect, LogicalSize};
use i_slint_core::model::VecModel;
Expand Down Expand Up @@ -1231,6 +1231,7 @@ async fn parse_source(
{
cc.resource_url_mapper = resource_url_mapper();
}
cc.embed_resources = EmbedResourcesKind::ListAllResources;

if !style.is_empty() {
cc.style = Some(style);
Expand Down

0 comments on commit 0d454bf

Please sign in to comment.