pub struct Modifier { /* private fields */ }Expand description
A modifier chain that can be applied to composable elements.
Modifiers allow you to decorate or augment a composable. Common operations include:
- Adjusting layout (e.g.,
padding,fill_max_size) - Adding behavior (e.g.,
clickable,scrollable) - Drawing (e.g.,
background,border)
Modifiers are immutable and form a chain using the builder pattern. The order of modifiers matters: previous modifiers wrap subsequent ones.
§Example
Modifier::padding(16.0) // Applied first (outer)
.background(Color::Red) // Applied second
.clickable(|| println!("Clicked")) // Applied last (inner)Implementations§
Source§impl Modifier
impl Modifier
pub fn align(self, alignment: Alignment) -> Self
pub fn alignInBox(self, alignment: Alignment) -> Self
pub fn alignInColumn(self, alignment: HorizontalAlignment) -> Self
pub fn alignInRow(self, alignment: VerticalAlignment) -> Self
Source§impl Modifier
impl Modifier
Sourcepub fn background(self, color: Color) -> Self
pub fn background(self, color: Color) -> Self
Set the background color.
Example: Modifier::empty().background(Color::rgb(1.0, 0.0, 0.0))
Sourcepub fn rounded_corners(self, radius: f32) -> Self
pub fn rounded_corners(self, radius: f32) -> Self
Add rounded corners with uniform radius.
Example: Modifier::empty().rounded_corners(8.0)
Sourcepub fn rounded_corner_shape(self, shape: RoundedCornerShape) -> Self
pub fn rounded_corner_shape(self, shape: RoundedCornerShape) -> Self
Add rounded corners with a custom shape.
Example: Modifier::empty().rounded_corner_shape(shape)
Source§impl Modifier
impl Modifier
Sourcepub fn blur(self, radius: Dp) -> Self
pub fn blur(self, radius: Dp) -> Self
Apply a Gaussian blur effect to this composable’s rendered content.
radius is expressed in Dp and converted to px using the current render
density when modifier slices are evaluated.
Compose parity: this defaults to bounded rectangular edge treatment.
Sourcepub fn blur_with_edge_treatment(
self,
radius: Dp,
edge_treatment: BlurredEdgeTreatment,
) -> Self
pub fn blur_with_edge_treatment( self, radius: Dp, edge_treatment: BlurredEdgeTreatment, ) -> Self
Apply an isotropic Gaussian blur with explicit edge treatment.
Compose parity:
- bounded treatment clips to shape and uses clamp sampling
- unbounded treatment disables clip and uses decal sampling
Sourcepub fn blur_xy(
self,
radius_x: Dp,
radius_y: Dp,
edge_treatment: BlurredEdgeTreatment,
) -> Self
pub fn blur_xy( self, radius_x: Dp, radius_y: Dp, edge_treatment: BlurredEdgeTreatment, ) -> Self
Apply a Gaussian blur effect with separate horizontal and vertical radii.
Radii are expressed in Dp and converted to px at evaluation time.
Source§impl Modifier
impl Modifier
Sourcepub fn draw_with_content(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self
pub fn draw_with_content(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self
Draw around content.
draw_content() splits drawing into behind (before) and overlay (after)
phases. If draw_content() is never called, primitives are treated as
overlay for backward compatibility.
Example: Modifier::empty().draw_with_content(|scope| { ... })
Sourcepub fn draw_behind(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self
pub fn draw_behind(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self
Draw content behind.
Example: Modifier::empty().draw_behind(|scope| { ... })
Sourcepub fn draw_with_cache(self, build: impl FnOnce(&mut DrawCacheBuilder)) -> Self
pub fn draw_with_cache(self, build: impl FnOnce(&mut DrawCacheBuilder)) -> Self
Draw with cache.
Example: Modifier::empty().draw_with_cache(|builder| { ... })
Source§impl Modifier
impl Modifier
Sourcepub fn fill_max_width(self) -> Self
pub fn fill_max_width(self) -> Self
Have the content fill the maximum available width.
The [fraction] parameter allows filling only a portion of the available width (0.0 to 1.0).
Matches Kotlin: Modifier.fillMaxWidth(fraction: Float)
Example: Modifier::empty().fill_max_width()
Sourcepub fn fill_max_width_fraction(self, fraction: f32) -> Self
pub fn fill_max_width_fraction(self, fraction: f32) -> Self
Fill a fraction of the maximum available width.
Example: Modifier::empty().fill_max_width_fraction(0.5)
Sourcepub fn fill_max_height(self) -> Self
pub fn fill_max_height(self) -> Self
Have the content fill the maximum available height.
The [fraction] parameter allows filling only a portion of the available height (0.0 to 1.0).
Matches Kotlin: Modifier.fillMaxHeight(fraction: Float)
Example: Modifier::empty().fill_max_height()
Sourcepub fn fill_max_height_fraction(self, fraction: f32) -> Self
pub fn fill_max_height_fraction(self, fraction: f32) -> Self
Fill a fraction of the maximum available height.
Example: Modifier::empty().fill_max_height_fraction(0.5)
Sourcepub fn fill_max_size(self) -> Self
pub fn fill_max_size(self) -> Self
Have the content fill the maximum available size (both width and height).
The [fraction] parameter allows filling only a portion of the available size (0.0 to 1.0).
Matches Kotlin: Modifier.fillMaxSize(fraction: Float)
Example: Modifier::empty().fill_max_size()
Sourcepub fn fill_max_size_fraction(self, fraction: f32) -> Self
pub fn fill_max_size_fraction(self, fraction: f32) -> Self
Fill a fraction of the maximum available size.
Example: Modifier::empty().fill_max_size_fraction(0.8)
Source§impl Modifier
impl Modifier
Sourcepub fn graphics_layer(self, layer: impl Fn() -> GraphicsLayer + 'static) -> Self
pub fn graphics_layer(self, layer: impl Fn() -> GraphicsLayer + 'static) -> Self
Apply a lazily evaluated graphics layer.
The closure is evaluated during scene building, not composition, which lets layer properties update without forcing recomposition.
Example:
Modifier::empty().graphics_layer(|| GraphicsLayer { alpha: 0.5, ..Default::default() })
Sourcepub fn graphics_layer_value(self, layer: GraphicsLayer) -> Self
pub fn graphics_layer_value(self, layer: GraphicsLayer) -> Self
Apply a concrete graphics layer snapshot.
This is useful for parameter-style wrappers that already build a fixed
GraphicsLayer value.
Sourcepub fn graphics_layer_params(
self,
scale_x: f32,
scale_y: f32,
alpha: f32,
translation_x: f32,
translation_y: f32,
shadow_elevation: f32,
rotation_x: f32,
rotation_y: f32,
rotation_z: f32,
camera_distance: f32,
transform_origin: TransformOrigin,
shape: LayerShape,
clip: bool,
render_effect: Option<RenderEffect>,
ambient_shadow_color: Color,
spot_shadow_color: Color,
compositing_strategy: CompositingStrategy,
blend_mode: BlendMode,
color_filter: Option<ColorFilter>,
) -> Self
pub fn graphics_layer_params( self, scale_x: f32, scale_y: f32, alpha: f32, translation_x: f32, translation_y: f32, shadow_elevation: f32, rotation_x: f32, rotation_y: f32, rotation_z: f32, camera_distance: f32, transform_origin: TransformOrigin, shape: LayerShape, clip: bool, render_effect: Option<RenderEffect>, ambient_shadow_color: Color, spot_shadow_color: Color, compositing_strategy: CompositingStrategy, blend_mode: BlendMode, color_filter: Option<ColorFilter>, ) -> Self
Compose-compatible parameter-style graphics layer entry point.
This mirrors Modifier.graphicsLayer(...) style APIs and maps directly to
GraphicsLayer fields currently implemented by the renderer stack.
Sourcepub fn graphics_layer_block(
self,
configure: impl Fn(&mut GraphicsLayer) + 'static,
) -> Self
pub fn graphics_layer_block( self, configure: impl Fn(&mut GraphicsLayer) + 'static, ) -> Self
Compose-compatible block-style graphics layer entry point.
Example:
Modifier::empty().graphics_layer_block(|layer| { layer.alpha = 0.5; layer.scale_x = 1.2; })
Sourcepub fn shadow(self, elevation: f32) -> Self
pub fn shadow(self, elevation: f32) -> Self
Compose-style elevation shadow convenience.
This mirrors Modifier.shadow(elevation) defaults:
rectangle shape, black ambient/spot colors, and clipping enabled when
elevation is positive.
Sourcepub fn shadow_with(
self,
elevation: f32,
shape: LayerShape,
clip: bool,
ambient_color: Color,
spot_color: Color,
) -> Self
pub fn shadow_with( self, elevation: f32, shape: LayerShape, clip: bool, ambient_color: Color, spot_color: Color, ) -> Self
Compose-style shadow API with explicit shape/clip/colors.
Sourcepub fn backdrop_effect(self, effect: RenderEffect) -> Self
pub fn backdrop_effect(self, effect: RenderEffect) -> Self
Apply a backdrop effect to content behind this composable’s bounds.
Sourcepub fn shader_background(self, shader: RuntimeShader) -> Self
pub fn shader_background(self, shader: RuntimeShader) -> Self
Convenience alias for applying a backdrop shader effect.
Sourcepub fn color_filter(self, filter: ColorFilter) -> Self
pub fn color_filter(self, filter: ColorFilter) -> Self
Apply a color filter to this composable’s graphics layer output.
This mirrors Compose’s graphicsLayer(colorFilter = ...) capability.
Sourcepub fn compositing_strategy(self, strategy: CompositingStrategy) -> Self
pub fn compositing_strategy(self, strategy: CompositingStrategy) -> Self
Configures how the layer is composited into its parent.
Sourcepub fn layer_blend_mode(self, blend_mode: BlendMode) -> Self
pub fn layer_blend_mode(self, blend_mode: BlendMode) -> Self
Configures blend mode for this layer output.
Runtime support is backend-dependent. Current renderers fully support
SrcOver and DstOut; unsupported modes fall back to SrcOver.
Sourcepub fn gradient_cut_mask(
self,
area_width: f32,
area_height: f32,
spec: GradientCutMaskSpec,
) -> Self
pub fn gradient_cut_mask( self, area_width: f32, area_height: f32, spec: GradientCutMaskSpec, ) -> Self
Apply a directional gradient cut mask to this composable output.
This masks the rendered layer with rounded corners and a feathered edge.
Sourcepub fn rounded_alpha_mask(
self,
area_width: f32,
area_height: f32,
corner_radius: f32,
edge_feather: f32,
) -> Self
pub fn rounded_alpha_mask( self, area_width: f32, area_height: f32, corner_radius: f32, edge_feather: f32, ) -> Self
Apply a rounded alpha mask to this composable output.
Useful to constrain a preceding render effect (for example blur) to a rounded shape while preserving a soft edge transition.
Sourcepub fn gradient_fade_dst_out(
self,
area_width: f32,
area_height: f32,
spec: GradientFadeMaskSpec,
) -> Self
pub fn gradient_fade_dst_out( self, area_width: f32, area_height: f32, spec: GradientFadeMaskSpec, ) -> Self
Apply a directional gradient fade mask with destination-out semantics.
This mirrors Compose’s drawWithContent + drawRect(..., BlendMode.DstOut)
pattern for fading content to transparent along one axis.
Source§impl Modifier
impl Modifier
Sourcepub fn offset(self, x: f32, y: f32) -> Self
pub fn offset(self, x: f32, y: f32) -> Self
Offset the content by (x, y). The offsets can be positive or negative.
This modifier is RTL-aware: positive x offsets move content right in LTR and left in RTL layouts.
Matches Kotlin: Modifier.offset(x: Dp, y: Dp)
Example: Modifier::empty().offset(10.0, 20.0)
Sourcepub fn absolute_offset(self, x: f32, y: f32) -> Self
pub fn absolute_offset(self, x: f32, y: f32) -> Self
Offset the content by (x, y) without considering layout direction.
Positive x always moves content to the right regardless of RTL.
Matches Kotlin: Modifier.absoluteOffset(x: Dp, y: Dp)
Example: Modifier::empty().absolute_offset(10.0, 20.0)
Source§impl Modifier
impl Modifier
Sourcepub fn padding(self, p: f32) -> Self
pub fn padding(self, p: f32) -> Self
Add uniform padding to all sides.
Example: Modifier::empty().padding(16.0)
Sourcepub fn padding_horizontal(self, horizontal: f32) -> Self
pub fn padding_horizontal(self, horizontal: f32) -> Self
Add horizontal padding (left and right).
Example: Modifier::empty().padding_horizontal(16.0)
Sourcepub fn padding_vertical(self, vertical: f32) -> Self
pub fn padding_vertical(self, vertical: f32) -> Self
Add vertical padding (top and bottom).
Example: Modifier::empty().padding_vertical(8.0)
Sourcepub fn padding_symmetric(self, horizontal: f32, vertical: f32) -> Self
pub fn padding_symmetric(self, horizontal: f32, vertical: f32) -> Self
Add symmetric padding (horizontal and vertical).
Example: Modifier::empty().padding_symmetric(16.0, 8.0)
Source§impl Modifier
impl Modifier
pub fn pointer_input<K, F, Fut>(self, key: K, handler: F) -> Selfwhere
K: Hash + 'static,
F: Fn(PointerInputScope) -> Fut + 'static,
Fut: Future<Output = ()> + 'static,
Source§impl Modifier
impl Modifier
Sourcepub fn horizontal_scroll(
self,
state: ScrollState,
reverse_scrolling: bool,
) -> Self
pub fn horizontal_scroll( self, state: ScrollState, reverse_scrolling: bool, ) -> Self
Creates a horizontally scrollable modifier.
§Arguments
state- The ScrollState to control scroll positionreverse_scrolling- If true, reverses the scroll direction in layout. Note: This affects how scroll offset is applied to content (viaScrollNode), NOT the drag direction. Drag gestures always follow natural touch semantics: drag right = scroll left (content moves right under finger).
§Example
let scroll_state = ScrollState::new(0.0);
Row(
Modifier::empty().horizontal_scroll(scroll_state, false),
// ... content
);Sourcepub fn vertical_scroll(
self,
state: ScrollState,
reverse_scrolling: bool,
) -> Self
pub fn vertical_scroll( self, state: ScrollState, reverse_scrolling: bool, ) -> Self
Creates a vertically scrollable modifier.
§Arguments
state- The ScrollState to control scroll positionreverse_scrolling- If true, reverses the scroll direction in layout. Note: This affects how scroll offset is applied to content (viaScrollNode), NOT the drag direction. Drag gestures always follow natural touch semantics: drag down = scroll up (content moves down under finger).
Sourcepub fn horizontal_scroll_guarded(
self,
state: ScrollState,
reverse_scrolling: bool,
guard: impl Fn() -> bool + 'static,
) -> Self
pub fn horizontal_scroll_guarded( self, state: ScrollState, reverse_scrolling: bool, guard: impl Fn() -> bool + 'static, ) -> Self
Creates a horizontally scrollable modifier with a guard that can disable scrolling.
Sourcepub fn vertical_scroll_guarded(
self,
state: ScrollState,
reverse_scrolling: bool,
guard: impl Fn() -> bool + 'static,
) -> Self
pub fn vertical_scroll_guarded( self, state: ScrollState, reverse_scrolling: bool, guard: impl Fn() -> bool + 'static, ) -> Self
Creates a vertically scrollable modifier with a guard that can disable scrolling.
Source§impl Modifier
impl Modifier
Sourcepub fn lazy_vertical_scroll(
self,
state: LazyListState,
reverse_scrolling: bool,
) -> Self
pub fn lazy_vertical_scroll( self, state: LazyListState, reverse_scrolling: bool, ) -> Self
Creates a vertically scrollable modifier for lazy lists.
This connects pointer gestures to LazyListState for scroll handling. Unlike regular vertical_scroll, no layout offset is applied here since LazyListState manages item positioning internally. Creates a vertically scrollable modifier for lazy lists.
This connects pointer gestures to LazyListState for scroll handling. Unlike regular vertical_scroll, no layout offset is applied here since LazyListState manages item positioning internally.
Sourcepub fn lazy_horizontal_scroll(
self,
state: LazyListState,
reverse_scrolling: bool,
) -> Self
pub fn lazy_horizontal_scroll( self, state: LazyListState, reverse_scrolling: bool, ) -> Self
Creates a horizontally scrollable modifier for lazy lists.
Source§impl Modifier
impl Modifier
Sourcepub fn drop_shadow(
self,
shape: LayerShape,
block: impl Fn(&mut ShadowScope) + 'static,
) -> Self
pub fn drop_shadow( self, shape: LayerShape, block: impl Fn(&mut ShadowScope) + 'static, ) -> Self
Draws a drop shadow behind the current content.
This mirrors Compose 1.9’s dropShadow(shape) { ... }.
Backend note: the pixels renderer currently draws the shadow geometry
without Gaussian blur; wgpu applies the requested blur radius.
Sourcepub fn drop_shadow_value(self, shape: LayerShape, shadow: Shadow) -> Self
pub fn drop_shadow_value(self, shape: LayerShape, shadow: Shadow) -> Self
Static shadow configuration variant mirroring Compose’s dropShadow(shape, shadow).
Sourcepub fn inner_shadow(
self,
shape: LayerShape,
block: impl Fn(&mut ShadowScope) + 'static,
) -> Self
pub fn inner_shadow( self, shape: LayerShape, block: impl Fn(&mut ShadowScope) + 'static, ) -> Self
Draws an inner shadow on top of current content.
This mirrors Compose 1.9’s innerShadow(shape) { ... }.
Backend note: the pixels renderer currently draws the shadow geometry
without Gaussian blur; wgpu applies the requested blur radius.
Sourcepub fn inner_shadow_value(self, shape: LayerShape, shadow: Shadow) -> Self
pub fn inner_shadow_value(self, shape: LayerShape, shadow: Shadow) -> Self
Static shadow configuration variant mirroring Compose’s innerShadow(shape, shadow).
Source§impl Modifier
impl Modifier
Sourcepub fn size(self, size: Size) -> Self
pub fn size(self, size: Size) -> Self
Declare the preferred size of the content to be exactly [size].
The incoming measurement constraints may override this value, forcing the content to be either smaller or larger.
Matches Kotlin: Modifier.size(size: Dp)
Example: Modifier::empty().size(Size { width: 100.0, height: 200.0 })
Sourcepub fn size_points(self, width: f32, height: f32) -> Self
pub fn size_points(self, width: f32, height: f32) -> Self
Declare the preferred size of the content to be exactly [width]dp by [height]dp.
Convenience method for size(Size { width, height }).
Example: Modifier::empty().size_points(100.0, 200.0)
Sourcepub fn width(self, width: f32) -> Self
pub fn width(self, width: f32) -> Self
Declare the preferred width of the content to be exactly [width]dp.
The incoming measurement constraints may override this value, forcing the content to be either smaller or larger.
Matches Kotlin: Modifier.width(width: Dp)
Example: Modifier::empty().width(100.0).height(200.0)
Sourcepub fn height(self, height: f32) -> Self
pub fn height(self, height: f32) -> Self
Declare the preferred height of the content to be exactly [height]dp.
The incoming measurement constraints may override this value, forcing the content to be either smaller or larger.
Matches Kotlin: Modifier.height(height: Dp)
Example: Modifier::empty().width(100.0).height(200.0)
Sourcepub fn width_intrinsic(self, intrinsic: IntrinsicSize) -> Self
pub fn width_intrinsic(self, intrinsic: IntrinsicSize) -> Self
Declare the width of the content based on its intrinsic size.
Matches Kotlin: Modifier.width(IntrinsicSize)
Sourcepub fn height_intrinsic(self, intrinsic: IntrinsicSize) -> Self
pub fn height_intrinsic(self, intrinsic: IntrinsicSize) -> Self
Declare the height of the content based on its intrinsic size.
Matches Kotlin: Modifier.height(IntrinsicSize)
Sourcepub fn required_size(self, size: Size) -> Self
pub fn required_size(self, size: Size) -> Self
Declare the size of the content to be exactly [size], ignoring incoming constraints.
The incoming measurement constraints will not override this value. If the content chooses a size that does not satisfy the incoming constraints, the parent layout will be reported a size coerced in the constraints.
Matches Kotlin: Modifier.requiredSize(size: Dp)
Source§impl Modifier
impl Modifier
pub fn empty() -> Self
Sourcepub fn clip_to_bounds(self) -> Self
pub fn clip_to_bounds(self) -> Self
Clip the content to the bounds of this modifier.
Example: Modifier::empty().clip_to_bounds()
pub fn modifier_local_provider<T, F>(
self,
key: ModifierLocalKey<T>,
value: F,
) -> Selfwhere
T: 'static,
F: Fn() -> T + 'static,
pub fn modifier_local_consumer<F>(self, consumer: F) -> Selfwhere
F: for<'scope> Fn(&mut ModifierLocalReadScope<'scope>) + 'static,
pub fn semantics<F>(self, recorder: F) -> Selfwhere
F: Fn(&mut SemanticsConfiguration) + 'static,
Sourcepub fn focus_target(self) -> Self
pub fn focus_target(self) -> Self
Makes this component focusable.
This adds a focus target node that can receive focus and participate in focus traversal. The component will be included in tab order and can be focused programmatically.
Sourcepub fn on_focus_changed<F>(self, callback: F) -> Selfwhere
F: Fn(FocusState) + 'static,
pub fn on_focus_changed<F>(self, callback: F) -> Selfwhere
F: Fn(FocusState) + 'static,
Makes this component focusable with a callback for focus changes.
The callback is invoked whenever the focus state changes, allowing components to react to gaining or losing focus.
Sourcepub fn focus_requester(self, requester: &FocusRequester) -> Self
pub fn focus_requester(self, requester: &FocusRequester) -> Self
Attaches a focus requester to this component.
The requester can be used to programmatically request focus for this component from application code.
Sourcepub fn debug_chain(self, tag: &'static str) -> Self
pub fn debug_chain(self, tag: &'static str) -> Self
Enables debug logging for this modifier chain.
When enabled, logs the entire modifier chain structure including:
- Element types and their properties
- Inspector metadata
- Capability flags
This is useful for debugging modifier composition issues and understanding how the modifier chain is structured at runtime.
Example:
Modifier::empty()
.padding(8.0)
.background(Color(1.0, 0.0, 0.0, 1.0))
.debug_chain("MyWidget")Sourcepub fn then(&self, next: Modifier) -> Modifier
pub fn then(&self, next: Modifier) -> Modifier
Concatenates this modifier with another.
Eagerly concatenates both element vectors into a single flat Single
variant, avoiding recursive Rc tree overhead on drop and comparison.
pub fn total_padding(&self) -> f32
pub fn explicit_size(&self) -> Option<Size>
pub fn padding_values(&self) -> EdgeInsets
pub fn box_alignment(&self) -> Option<Alignment>
pub fn column_alignment(&self) -> Option<HorizontalAlignment>
pub fn row_alignment(&self) -> Option<VerticalAlignment>
pub fn draw_commands(&self) -> Vec<DrawCommand>
pub fn clips_to_bounds(&self) -> bool
Sourcepub fn collect_inspector_records(&self) -> Vec<ModifierInspectorRecord>
pub fn collect_inspector_records(&self) -> Vec<ModifierInspectorRecord>
Returns structured inspector records for each modifier element.
pub fn resolved_modifiers(&self) -> ResolvedModifiers
Sourcepub fn structural_eq(&self, other: &Self) -> bool
pub fn structural_eq(&self, other: &Self) -> bool
Checks whether two modifiers are structurally equivalent for layout decisions.
This ignores identity-sensitive modifier elements (e.g., draw closures) so draw-only updates do not force measure/layout invalidation.