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