iced_tiny_skia/
primitive.rs

1use crate::core::Rectangle;
2
3#[derive(Debug, Clone, PartialEq)]
4pub enum Primitive {
5    /// A path filled with some paint.
6    Fill {
7        /// The path to fill.
8        path: tiny_skia::Path,
9        /// The paint to use.
10        paint: tiny_skia::Paint<'static>,
11        /// The fill rule to follow.
12        rule: tiny_skia::FillRule,
13    },
14    /// A path stroked with some paint.
15    Stroke {
16        /// The path to stroke.
17        path: tiny_skia::Path,
18        /// The paint to use.
19        paint: tiny_skia::Paint<'static>,
20        /// The stroke settings.
21        stroke: tiny_skia::Stroke,
22    },
23}
24
25impl Primitive {
26    /// Returns the visible bounds of the [`Primitive`].
27    pub fn visible_bounds(&self) -> Rectangle {
28        let bounds = match self {
29            Primitive::Fill { path, .. } => path.bounds(),
30            Primitive::Stroke { path, .. } => path.bounds(),
31        };
32
33        Rectangle {
34            x: bounds.x(),
35            y: bounds.y(),
36            width: bounds.width(),
37            height: bounds.height(),
38        }
39    }
40}