skia_safe/modules/svg/shape/
poly.rs

1use crate::{
2    prelude::*,
3    svg::{DebugAttributes, NodeSubtype},
4    Point,
5};
6use skia_bindings as sb;
7
8pub type Poly = RCHandle<sb::SkSVGPoly>;
9
10impl NodeSubtype for sb::SkSVGPoly {
11    type Base = sb::SkSVGShape;
12}
13
14impl DebugAttributes for Poly {
15    const NAME: &'static str = "Poly";
16
17    fn _dbg(&self, builder: &mut std::fmt::DebugStruct) {
18        self.as_base()._dbg(builder.field("points", &self.points()));
19    }
20}
21
22impl Poly {
23    pub fn polygon() -> Self {
24        Self::from_ptr(unsafe { sb::C_SkSVGPoly_MakePolygon() }).unwrap()
25    }
26
27    pub fn polyline() -> Self {
28        Self::from_ptr(unsafe { sb::C_SkSVGPoly_MakePolyline() }).unwrap()
29    }
30
31    pub fn points(&self) -> &[Point] {
32        unsafe {
33            safer::from_raw_parts(
34                Point::from_native_ptr(sb::C_SkSVGPoly_getPoints(self.native())),
35                sb::C_SkSVGPoly_getPointsCount(self.native()),
36            )
37        }
38    }
39}