Clean up wasm-interpreter / winit interface

Use the window attributes hook instead of a private function in the winit backend.
This commit is contained in:
Simon Hausmann 2025-04-08 07:19:27 +02:00 committed by Simon Hausmann
parent ca0c75bfe1
commit 4e65998016
5 changed files with 62 additions and 46 deletions

View file

@ -983,22 +983,6 @@ impl ComponentDefinition {
})
}
/// Instantiate the component for wasm using the given canvas id
#[cfg(target_arch = "wasm32")]
pub fn create_with_canvas_id(
&self,
canvas_id: &str,
) -> Result<ComponentInstance, PlatformError> {
generativity::make_guard!(guard);
Ok(ComponentInstance {
inner: self
.inner
.unerase(guard)
.clone()
.create(WindowOptions::CreateWithCanvasId(canvas_id.into()))?,
})
}
/// Instantiate the component using an existing window.
#[doc(hidden)]
#[cfg(feature = "internal")]

View file

@ -289,8 +289,6 @@ pub(crate) struct ComponentExtraData {
pub(crate) globals: OnceCell<crate::global_component::GlobalStorage>,
pub(crate) self_weak: OnceCell<ErasedItemTreeBoxWeak>,
pub(crate) embedding_position: OnceCell<(ItemTreeWeak, u32)>,
#[cfg(target_arch = "wasm32")]
pub(crate) canvas_id: OnceCell<String>,
}
struct ErasedRepeaterWithinComponent<'id>(RepeaterWithinItemTree<'id, 'static>);
@ -460,8 +458,6 @@ pub enum WindowOptions {
#[default]
CreateNewWindow,
UseExistingWindow(WindowAdapterRc),
#[cfg(target_arch = "wasm32")]
CreateWithCanvasId(String),
Embed {
parent_item_tree: ItemTreeWeak,
parent_item_tree_index: u32,
@ -1513,11 +1509,6 @@ pub fn instantiate(
}
let extra_data = description.extra_data_offset.apply(instance_ref.as_ref());
extra_data.globals.set(globals).ok().unwrap();
#[cfg(target_arch = "wasm32")]
if let Some(WindowOptions::CreateWithCanvasId(canvas_id)) = window_options {
extra_data.canvas_id.set(canvas_id.clone()).unwrap();
}
}
if let Some(WindowOptions::Embed { parent_item_tree, parent_item_tree_index }) = window_options
@ -2301,12 +2292,7 @@ impl<'a, 'id> InstanceRef<'a, 'id> {
let extra_data = description.extra_data_offset.apply(instance);
let window_adapter = // We are the root: Create a window adapter
i_slint_backend_selector::with_platform(|_b| {
#[cfg(not(target_arch = "wasm32"))]
return _b.create_window_adapter();
#[cfg(target_arch = "wasm32")]
i_slint_backend_winit::create_gl_window_with_canvas_id(
extra_data.canvas_id.get().map_or("canvas", |s| s.as_str()),
)
})?;
let comp_rc = extra_data.self_weak.get().unwrap().upgrade().unwrap();