Skip to main content

cranpose_ui/modifier/
graphics_layer.rs

1use std::{rc::Rc, sync::Arc};
2
3use cranpose_ui_graphics::{
4    BlendMode, Color, ColorFilter, CompositingStrategy, Density, Dp, GradientBlurDirection,
5    GradientBlurProfile, GradientCutMaskSpec, GradientFadeMaskSpec, LayerShape, Px, RenderEffect,
6    RoundedCornerShape, RuntimeShader, TransformOrigin, gradient_blur_effect,
7    gradient_cut_mask_effect, gradient_fade_dst_out_effect, rounded_alpha_mask_effect,
8    space::{LayerSpace, Mat4, MeshSurface, MeshSurfaces, Scene3d},
9};
10
11use super::{GraphicsLayer, Modifier, inspector_metadata};
12use crate::modifier_nodes::{GraphicsLayerElement, LazyGraphicsLayerElement};
13
14fn backdrop_blur_layer(radius: Dp, shape: LayerShape) -> GraphicsLayer {
15    let density = Density::from_scale(crate::render_state::current_density());
16    let radius_px = radius.to_px(density).max(Px::ZERO);
17    GraphicsLayer {
18        backdrop_effect: (radius_px.0 > 0.0).then(|| RenderEffect::blur(radius_px.0)),
19        shape,
20        clip: true,
21        ..Default::default()
22    }
23}
24
25fn backdrop_gradient_blur_layer(
26    start_radius: Dp,
27    end_radius: Dp,
28    direction: GradientBlurDirection,
29    profile: GradientBlurProfile,
30) -> GraphicsLayer {
31    let density = Density::from_scale(crate::render_state::current_density());
32    let start_px = start_radius.to_px(density).max(Px::ZERO);
33    let end_px = end_radius.to_px(density).max(Px::ZERO);
34    GraphicsLayer {
35        backdrop_effect: (start_px.0 > 0.0 || end_px.0 > 0.0)
36            .then(|| gradient_blur_effect(start_px.0, end_px.0, direction, profile)),
37        shape: LayerShape::Rectangle,
38        clip: true,
39        ..Default::default()
40    }
41}
42
43impl Modifier {
44    /// Apply a lazily evaluated graphics layer.
45    ///
46    /// The closure is evaluated during scene building, not composition, which lets
47    /// layer properties update without forcing recomposition.
48    ///
49    /// Example:
50    /// `Modifier::empty().graphics_layer(|| GraphicsLayer { alpha: 0.5, ..Default::default() })`
51    ///
52    /// # A drag that drives the translation must not be read inside it
53    ///
54    /// [`PointerEvent::position`](crate::modifier::PointerEvent::position) is
55    /// in the receiving node's own space, so a node this layer translates
56    /// reports a finger that has moved only as far as it OUTRAN the
57    /// translation. Feed that position back into `translation_x` and the
58    /// gesture measures itself:
59    ///
60    /// ```text
61    /// reported = finger - offset          offset = reported - start
62    ///         => offset = (finger - start) / 2
63    /// ```
64    ///
65    /// The offset converges on half the finger's travel and can never exceed
66    /// it, so a swipe-to-dismiss whose threshold is half the width never
67    /// crosses it however far the finger goes -- silently, with the content
68    /// sliding convincingly the whole time.
69    ///
70    /// Two ways out, and [`SwipeToDismiss`](crate::widgets::SwipeToDismiss)
71    /// uses both:
72    ///
73    /// - put `pointer_input` on a node OUTSIDE the translated one, which is
74    ///   also how Compose's own `SwipeToDismissBox` is built -- the drag is
75    ///   detected on the box, the content carries the layer;
76    /// - or read
77    ///   [`PointerEvent::global_position`](crate::modifier::PointerEvent::global_position),
78    ///   which no layer transform touches.
79    pub fn graphics_layer(self, layer: impl Fn() -> GraphicsLayer + 'static) -> Self {
80        let modifier = Self::with_element(LazyGraphicsLayerElement::new(Rc::new(layer)))
81            .with_inspector_metadata(inspector_metadata("graphicsLayer", |info| {
82                info.add_property("lazy", "true");
83            }));
84        self.then(modifier)
85    }
86
87    /// Shows a 3D scene in this node's bounds.
88    ///
89    /// Every node inside the scene takes a 3D frame from its parent's: its
90    /// place in its parent's layout, on the parent's plane, with x right, y
91    /// down and z away from the side the content shows to, a unit to a
92    /// logical pixel. The scene's own frame is its space, which the camera
93    /// looks into through the middle of the node's bounds; a camera one
94    /// focal length in front of the plane z = 0 shows the scene's children
95    /// at their own size, where layout put them. A child with a
96    /// [`mesh_surface`](Self::mesh_surface) draws its content on its mesh in
97    /// its frame, and nearer surfaces hide farther ones; a
98    /// [`transform3d`](Self::transform3d) moves the frames beneath it. The
99    /// scene is cut to the node's bounds, and the node's own draws and its
100    /// children's flat draws stay flat: those that come before the first
101    /// child in 3D are drawn under the scene, the rest over it.
102    ///
103    /// The scene covers what the modifiers after this one lay out, as a
104    /// Compose graphics layer does: a padding before `scene3d` insets it.
105    ///
106    /// A `scene3d` inside the scene is a doorway: the rect it covers, in its
107    /// frame, opens onto a space of its own, which lies behind it, placed so
108    /// the inner scene's camera stands in the doorway's middle (see
109    /// [`Camera::doorway`](cranpose_ui_graphics::space::Camera::doorway)).
110    /// The window's eye sees through each doorway that shows on screen, as
111    /// deep as they show, and walks through them (see [`Eye`](crate::Eye)).
112    ///
113    /// The closure runs when the scene is drawn, as a lazy
114    /// [`graphics_layer`](Self::graphics_layer)'s does, so a camera that
115    /// follows a state read in it moves without recomposition.
116    ///
117    /// ```
118    /// use std::sync::Arc;
119    ///
120    /// use cranpose_ui::Modifier;
121    /// use cranpose_ui_graphics::space::{
122    ///     Camera, Mat4, Material, Mesh, MeshSurface, Multisample, Scene3d, Vec3,
123    /// };
124    ///
125    /// let camera = Camera::look_at(
126    ///     Vec3::new(0.0, 0.0, -800.0),
127    ///     Vec3::ZERO,
128    ///     Vec3::new(0.0, 1.0, 0.0),
129    ///     700.0,
130    /// );
131    /// let scene = Modifier::empty().scene3d(move || Scene3d {
132    ///     camera,
133    ///     light: None,
134    ///     eye: None,
135    ///     multisample: Multisample::Off,
136    /// });
137    /// let sphere = Arc::new(Mesh::sphere(48, 24));
138    /// let globe = Modifier::empty().mesh_surface(move || MeshSurface {
139    ///     mesh: Arc::clone(&sphere),
140    ///     transform: Mat4::scaling(Vec3::new(200.0, 200.0, 200.0)),
141    ///     material: Material::Lit,
142    ///     casts_shadow: true,
143    ///     solid: true,
144    /// });
145    /// # let _ = (scene, globe);
146    /// ```
147    pub fn scene3d(self, scene: impl Fn() -> Scene3d + 'static) -> Self {
148        self.graphics_layer(move || GraphicsLayer {
149            space: Some(Arc::new(LayerSpace::Scene(scene()))),
150            clip: true,
151            ..GraphicsLayer::DEFAULT
152        })
153    }
154
155    /// Draws this node's content on a mesh in its scene, placed in the
156    /// node's 3D frame (see [`scene3d`](Self::scene3d)).
157    ///
158    /// The content laid on the mesh is what the modifiers after this one lay
159    /// out, as a Compose graphics layer covers the coordinator after it:
160    /// the node's own size, unless a modifier before this one, as a padding
161    /// or a size the parent does not hold, moves or sizes it. Content point
162    /// `(x, y)` from that content's corner shows where the mesh's texture
163    /// coordinate is `(x / width, y / height)`. The surface's transform places the mesh in
164    /// the node's frame, which starts where layout placed the node. The
165    /// content stays live and takes pointer input where it shows on the
166    /// mesh. The frames of the node's children lie in its content: x and y
167    /// in its content's pixels, z into it (see
168    /// [`MeshSurface::content_to_scene`](cranpose_ui_graphics::space::MeshSurface::content_to_scene)),
169    /// so a control can stand out of the wall it sits on, where layout put
170    /// it on the wall. A node outside every scene draws its content flat.
171    ///
172    /// The closure runs when the scene is drawn, as a lazy
173    /// [`graphics_layer`](Self::graphics_layer)'s does.
174    pub fn mesh_surface(self, surface: impl Fn() -> MeshSurface + 'static) -> Self {
175        self.mesh_surfaces(move || MeshSurfaces::from(surface()))
176    }
177
178    /// Draws this node's content on several meshes in its scene at once,
179    /// each placed in the node's 3D frame as
180    /// [`mesh_surface`](Self::mesh_surface) places its one: one live content
181    /// shown more than once, as a page and a photograph of it.
182    ///
183    /// The content is laid out and drawn once, and every mesh shows the same
184    /// picture of it. A pointer reaches the content where the nearest of the
185    /// meshes shows it, so a click on either copy of a word clicks that
186    /// word, and a drag stays on the mesh it started on, also past its edge.
187    /// The first mesh, [`MeshSurfaces::owner`], places the node for all that
188    /// takes one place: its children's 3D frames lie in its content as the
189    /// first mesh shows it, and the window and accessibility bounds of the
190    /// content are where the first mesh shows it.
191    ///
192    /// The closure runs when the scene is drawn, as a lazy
193    /// [`graphics_layer`](Self::graphics_layer)'s does.
194    ///
195    /// ```
196    /// use std::sync::Arc;
197    ///
198    /// use cranpose_ui::Modifier;
199    /// use cranpose_ui_graphics::space::{Mat4, Material, Mesh, MeshSurface, MeshSurfaces, Vec3};
200    ///
201    /// let plane = Arc::new(Mesh::plane());
202    /// let placed = move |x: f32| MeshSurface {
203    ///     mesh: Arc::clone(&plane),
204    ///     transform: Mat4::scaling(Vec3::new(300.0, 200.0, 1.0))
205    ///         .then(&Mat4::translation(Vec3::new(x, 0.0, 0.0))),
206    ///     material: Material::Unlit,
207    ///     casts_shadow: false,
208    ///     solid: true,
209    /// };
210    /// let twice = Modifier::empty()
211    ///     .mesh_surfaces(move || MeshSurfaces::new(placed(0.0), vec![placed(400.0)]));
212    /// # let _ = twice;
213    /// ```
214    pub fn mesh_surfaces(self, surfaces: impl Fn() -> MeshSurfaces + 'static) -> Self {
215        self.graphics_layer(move || GraphicsLayer {
216            space: Some(Arc::new(LayerSpace::Surface(surfaces()))),
217            clip: true,
218            ..GraphicsLayer::DEFAULT
219        })
220    }
221
222    /// Moves the 3D frames beneath this node by `transform`, in the node's
223    /// own frame, as a group of 3D objects moves together: the mesh surfaces
224    /// and doorways under it follow. The node's own draws and the flat draws
225    /// beneath it stay where they would be without it, and outside a scene
226    /// it changes nothing.
227    ///
228    /// The closure runs when the scene is drawn, as a lazy
229    /// [`graphics_layer`](Self::graphics_layer)'s does, so a group that
230    /// follows a state read in it moves without recomposition.
231    pub fn transform3d(self, transform: impl Fn() -> Mat4 + 'static) -> Self {
232        self.graphics_layer(move || GraphicsLayer {
233            space: Some(Arc::new(LayerSpace::Transform(transform()))),
234            ..GraphicsLayer::DEFAULT
235        })
236    }
237
238    /// Apply a concrete graphics layer snapshot.
239    ///
240    /// This is useful for parameter-style wrappers that already build a fixed
241    /// [`GraphicsLayer`] value.
242    pub fn graphics_layer_value(self, layer: GraphicsLayer) -> Self {
243        let inspector_values = layer.clone();
244        let modifier = Self::with_element(GraphicsLayerElement::new(layer))
245            .with_inspector_metadata(inspector_metadata("graphicsLayer", move |info| {
246                info.add_property("alpha", inspector_values.alpha.to_string());
247                info.add_property("scale", inspector_values.scale.to_string());
248                info.add_property("scaleX", inspector_values.scale_x.to_string());
249                info.add_property("scaleY", inspector_values.scale_y.to_string());
250                info.add_property("rotationX", inspector_values.rotation_x.to_string());
251                info.add_property("rotationY", inspector_values.rotation_y.to_string());
252                info.add_property("rotationZ", inspector_values.rotation_z.to_string());
253                info.add_property(
254                    "cameraDistance",
255                    inspector_values.camera_distance.to_string(),
256                );
257                info.add_property(
258                    "transformOrigin",
259                    format!(
260                        "{},{}",
261                        inspector_values.transform_origin.pivot_fraction_x,
262                        inspector_values.transform_origin.pivot_fraction_y
263                    ),
264                );
265                info.add_property("translationX", inspector_values.translation_x.to_string());
266                info.add_property("translationY", inspector_values.translation_y.to_string());
267                if let Some(space) = &inspector_values.space {
268                    info.add_property("space", format!("{space:?}"));
269                }
270                info.add_property(
271                    "shadowElevation",
272                    inspector_values.shadow_elevation.to_string(),
273                );
274                info.add_property("shape", format!("{:?}", inspector_values.shape));
275                info.add_property("clip", inspector_values.clip.to_string());
276                info.add_property(
277                    "ambientShadowColor",
278                    format!("{:?}", inspector_values.ambient_shadow_color),
279                );
280                info.add_property(
281                    "spotShadowColor",
282                    format!("{:?}", inspector_values.spot_shadow_color),
283                );
284                info.add_property(
285                    "compositingStrategy",
286                    format!("{:?}", inspector_values.compositing_strategy),
287                );
288                info.add_property("blendMode", format!("{:?}", inspector_values.blend_mode));
289                if let Some(filter) = inspector_values.color_filter {
290                    info.add_property("colorFilter", format!("{filter:?}"));
291                }
292            }));
293        self.then(modifier)
294    }
295
296    /// Compose-compatible parameter-style graphics layer entry point.
297    ///
298    /// This mirrors `Modifier.graphicsLayer(...)` style APIs and maps directly to
299    /// [`GraphicsLayer`] fields currently implemented by the renderer stack.
300    #[expect(clippy::too_many_arguments, reason = "Compose's parameters")]
301    pub fn graphics_layer_params(
302        self,
303        scale_x: f32,
304        scale_y: f32,
305        alpha: f32,
306        translation_x: f32,
307        translation_y: f32,
308        shadow_elevation: f32,
309        rotation_x: f32,
310        rotation_y: f32,
311        rotation_z: f32,
312        camera_distance: f32,
313        transform_origin: TransformOrigin,
314        shape: LayerShape,
315        clip: bool,
316        render_effect: Option<RenderEffect>,
317        ambient_shadow_color: Color,
318        spot_shadow_color: Color,
319        compositing_strategy: CompositingStrategy,
320        blend_mode: BlendMode,
321        color_filter: Option<ColorFilter>,
322    ) -> Self {
323        self.graphics_layer_value(GraphicsLayer {
324            alpha,
325            scale: 1.0,
326            scale_x,
327            scale_y,
328            rotation_x,
329            rotation_y,
330            rotation_z,
331            camera_distance,
332            transform_origin,
333            translation_x,
334            translation_y,
335            space: None,
336            shadow_elevation,
337            ambient_shadow_color,
338            spot_shadow_color,
339            shape,
340            clip,
341            compositing_strategy,
342            blend_mode,
343            color_filter,
344            render_effect,
345            backdrop_effect: None,
346        })
347    }
348
349    /// Compose-compatible block-style graphics layer entry point.
350    ///
351    /// Example:
352    /// `Modifier::empty().graphics_layer_block(|layer| { layer.alpha = 0.5; layer.scale_x = 1.2; })`
353    pub fn graphics_layer_block(self, configure: impl Fn(&mut GraphicsLayer) + 'static) -> Self {
354        self.graphics_layer(move || {
355            let mut layer = GraphicsLayer::default();
356            configure(&mut layer);
357            layer
358        })
359    }
360
361    /// Compose-style rotation convenience.
362    ///
363    /// Matches Kotlin: `Modifier.rotate(degrees: Float)`, which maps to
364    /// `graphicsLayer(rotationZ = degrees)`. Rotation is clockwise for
365    /// positive `degrees` and pivots around the layer's center, matching
366    /// `graphics_layer_value`'s default (centered) `transform_origin`.
367    pub fn rotate(self, degrees: f32) -> Self {
368        self.graphics_layer_value(GraphicsLayer {
369            rotation_z: degrees,
370            ..Default::default()
371        })
372    }
373
374    /// Compose-style uniform scale convenience.
375    ///
376    /// Matches Kotlin: `Modifier.scale(scale: Float)`, which maps to
377    /// `graphicsLayer(scaleX = scale, scaleY = scale)`.
378    pub fn scale(self, scale: f32) -> Self {
379        self.scale_xy(scale, scale)
380    }
381
382    /// Compose-style non-uniform scale convenience.
383    ///
384    /// Matches Kotlin: `Modifier.scale(scaleX: Float, scaleY: Float)`.
385    pub fn scale_xy(self, scale_x: f32, scale_y: f32) -> Self {
386        self.graphics_layer_value(GraphicsLayer {
387            scale_x,
388            scale_y,
389            ..Default::default()
390        })
391    }
392
393    /// Compose-style elevation shadow convenience.
394    ///
395    /// This mirrors `Modifier.shadow(elevation)` defaults:
396    /// rectangle shape, black ambient/spot colors, and clipping enabled when
397    /// elevation is positive.
398    pub fn shadow(self, elevation: f32) -> Self {
399        self.shadow_with(
400            elevation,
401            LayerShape::Rectangle,
402            elevation > 0.0,
403            Color::BLACK,
404            Color::BLACK,
405        )
406    }
407
408    /// Compose-style shadow API with explicit shape/clip/colors.
409    pub fn shadow_with(
410        self,
411        elevation: f32,
412        shape: LayerShape,
413        clip: bool,
414        ambient_color: Color,
415        spot_color: Color,
416    ) -> Self {
417        let clamped_elevation = elevation.max(0.0);
418        if clamped_elevation == 0.0 && !clip {
419            return self;
420        }
421
422        self.graphics_layer_value(GraphicsLayer {
423            shadow_elevation: clamped_elevation,
424            ambient_shadow_color: ambient_color,
425            spot_shadow_color: spot_color,
426            shape,
427            clip,
428            ..Default::default()
429        })
430    }
431
432    /// Apply a backdrop effect to content behind this composable's bounds.
433    pub fn backdrop_effect(self, effect: RenderEffect) -> Self {
434        let layer = GraphicsLayer {
435            backdrop_effect: Some(effect),
436            ..Default::default()
437        };
438        let modifier = Self::with_element(GraphicsLayerElement::new(layer))
439            .with_inspector_metadata(inspector_metadata("backdropEffect", |info| {
440                info.add_property("enabled", "true");
441            }));
442        self.then(modifier)
443    }
444
445    /// Blur content behind this composable, clipped to the composable bounds.
446    ///
447    /// `radius` is expressed in Dp and converted to px using the current render
448    /// density when modifier slices are evaluated.
449    pub fn backdrop_blur(self, radius: Dp) -> Self {
450        if radius.0 <= 0.0 {
451            return self.clip_to_bounds();
452        }
453
454        let modifier = Self::with_element(LazyGraphicsLayerElement::new(Rc::new(move || {
455            backdrop_blur_layer(radius, LayerShape::Rectangle)
456        })))
457        .with_inspector_metadata(inspector_metadata("backdropBlur", move |info| {
458            info.add_property("radius", radius.0.to_string());
459        }));
460        self.then(modifier)
461    }
462
463    /// Blur content behind this composable with a radius that changes across
464    /// its bounds. This is a true spatial blur gradient: the sampling kernel
465    /// interpolates from `start_radius` to `end_radius` in `direction`, over
466    /// the part of the bounds and through the levels `profile` names; it is
467    /// not an opacity gradient over a uniformly blurred layer.
468    pub fn backdrop_gradient_blur(
469        self,
470        start_radius: Dp,
471        end_radius: Dp,
472        direction: GradientBlurDirection,
473        profile: GradientBlurProfile,
474    ) -> Self {
475        if start_radius.0 <= 0.0 && end_radius.0 <= 0.0 {
476            return self.clip_to_bounds();
477        }
478        let modifier = Self::with_element(LazyGraphicsLayerElement::new(Rc::new(move || {
479            backdrop_gradient_blur_layer(start_radius, end_radius, direction, profile)
480        })))
481        .with_inspector_metadata(inspector_metadata(
482            "backdropGradientBlur",
483            move |info| {
484                info.add_property("startRadius", start_radius.0.to_string());
485                info.add_property("endRadius", end_radius.0.to_string());
486                info.add_property("direction", format!("{direction:?}"));
487                info.add_property("profile", format!("{profile:?}"));
488            },
489        ));
490        self.then(modifier)
491    }
492
493    /// Apply a frosted glass material: backdrop blur, clipped shape, and tint.
494    pub fn glass_material(self, material: GlassMaterial) -> Self {
495        let blur_radius = material.blur_radius;
496        let shape = material.shape;
497        let modifier = Self::with_element(LazyGraphicsLayerElement::new(Rc::new(move || {
498            backdrop_blur_layer(blur_radius, LayerShape::Rounded(shape))
499        })))
500        .with_inspector_metadata(inspector_metadata("glassMaterial", move |info| {
501            info.add_property("blurRadius", blur_radius.0.to_string());
502            info.add_property("shape", format!("{shape:?}"));
503        }));
504
505        self.then(modifier)
506            .rounded_corner_shape(material.shape)
507            .background(material.tint)
508    }
509
510    /// Convenience alias for applying a backdrop shader effect.
511    pub fn shader_background(self, shader: RuntimeShader) -> Self {
512        self.backdrop_effect(RenderEffect::runtime_shader(shader))
513    }
514
515    /// Apply a color filter to this composable's graphics layer output.
516    ///
517    /// This mirrors Compose's `graphicsLayer(colorFilter = ...)` capability.
518    pub fn color_filter(self, filter: ColorFilter) -> Self {
519        let layer = GraphicsLayer {
520            color_filter: Some(filter),
521            ..Default::default()
522        };
523        let modifier = Self::with_element(GraphicsLayerElement::new(layer))
524            .with_inspector_metadata(inspector_metadata("colorFilter", |info| {
525                info.add_property("enabled", "true");
526            }));
527        self.then(modifier)
528    }
529
530    /// Convenience color filter that tints layer output.
531    pub fn tint(self, tint: Color) -> Self {
532        self.color_filter(ColorFilter::tint(tint))
533    }
534
535    /// Configures how the layer is composited into its parent.
536    pub fn compositing_strategy(self, strategy: CompositingStrategy) -> Self {
537        self.graphics_layer_value(GraphicsLayer {
538            compositing_strategy: strategy,
539            ..Default::default()
540        })
541    }
542
543    /// Configures blend mode for this layer output.
544    ///
545    /// Runtime support is backend-dependent. Current renderers fully support
546    /// `SrcOver` and `DstOut`; unsupported modes fall back to `SrcOver`.
547    pub fn layer_blend_mode(self, blend_mode: BlendMode) -> Self {
548        self.graphics_layer_value(GraphicsLayer {
549            blend_mode,
550            ..Default::default()
551        })
552    }
553
554    /// Apply a directional gradient cut mask to this composable output.
555    ///
556    /// This masks the rendered layer with rounded corners and a feathered edge.
557    pub fn gradient_cut_mask(
558        self,
559        area_width: f32,
560        area_height: f32,
561        spec: GradientCutMaskSpec,
562    ) -> Self {
563        let layer = GraphicsLayer {
564            render_effect: Some(gradient_cut_mask_effect(&spec, area_width, area_height)),
565            ..Default::default()
566        };
567        self.graphics_layer_value(layer)
568    }
569
570    /// Apply a rounded alpha mask to this composable output.
571    ///
572    /// Useful to constrain a preceding render effect (for example blur) to a
573    /// rounded shape while preserving a soft edge transition.
574    pub fn rounded_alpha_mask(
575        self,
576        area_width: f32,
577        area_height: f32,
578        corner_radius: f32,
579        edge_feather: f32,
580    ) -> Self {
581        let has_radius = corner_radius.is_finite() && corner_radius > 0.0;
582        let has_feather = edge_feather.is_finite() && edge_feather > 0.0;
583        if !has_radius && !has_feather {
584            return self;
585        }
586        let layer = GraphicsLayer {
587            render_effect: Some(rounded_alpha_mask_effect(
588                area_width,
589                area_height,
590                corner_radius,
591                edge_feather,
592            )),
593            ..Default::default()
594        };
595        self.graphics_layer_value(layer)
596    }
597
598    /// Apply a directional gradient fade mask with destination-out semantics.
599    ///
600    /// This mirrors Compose's `drawWithContent + drawRect(..., BlendMode.DstOut)`
601    /// pattern for fading content to transparent along one axis.
602    pub fn gradient_fade_dst_out(
603        self,
604        area_width: f32,
605        area_height: f32,
606        spec: GradientFadeMaskSpec,
607    ) -> Self {
608        let layer = GraphicsLayer {
609            render_effect: Some(gradient_fade_dst_out_effect(&spec, area_width, area_height)),
610            ..Default::default()
611        };
612        self.graphics_layer_value(layer)
613    }
614}
615
616/// Visual parameters for [`Modifier::glass_material`].
617#[derive(Clone, Copy, Debug, PartialEq)]
618pub struct GlassMaterial {
619    /// Radius of the blur applied to what is behind the node.
620    pub blur_radius: Dp,
621    /// Color drawn over the blurred backdrop as the node's background.
622    pub tint: Color,
623    /// Rounded corners that clip the blur and the tint.
624    pub shape: RoundedCornerShape,
625}
626
627impl GlassMaterial {
628    /// Creates a material from its blur radius, tint and shape.
629    pub fn new(blur_radius: Dp, tint: Color, shape: RoundedCornerShape) -> Self {
630        Self {
631            blur_radius,
632            tint,
633            shape,
634        }
635    }
636}