mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 12:54:45 +00:00
Rename the free_graphics_resources to component_destroyed
And do not iterate over the items anymore
This commit is contained in:
parent
6cbf2c0609
commit
ad2d19165a
10 changed files with 17 additions and 60 deletions
|
@ -112,11 +112,11 @@ public:
|
||||||
float scale_factor() const { return slint_windowrc_get_scale_factor(&inner); }
|
float scale_factor() const { return slint_windowrc_get_scale_factor(&inner); }
|
||||||
void set_scale_factor(float value) const { slint_windowrc_set_scale_factor(&inner, value); }
|
void set_scale_factor(float value) const { slint_windowrc_set_scale_factor(&inner, value); }
|
||||||
|
|
||||||
template<typename Component, typename ItemArray>
|
template<typename Component>
|
||||||
void free_graphics_resources(Component *c, ItemArray items) const
|
void component_destroyed(Component *c) const
|
||||||
{
|
{
|
||||||
cbindgen_private::slint_component_free_item_array_graphics_resources(
|
cbindgen_private::slint_component_destroyed(
|
||||||
vtable::VRef<ComponentVTable> { &Component::static_vtable, c }, items, &inner);
|
vtable::VRef<ComponentVTable> { &Component::static_vtable, c }, &inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_focus_item(const ComponentRc &component_rc, uintptr_t item_index)
|
void set_focus_item(const ComponentRc &component_rc, uintptr_t item_index)
|
||||||
|
|
|
@ -287,8 +287,8 @@ pub mod re_exports {
|
||||||
pub use i_slint_core::animations::EasingCurve;
|
pub use i_slint_core::animations::EasingCurve;
|
||||||
pub use i_slint_core::callbacks::Callback;
|
pub use i_slint_core::callbacks::Callback;
|
||||||
pub use i_slint_core::component::{
|
pub use i_slint_core::component::{
|
||||||
free_component_item_graphics_resources, init_component_items, Component, ComponentRefPin,
|
init_component_items, Component, ComponentRefPin, ComponentVTable, ComponentWeak,
|
||||||
ComponentVTable, ComponentWeak, IndexRange,
|
IndexRange,
|
||||||
};
|
};
|
||||||
pub use i_slint_core::graphics::*;
|
pub use i_slint_core::graphics::*;
|
||||||
pub use i_slint_core::input::{
|
pub use i_slint_core::input::{
|
||||||
|
|
|
@ -299,11 +299,7 @@ impl PlatformWindow for GLWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn free_graphics_resources<'a>(
|
fn component_destroyed<'a>(&self, component: corelib::component::ComponentRef) {
|
||||||
&self,
|
|
||||||
component: corelib::component::ComponentRef,
|
|
||||||
_items: &mut dyn Iterator<Item = Pin<ItemRef<'a>>>,
|
|
||||||
) {
|
|
||||||
match &*self.map_state.borrow() {
|
match &*self.map_state.borrow() {
|
||||||
GraphicsWindowBackendState::Unmapped => {}
|
GraphicsWindowBackendState::Unmapped => {}
|
||||||
GraphicsWindowBackendState::Mapped(_) => {
|
GraphicsWindowBackendState::Mapped(_) => {
|
||||||
|
|
|
@ -1515,11 +1515,7 @@ impl PlatformWindow for QtWindow {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn free_graphics_resources<'a>(
|
fn component_destroyed<'a>(&self, component: ComponentRef) {
|
||||||
&self,
|
|
||||||
component: ComponentRef,
|
|
||||||
_: &mut dyn Iterator<Item = Pin<ItemRef<'a>>>,
|
|
||||||
) {
|
|
||||||
self.cache.component_destroyed(component);
|
self.cache.component_destroyed(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,12 +93,7 @@ impl PlatformWindow for TestingWindow {
|
||||||
|
|
||||||
fn request_redraw(&self) {}
|
fn request_redraw(&self) {}
|
||||||
|
|
||||||
fn free_graphics_resources<'a>(
|
fn component_destroyed<'a>(&self, _: i_slint_core::component::ComponentRef) {}
|
||||||
&self,
|
|
||||||
_: i_slint_core::component::ComponentRef,
|
|
||||||
_items: &mut dyn Iterator<Item = Pin<i_slint_core::items::ItemRef<'a>>>,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_popup(&self, _popup: &ComponentRc, _position: i_slint_core::graphics::Point) {
|
fn show_popup(&self, _popup: &ComponentRc, _position: i_slint_core::graphics::Point) {
|
||||||
todo!()
|
todo!()
|
||||||
|
|
|
@ -1091,10 +1091,8 @@ fn generate_item_tree(
|
||||||
|
|
||||||
let mut destructor = vec!["auto self = this;".to_owned()];
|
let mut destructor = vec!["auto self = this;".to_owned()];
|
||||||
|
|
||||||
destructor.push(format!(
|
destructor
|
||||||
"{}->m_window.window_handle().free_graphics_resources(self, item_array());",
|
.push(format!("{}->m_window.window_handle().component_destroyed(self);", root_access));
|
||||||
root_access
|
|
||||||
));
|
|
||||||
|
|
||||||
target_struct.members.push((
|
target_struct.members.push((
|
||||||
Access::Public,
|
Access::Public,
|
||||||
|
|
|
@ -1124,7 +1124,7 @@ fn generate_item_tree(
|
||||||
fn drop(self: core::pin::Pin<&mut #inner_component_id>) {
|
fn drop(self: core::pin::Pin<&mut #inner_component_id>) {
|
||||||
use slint::re_exports::*;
|
use slint::re_exports::*;
|
||||||
new_vref!(let vref : VRef<ComponentVTable> for Component = self.as_ref().get_ref());
|
new_vref!(let vref : VRef<ComponentVTable> for Component = self.as_ref().get_ref());
|
||||||
slint::re_exports::free_component_item_graphics_resources(self.as_ref(), vref, Self::item_array(), self.window.get().unwrap().window_handle());
|
self.window.get().unwrap().window_handle().component_destroyed(vref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,19 +105,6 @@ pub fn init_component_items<Base>(
|
||||||
item_array.iter().for_each(|item| item.apply_pin(base).as_ref().init(window));
|
item_array.iter().for_each(|item| item.apply_pin(base).as_ref().init(window));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free the backend graphics resources allocated by the component's items.
|
|
||||||
pub fn free_component_item_graphics_resources<Base>(
|
|
||||||
base: core::pin::Pin<&Base>,
|
|
||||||
component: ComponentRef,
|
|
||||||
item_array: &[vtable::VOffset<Base, ItemVTable, vtable::AllowPin>],
|
|
||||||
window: &WindowRc,
|
|
||||||
) {
|
|
||||||
window.free_graphics_resources(
|
|
||||||
component,
|
|
||||||
&mut item_array.iter().map(|item| item.apply_pin(base)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "ffi")]
|
#[cfg(feature = "ffi")]
|
||||||
pub(crate) mod ffi {
|
pub(crate) mod ffi {
|
||||||
#![allow(unsafe_code)]
|
#![allow(unsafe_code)]
|
||||||
|
@ -141,17 +128,11 @@ pub(crate) mod ffi {
|
||||||
|
|
||||||
/// Free the backend graphics resources allocated in the item array.
|
/// Free the backend graphics resources allocated in the item array.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn slint_component_free_item_array_graphics_resources(
|
pub unsafe extern "C" fn slint_component_destroyed(
|
||||||
component: ComponentRefPin,
|
component: ComponentRef,
|
||||||
item_array: Slice<vtable::VOffset<u8, ItemVTable, vtable::AllowPin>>,
|
|
||||||
window_handle: *const crate::window::ffi::WindowRcOpaque,
|
window_handle: *const crate::window::ffi::WindowRcOpaque,
|
||||||
) {
|
) {
|
||||||
let window = &*(window_handle as *const WindowRc);
|
let window = &*(window_handle as *const WindowRc);
|
||||||
super::free_component_item_graphics_resources(
|
window.component_destroyed(component)
|
||||||
core::pin::Pin::new_unchecked(&*(component.as_ptr() as *const u8)),
|
|
||||||
core::pin::Pin::into_inner(component),
|
|
||||||
item_array.as_slice(),
|
|
||||||
window,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,11 +41,7 @@ pub trait PlatformWindow {
|
||||||
|
|
||||||
/// This function is called by the generated code when a component and therefore its tree of items are destroyed. The
|
/// 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`].
|
/// implementation typically uses this to free the underlying graphics resources cached via [`crate::graphics::RenderingCache`].
|
||||||
fn free_graphics_resources<'a>(
|
fn component_destroyed(&self, component: ComponentRef);
|
||||||
&self,
|
|
||||||
component: ComponentRef,
|
|
||||||
items: &mut dyn Iterator<Item = Pin<ItemRef<'a>>>,
|
|
||||||
);
|
|
||||||
|
|
||||||
/// This function is called through the public API to register a callback that the backend needs to invoke during
|
/// This function is called through the public API to register a callback that the backend needs to invoke during
|
||||||
/// different phases of rendering.
|
/// different phases of rendering.
|
||||||
|
|
|
@ -68,12 +68,7 @@ impl<'id> Drop for ComponentBox<'id> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let instance_ref = self.borrow_instance();
|
let instance_ref = self.borrow_instance();
|
||||||
if let Some(window) = eval::window_ref(instance_ref) {
|
if let Some(window) = eval::window_ref(instance_ref) {
|
||||||
i_slint_core::component::free_component_item_graphics_resources(
|
window.component_destroyed(Pin::into_inner(instance_ref.borrow()))
|
||||||
instance_ref.instance,
|
|
||||||
Pin::into_inner(instance_ref.borrow()),
|
|
||||||
instance_ref.component_type.item_array.as_slice(),
|
|
||||||
window,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue