Skip to main content

ferroui_base/rendering/composition/
composition_winui_factories.rs

1//! The factories of the WinUI visuals, brushes, surfaces, shadows and clips
2//! (`Compositor.Create*` of `Microsoft.UI.Composition`).
3
4use super::{
5    CompositionSolidColorBrush, CompositionSurfaceBrush, CompositionVisualSurface, Compositor, DropShadow,
6    ICompositionSurface, InsetClip, RectangleClip, SpriteVisual,
7};
8use crate::media::Color;
9use crate::Vector;
10use std::rc::Rc;
11
12impl Compositor {
13    /// `CreateSpriteVisual`: a visual that paints its size with a brush.
14    pub fn create_sprite_visual(&self) -> SpriteVisual {
15        SpriteVisual::new(&self.this_handle())
16    }
17
18    /// `CreateColorBrush`: the WinUI name of
19    /// [`create_solid_color_brush`](Self::create_solid_color_brush).
20    pub fn create_color_brush(&self) -> CompositionSolidColorBrush {
21        self.create_solid_color_brush()
22    }
23
24    /// `CreateColorBrush(color)`: the WinUI name of
25    /// [`create_solid_color_brush_with`](Self::create_solid_color_brush_with).
26    pub fn create_color_brush_with_color(&self, color: Color) -> CompositionSolidColorBrush {
27        self.create_solid_color_brush_with(color)
28    }
29
30    /// `CreateSurfaceBrush`: a brush that paints a surface, without a
31    /// surface.
32    pub fn create_surface_brush(&self) -> CompositionSurfaceBrush {
33        CompositionSurfaceBrush::new(&self.this_handle())
34    }
35
36    /// `CreateSurfaceBrush(surface)`: a brush that paints `surface`.
37    pub fn create_surface_brush_with_surface(&self, surface: Rc<dyn ICompositionSurface>) -> CompositionSurfaceBrush {
38        CompositionSurfaceBrush::with_surface(&self.this_handle(), surface)
39    }
40
41    /// `CreateVisualSurface`: a live image of the subtree of a visual.
42    pub fn create_visual_surface(&self) -> Rc<CompositionVisualSurface> {
43        CompositionVisualSurface::new(&self.this_handle())
44    }
45
46    /// `CreateDropShadow`: a shadow for a sprite visual.
47    pub fn create_drop_shadow(&self) -> Rc<DropShadow> {
48        DropShadow::new(&self.this_handle())
49    }
50
51    /// `CreateInsetClip`: a clip with zero insets.
52    pub fn create_inset_clip(&self) -> InsetClip {
53        InsetClip::new(&self.this_handle())
54    }
55
56    /// `CreateInsetClip(leftInset, topInset, rightInset, bottomInset)`.
57    pub fn create_inset_clip_with_insets(&self, left: f32, top: f32, right: f32, bottom: f32) -> InsetClip {
58        InsetClip::with_insets(&self.this_handle(), left, top, right, bottom)
59    }
60
61    /// `CreateRectangleClip`: a clip whose edges are all zero (it leaves
62    /// nothing visible until its edges are set).
63    pub fn create_rectangle_clip(&self) -> RectangleClip {
64        RectangleClip::new(&self.this_handle())
65    }
66
67    /// `CreateRectangleClip(left, top, right, bottom)`.
68    pub fn create_rectangle_clip_with(&self, left: f32, top: f32, right: f32, bottom: f32) -> RectangleClip {
69        RectangleClip::with_edges(&self.this_handle(), left, top, right, bottom)
70    }
71
72    /// `CreateRectangleClip(left, top, right, bottom, topLeftRadius,
73    /// topRightRadius, bottomRightRadius, bottomLeftRadius)`.
74    #[allow(clippy::too_many_arguments)]
75    pub fn create_rectangle_clip_with_radii(
76        &self,
77        left: f32,
78        top: f32,
79        right: f32,
80        bottom: f32,
81        top_left_radius: Vector,
82        top_right_radius: Vector,
83        bottom_right_radius: Vector,
84        bottom_left_radius: Vector,
85    ) -> RectangleClip {
86        RectangleClip::with_edges_and_radii(
87            &self.this_handle(),
88            left,
89            top,
90            right,
91            bottom,
92            top_left_radius,
93            top_right_radius,
94            bottom_right_radius,
95            bottom_left_radius,
96        )
97    }
98}