Skip to main content

ferroui_base/media/
path_geometry_collections.rs

1use crate::media::media_collection::media_collection_type;
2use crate::media::{MediaCollection, PathFigure, PathGeometry, PathSegment};
3use crate::utilities::FormatError;
4use crate::Ref;
5
6media_collection_type!(
7    /// A collection of [`PathFigure`]s.
8    PathFigures, Ref<PathFigure>
9);
10
11impl PathFigures {
12    /// Creates an empty collection.
13    pub fn new() -> Self {
14        Self(MediaCollection::new())
15    }
16
17    /// Creates a collection holding `items`.
18    pub fn from_items(items: impl IntoIterator<Item = Ref<PathFigure>>) -> Self {
19        Self(MediaCollection::from_items(items))
20    }
21
22    /// Parses the specified path data to path figures.
23    pub fn parse(path_data: &str) -> Result<PathFigures, FormatError> {
24        let path_geometry = PathGeometry::parse(path_data)?;
25        Ok(path_geometry.figures().expect("a parsed path geometry has figures"))
26    }
27}
28
29media_collection_type!(
30    /// A collection of [`PathSegment`]s.
31    PathSegments, Ref<PathSegment>
32);
33
34impl PathSegments {
35    /// Creates an empty collection.
36    pub fn new() -> Self {
37        Self(MediaCollection::new())
38    }
39
40    /// Creates a collection holding `items`.
41    pub fn from_items(items: impl IntoIterator<Item = Ref<PathSegment>>) -> Self {
42        Self(MediaCollection::from_items(items))
43    }
44
45    /// Creates an empty collection with the given capacity.
46    pub fn with_capacity(capacity: usize) -> Self {
47        let _ = capacity;
48        Self(MediaCollection::new())
49    }
50}