1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#![warn(missing_docs)]
use crate::item_tree::{ItemVisitorVTable, TraversalOrder, VisitChildrenResult};
use crate::items::{ItemVTable, ItemWeak};
use crate::layout::{LayoutInfo, Orientation};
use crate::window::WindowRc;
use vtable::*;
#[vtable]
#[repr(C)]
pub struct ComponentVTable {
pub visit_children_item: extern "C" fn(
core::pin::Pin<VRef<ComponentVTable>>,
index: isize,
order: TraversalOrder,
visitor: VRefMut<ItemVisitorVTable>,
) -> VisitChildrenResult,
pub get_item_ref: extern "C" fn(
core::pin::Pin<VRef<ComponentVTable>>,
index: usize,
) -> core::pin::Pin<VRef<ItemVTable>>,
pub parent_item:
extern "C" fn(core::pin::Pin<VRef<ComponentVTable>>, index: usize, result: &mut ItemWeak),
pub layout_info:
extern "C" fn(core::pin::Pin<VRef<ComponentVTable>>, Orientation) -> LayoutInfo,
pub drop_in_place: unsafe fn(VRefMut<ComponentVTable>) -> vtable::Layout,
pub dealloc: unsafe fn(&ComponentVTable, ptr: *mut u8, layout: vtable::Layout),
}
pub type ComponentRef<'a> = vtable::VRef<'a, ComponentVTable>;
pub type ComponentRefPin<'a> = core::pin::Pin<ComponentRef<'a>>;
pub type ComponentRc = vtable::VRc<ComponentVTable, Dyn>;
pub type ComponentWeak = vtable::VWeak<ComponentVTable, Dyn>;
pub fn init_component_items<Base>(
base: core::pin::Pin<&Base>,
item_tree: &[crate::item_tree::ItemTreeNode<Base>],
window: &WindowRc,
) {
item_tree.iter().for_each(|entry| match entry {
crate::item_tree::ItemTreeNode::Item { item, .. } => {
item.apply_pin(base).as_ref().init(window)
}
crate::item_tree::ItemTreeNode::DynamicTree { .. } => {}
})
}
pub fn free_component_item_graphics_resources<Base>(
base: core::pin::Pin<&Base>,
item_tree: &[crate::item_tree::ItemTreeNode<Base>],
window: &WindowRc,
) {
window.free_graphics_resources(&mut item_tree.iter().filter_map(|entry| match entry {
crate::item_tree::ItemTreeNode::Item { item, .. } => Some(item.apply_pin(base)),
crate::item_tree::ItemTreeNode::DynamicTree { .. } => None,
}));
}
#[cfg(feature = "ffi")]
pub(crate) mod ffi {
#![allow(unsafe_code)]
use super::*;
use crate::item_tree::*;
use crate::slice::Slice;
#[no_mangle]
pub unsafe extern "C" fn sixtyfps_component_init_items(
component: ComponentRefPin,
item_tree: Slice<ItemTreeNode<u8>>,
window_handle: *const crate::window::ffi::WindowRcOpaque,
) {
let window = &*(window_handle as *const WindowRc);
super::init_component_items(
core::pin::Pin::new_unchecked(&*(component.as_ptr() as *const u8)),
item_tree.as_slice(),
window,
)
}
#[no_mangle]
pub unsafe extern "C" fn sixtyfps_component_free_item_graphics_resources(
component: ComponentRefPin,
item_tree: Slice<ItemTreeNode<u8>>,
window_handle: *const crate::window::ffi::WindowRcOpaque,
) {
let window = &*(window_handle as *const WindowRc);
super::free_component_item_graphics_resources(
core::pin::Pin::new_unchecked(&*(component.as_ptr() as *const u8)),
item_tree.as_slice(),
window,
)
}
}