Skip to main content

ferroui_base/rendering/composition/
composition_shape_factories.rs

1//! The factories of the WinUI shapes, geometries, view boxes and geometric
2//! clips (`Compositor.Create*` of `Microsoft.UI.Composition`).
3
4use super::{
5    CompositionContainerShape, CompositionEllipseGeometry, CompositionGeometry, CompositionLineGeometry,
6    CompositionPath, CompositionPathGeometry, CompositionRectangleGeometry, CompositionRoundedRectangleGeometry,
7    CompositionSpriteShape, CompositionViewBox, Compositor, GeometricClip, ShapeVisual,
8};
9use std::rc::Rc;
10
11impl Compositor {
12    /// `CreateShapeVisual`: a visual that draws shapes.
13    pub fn create_shape_visual(&self) -> ShapeVisual {
14        ShapeVisual::new(&self.this_handle())
15    }
16
17    /// `CreateSpriteShape`: a shape without a geometry.
18    pub fn create_sprite_shape(&self) -> CompositionSpriteShape {
19        CompositionSpriteShape::new(&self.this_handle())
20    }
21
22    /// `CreateSpriteShape(geometry)`: a shape that draws `geometry`.
23    pub fn create_sprite_shape_with_geometry(&self, geometry: Option<Rc<CompositionGeometry>>) -> CompositionSpriteShape {
24        CompositionSpriteShape::with_geometry(&self.this_handle(), geometry)
25    }
26
27    /// `CreateContainerShape`: a shape that groups shapes.
28    pub fn create_container_shape(&self) -> CompositionContainerShape {
29        CompositionContainerShape::new(&self.this_handle())
30    }
31
32    /// `CreateRectangleGeometry`: an empty rectangle at the origin.
33    pub fn create_rectangle_geometry(&self) -> CompositionRectangleGeometry {
34        CompositionRectangleGeometry::new(&self.this_handle())
35    }
36
37    /// `CreateRoundedRectangleGeometry`: an empty rounded rectangle at the
38    /// origin.
39    pub fn create_rounded_rectangle_geometry(&self) -> CompositionRoundedRectangleGeometry {
40        CompositionRoundedRectangleGeometry::new(&self.this_handle())
41    }
42
43    /// `CreateEllipseGeometry`: an ellipse with zero radii at the origin.
44    pub fn create_ellipse_geometry(&self) -> CompositionEllipseGeometry {
45        CompositionEllipseGeometry::new(&self.this_handle())
46    }
47
48    /// `CreateLineGeometry`: a line from the origin to the origin.
49    pub fn create_line_geometry(&self) -> CompositionLineGeometry {
50        CompositionLineGeometry::new(&self.this_handle())
51    }
52
53    /// `CreatePathGeometry`: a geometry without a path.
54    pub fn create_path_geometry(&self) -> CompositionPathGeometry {
55        CompositionPathGeometry::new(&self.this_handle())
56    }
57
58    /// `CreatePathGeometry(path)`: a geometry that shows `path`.
59    pub fn create_path_geometry_with_path(&self, path: Option<CompositionPath>) -> CompositionPathGeometry {
60        CompositionPathGeometry::with_path(&self.this_handle(), path)
61    }
62
63    /// `CreateViewBox`: a view box with a zero size.
64    pub fn create_view_box(&self) -> Rc<CompositionViewBox> {
65        CompositionViewBox::new(&self.this_handle())
66    }
67
68    /// `CreateGeometricClip`: a clip without a geometry.
69    pub fn create_geometric_clip(&self) -> GeometricClip {
70        GeometricClip::new(&self.this_handle())
71    }
72
73    /// `CreateGeometricClip(geometry)`: a clip to the inside of `geometry`.
74    pub fn create_geometric_clip_with_geometry(&self, geometry: Option<Rc<CompositionGeometry>>) -> GeometricClip {
75        GeometricClip::with_geometry(&self.this_handle(), geometry)
76    }
77}