skia_safe/modules/svg/
container.rs

1use super::{DebugAttributes, Node, NodeSubtype, TypedNode};
2use crate::prelude::*;
3use skia_bindings as sb;
4
5pub type Container = RCHandle<sb::SkSVGContainer>;
6
7impl NodeSubtype for sb::SkSVGContainer {
8    type Base = sb::SkSVGTransformableNode;
9}
10
11impl DebugAttributes for Container {
12    const NAME: &'static str = "Container";
13
14    fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
15        self.as_base()
16            ._dbg(builder.field("children", &self.children_typed()));
17    }
18}
19
20impl Container {
21    pub fn append_child(&mut self, node: impl Into<Node>) {
22        unsafe { sb::C_SkSVGContainer_appendChild(self.native_mut(), node.into().into_ptr()) }
23    }
24
25    pub fn children(&self) -> &[Node] {
26        unsafe {
27            let sp_slice = safer::from_raw_parts(
28                sb::C_SkSVGContainer_children(self.native()),
29                self.children_count(),
30            );
31
32            RCHandle::from_non_null_sp_slice(sp_slice)
33        }
34    }
35
36    pub fn children_typed(&self) -> Vec<TypedNode> {
37        self.children().iter().cloned().map(|n| n.typed()).collect()
38    }
39
40    pub(crate) fn children_count(&self) -> usize {
41        unsafe {
42            usize::try_from(sb::C_SkSVGContainer_childrenCount(self.native())).unwrap_or_default()
43        }
44    }
45}