diff --git a/api/cpp/include/slint.h b/api/cpp/include/slint.h index fce625f3b..af7a52985 100644 --- a/api/cpp/include/slint.h +++ b/api/cpp/include/slint.h @@ -126,9 +126,9 @@ public: } template - void init_items(Component *c, ItemArray items) const + void register_component(Component *c, ItemArray items) const { - cbindgen_private::slint_component_init_items( + cbindgen_private::slint_register_component( vtable::VRef { &Component::static_vtable, c }, items, &inner); } diff --git a/api/rs/slint/lib.rs b/api/rs/slint/lib.rs index 71475c737..03e839354 100644 --- a/api/rs/slint/lib.rs +++ b/api/rs/slint/lib.rs @@ -288,7 +288,7 @@ pub mod re_exports { pub use i_slint_core::animations::EasingCurve; pub use i_slint_core::callbacks::Callback; pub use i_slint_core::component::{ - init_component_items, unregister_component, Component, ComponentRefPin, ComponentVTable, + register_component, unregister_component, Component, ComponentRefPin, ComponentVTable, ComponentWeak, IndexRange, }; pub use i_slint_core::graphics::*; diff --git a/internal/backends/gl/glwindow.rs b/internal/backends/gl/glwindow.rs index 0eb460ce5..6a4be4156 100644 --- a/internal/backends/gl/glwindow.rs +++ b/internal/backends/gl/glwindow.rs @@ -315,6 +315,8 @@ impl PlatformWindow for GLWindow { } } + fn register_component(&self) {} + fn unregister_component<'a>( &self, component: corelib::component::ComponentRef, diff --git a/internal/backends/mcu/lib.rs b/internal/backends/mcu/lib.rs index 7acfd851f..f3d0e0b16 100644 --- a/internal/backends/mcu/lib.rs +++ b/internal/backends/mcu/lib.rs @@ -145,6 +145,7 @@ mod the_backend { fn request_redraw(&self) { self.backend.with_inner(|inner| inner.post_event(McuEvent::Repaint)) } + fn register_component(&self) {} fn unregister_component<'a>( &self, _: i_slint_core::component::ComponentRef, diff --git a/internal/backends/mcu/simulator.rs b/internal/backends/mcu/simulator.rs index 3f9fd06c1..ae0b6835d 100644 --- a/internal/backends/mcu/simulator.rs +++ b/internal/backends/mcu/simulator.rs @@ -141,6 +141,8 @@ impl PlatformWindow for SimulatorWindow { } } + fn register_component(&self) {} + fn unregister_component<'a>( &self, _: i_slint_core::component::ComponentRef, diff --git a/internal/backends/qt/qt_window.rs b/internal/backends/qt/qt_window.rs index 39a690cc4..f01d4f46b 100644 --- a/internal/backends/qt/qt_window.rs +++ b/internal/backends/qt/qt_window.rs @@ -1525,6 +1525,8 @@ impl PlatformWindow for QtWindow { }}; } + fn register_component(&self) {} + fn unregister_component<'a>( &self, component: ComponentRef, diff --git a/internal/backends/testing/lib.rs b/internal/backends/testing/lib.rs index 15e7c57c6..929f99b95 100644 --- a/internal/backends/testing/lib.rs +++ b/internal/backends/testing/lib.rs @@ -93,6 +93,8 @@ impl PlatformWindow for TestingWindow { fn request_redraw(&self) {} + fn register_component(&self) {} + fn unregister_component<'a>( &self, _: i_slint_core::component::ComponentRef, diff --git a/internal/compiler/generator/cpp.rs b/internal/compiler/generator/cpp.rs index a78057252..080e74c16 100644 --- a/internal/compiler/generator/cpp.rs +++ b/internal/compiler/generator/cpp.rs @@ -1104,7 +1104,10 @@ fn generate_item_tree( } create_code.extend([ - format!("{}->m_window.window_handle().init_items(self, self->item_array());", root_access), + format!( + "{}->m_window.window_handle().register_component(self, self->item_array());", + root_access + ), format!("self->init({}, self->self_weak, 0, 1 {});", root_access, init_parent_parameters), format!("return slint::ComponentHandle<{0}>{{ self_rc }};", target_struct.name), ]); diff --git a/internal/compiler/generator/rust.rs b/internal/compiler/generator/rust.rs index af8e6a671..8e0ff82a3 100644 --- a/internal/compiler/generator/rust.rs +++ b/internal/compiler/generator/rust.rs @@ -1195,7 +1195,7 @@ fn generate_item_tree( let self_rc = VRc::new(_self); let _self = self_rc.as_pin_ref(); #init_window - slint::re_exports::init_component_items(_self, Self::item_array(), #root_token.window.get().unwrap().window_handle()); + slint::re_exports::register_component(_self, Self::item_array(), #root_token.window.get().unwrap().window_handle()); Self::init(slint::re_exports::VRc::map(self_rc.clone(), |x| x), #root_token, 0, 1); self_rc } diff --git a/internal/core/component.rs b/internal/core/component.rs index ff8f149e8..e99cd3f96 100644 --- a/internal/core/component.rs +++ b/internal/core/component.rs @@ -111,12 +111,13 @@ pub type ComponentRc = vtable::VRc; pub type ComponentWeak = vtable::VWeak; /// Call init() on the ItemVTable for each item of the component. -pub fn init_component_items( +pub fn register_component( base: core::pin::Pin<&Base>, item_array: &[vtable::VOffset], window: &WindowRc, ) { item_array.iter().for_each(|item| item.apply_pin(base).as_ref().init(window)); + window.register_component(); } /// Free the backend graphics resources allocated by the component's items. @@ -137,13 +138,13 @@ pub(crate) mod ffi { /// Call init() on the ItemVTable of each item in the item array. #[no_mangle] - pub unsafe extern "C" fn slint_component_init_items( + pub unsafe extern "C" fn slint_register_component( component: ComponentRefPin, item_array: Slice>, window_handle: *const crate::window::ffi::WindowRcOpaque, ) { let window = &*(window_handle as *const WindowRc); - super::init_component_items( + super::register_component( core::pin::Pin::new_unchecked(&*(component.as_ptr() as *const u8)), item_array.as_slice(), window, diff --git a/internal/core/lib.rs b/internal/core/lib.rs index a5fea40ff..2d1a8b20c 100644 --- a/internal/core/lib.rs +++ b/internal/core/lib.rs @@ -1,7 +1,7 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial -// cSpell: ignore sharedvector textlayout +// cSpell: ignore sharedvector swrenderer textlayout #![doc = include_str!("README.md")] #![doc(html_logo_url = "https://slint-ui.com/logo/slint-logo-square-light.svg")] @@ -144,7 +144,7 @@ pub fn use_modules() -> usize { + properties::ffi::slint_property_init as usize + string::ffi::slint_shared_string_bytes as usize + window::ffi::slint_windowrc_drop as usize - + component::ffi::slint_component_init_items as usize + + component::ffi::slint_register_component as usize + timers::ffi::slint_timer_start as usize + graphics::color::ffi::slint_color_brighter as usize + graphics::image::ffi::slint_image_size as usize diff --git a/internal/core/window.rs b/internal/core/window.rs index a083367b5..d62ff7299 100644 --- a/internal/core/window.rs +++ b/internal/core/window.rs @@ -39,6 +39,9 @@ pub trait PlatformWindow { /// request. fn request_redraw(&self); + /// This function is called by the generated code when a component and therefore its tree of items are created. + fn register_component(&self); + /// This function is called by the generated code when a component and therefore its tree of items are destroyed. The /// implementation typically uses this to free the underlying graphics resources cached via [`crate::graphics::RenderingCache`]. fn unregister_component<'a>( diff --git a/internal/interpreter/dynamic_component.rs b/internal/interpreter/dynamic_component.rs index c48ecfcec..b4c68acfb 100644 --- a/internal/interpreter/dynamic_component.rs +++ b/internal/interpreter/dynamic_component.rs @@ -1189,7 +1189,7 @@ pub fn instantiate( let instance_ref = component_box.borrow_instance(); if !component_type.original.is_global() { - i_slint_core::component::init_component_items( + i_slint_core::component::register_component( instance_ref.instance, instance_ref.component_type.item_array.as_slice(), eval::window_ref(instance_ref).unwrap(),