Skip to main content

ferroui_base/rendering/composition/
composition_winui_layer_factories.rs

1//! The factories of the WinUI layer and redirect visuals, the nine-grid and
2//! mask brushes and the colour gradient stop (`Compositor.Create*` of
3//! `Microsoft.UI.Composition`, phase 2).
4
5use super::{
6    CompositionGradientStop, CompositionMaskBrush, CompositionNineGridBrush, CompositionVisual, Compositor,
7    LayerVisual, RedirectVisual,
8};
9use crate::media::Color;
10use std::rc::Rc;
11
12impl Compositor {
13    /// `CreateLayerVisual`: a container visual whose children are composed
14    /// into one layer.
15    pub fn create_layer_visual(&self) -> LayerVisual {
16        LayerVisual::new(&self.this_handle())
17    }
18
19    /// `CreateRedirectVisual`: a visual that shows the subtree of another
20    /// visual, without a source.
21    pub fn create_redirect_visual(&self) -> RedirectVisual {
22        RedirectVisual::new(&self.this_handle())
23    }
24
25    /// `CreateRedirectVisual(source)`: a visual that shows the subtree of
26    /// `source`.
27    pub fn create_redirect_visual_with_source_visual(&self, source: Option<Rc<CompositionVisual>>) -> RedirectVisual {
28        RedirectVisual::with_source(&self.this_handle(), source)
29    }
30
31    /// `CreateNineGridBrush`: a brush that paints another brush as a
32    /// nine-grid.
33    pub fn create_nine_grid_brush(&self) -> CompositionNineGridBrush {
34        CompositionNineGridBrush::new(&self.this_handle())
35    }
36
37    /// `CreateMaskBrush`: a brush that paints a brush through the alpha of
38    /// another.
39    pub fn create_mask_brush(&self) -> CompositionMaskBrush {
40        CompositionMaskBrush::new(&self.this_handle())
41    }
42
43    /// `CreateColorGradientStop(offset, color)`: the WinUI name of
44    /// [`create_gradient_stop_with`](Self::create_gradient_stop_with).
45    pub fn create_color_gradient_stop(&self, offset: f32, color: Color) -> Rc<CompositionGradientStop> {
46        self.create_gradient_stop_with(offset as f64, color)
47    }
48
49    /// `CreateColorGradientStop()`: the WinUI name of
50    /// [`create_gradient_stop`](Self::create_gradient_stop).
51    pub fn create_color_gradient_stop_default(&self) -> Rc<CompositionGradientStop> {
52        self.create_gradient_stop()
53    }
54}