Skip to main content

Modifier

Struct Modifier 

Source
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

Source

pub fn press_interaction_source( self, interaction_source: MutableInteractionSource, ) -> Self

Source§

impl Modifier

Source

pub fn align(self, alignment: Alignment) -> Self

Source

pub fn alignInBox(self, alignment: Alignment) -> Self

Source

pub fn alignInColumn(self, alignment: HorizontalAlignment) -> Self

Source

pub fn alignInRow(self, alignment: VerticalAlignment) -> Self

Source§

impl Modifier

Source

pub fn background(self, color: Color) -> Self

Set the background color.

Example: Modifier::empty().background(Color::rgb(1.0, 0.0, 0.0))

Source

pub fn rounded_corners(self, radius: f32) -> Self

Add rounded corners with uniform radius.

Example: Modifier::empty().rounded_corners(8.0)

Source

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

Source

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.

Source

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
Source

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

Source

pub fn clickable(self, handler: impl Fn(Point) + 'static) -> Self

Make the component clickable.

Example: Modifier::empty().clickable(|pt| println!("Clicked at {:?}", pt))

Source§

impl Modifier

Source

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| { ... })

Source

pub fn draw_behind(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self

Draw content behind.

Example: Modifier::empty().draw_behind(|scope| { ... })

Source

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

Source

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()

Source

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)

Source

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()

Source

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)

Source

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()

Source

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

Source

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() })

Source

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.

Source

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.

Source

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; })

Source

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.

Source

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.

Source

pub fn backdrop_effect(self, effect: RenderEffect) -> Self

Apply a backdrop effect to content behind this composable’s bounds.

Source

pub fn backdrop_blur(self, radius: Dp) -> Self

Blur content behind this composable, clipped to the composable bounds.

radius is expressed in Dp and converted to px using the current render density when modifier slices are evaluated.

Source

pub fn glass_material(self, material: GlassMaterial) -> Self

Apply a frosted glass material: backdrop blur, clipped shape, and tint.

Source

pub fn shader_background(self, shader: RuntimeShader) -> Self

Convenience alias for applying a backdrop shader effect.

Source

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.

Source

pub fn tint(self, tint: Color) -> Self

Convenience color filter that tints layer output.

Source

pub fn compositing_strategy(self, strategy: CompositingStrategy) -> Self

Configures how the layer is composited into its parent.

Source

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.

Source

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.

Source

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.

Source

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

Source

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)

Source

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

Source

pub fn padding(self, p: f32) -> Self

Add uniform padding to all sides.

Example: Modifier::empty().padding(16.0)

Source

pub fn padding_horizontal(self, horizontal: f32) -> Self

Add horizontal padding (left and right).

Example: Modifier::empty().padding_horizontal(16.0)

Source

pub fn padding_vertical(self, vertical: f32) -> Self

Add vertical padding (top and bottom).

Example: Modifier::empty().padding_vertical(8.0)

Source

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

pub fn padding_each(self, left: f32, top: f32, right: f32, bottom: f32) -> Self

Add padding to each side individually.

Example: Modifier::empty().padding_each(8.0, 4.0, 8.0, 4.0)

Source§

impl Modifier

Source

pub fn pointer_input<K, F, Fut>(self, key: K, handler: F) -> Self
where K: Hash + 'static, F: Fn(PointerInputScope) -> Fut + 'static, Fut: Future<Output = ()> + 'static,

Source§

impl Modifier

Source

pub fn horizontal_scroll( self, state: ScrollState, reverse_scrolling: bool, ) -> Self

Creates a horizontally scrollable modifier.

§Arguments
  • state - The ScrollState to control scroll position
  • reverse_scrolling - If true, reverses the scroll direction in layout. Note: This affects how scroll offset is applied to content (via ScrollNode), 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
);
Source

pub fn vertical_scroll( self, state: ScrollState, reverse_scrolling: bool, ) -> Self

Creates a vertically scrollable modifier.

§Arguments
  • state - The ScrollState to control scroll position
  • reverse_scrolling - If true, reverses the scroll direction in layout. Note: This affects how scroll offset is applied to content (via ScrollNode), NOT the drag direction. Drag gestures always follow natural touch semantics: drag down = scroll up (content moves down under finger).
Source

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.

Source

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

Source

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.

Source

pub fn lazy_horizontal_scroll( self, state: LazyListState, reverse_scrolling: bool, ) -> Self

Creates a horizontally scrollable modifier for lazy lists.

Source§

impl Modifier

Source

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.

Source

pub fn drop_shadow_value(self, shape: LayerShape, shadow: Shadow) -> Self

Static shadow configuration variant mirroring Compose’s dropShadow(shape, shadow).

Source

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.

Source

pub fn inner_shadow_value(self, shape: LayerShape, shadow: Shadow) -> Self

Static shadow configuration variant mirroring Compose’s innerShadow(shape, shadow).

Source§

impl Modifier

Source

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 })

Source

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)

Source

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)

Source

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)

Source

pub fn width_intrinsic(self, intrinsic: IntrinsicSize) -> Self

Declare the width of the content based on its intrinsic size.

Matches Kotlin: Modifier.width(IntrinsicSize)

Source

pub fn height_intrinsic(self, intrinsic: IntrinsicSize) -> Self

Declare the height of the content based on its intrinsic size.

Matches Kotlin: Modifier.height(IntrinsicSize)

Source

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

Source

pub fn weight(self, weight: f32) -> Self

Source

pub fn weight_with_fill(self, weight: f32, fill: bool) -> Self

Source

pub fn columnWeight(self, weight: f32, fill: bool) -> Self

Source

pub fn rowWeight(self, weight: f32, fill: bool) -> Self

Source§

impl Modifier

Source

pub fn empty() -> Self

Source

pub fn clip_to_bounds(self) -> Self

Clip the content to the bounds of this modifier.

Example: Modifier::empty().clip_to_bounds()

Source

pub fn modifier_local_provider<T, F>( self, key: ModifierLocalKey<T>, value: F, ) -> Self
where T: 'static, F: Fn() -> T + 'static,

Source

pub fn modifier_local_consumer<F>(self, consumer: F) -> Self
where F: for<'scope> Fn(&mut ModifierLocalReadScope<'scope>) + 'static,

Source

pub fn semantics<F>(self, recorder: F) -> Self
where F: Fn(&mut SemanticsConfiguration) + 'static,

Source

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.

Source

pub fn on_focus_changed<F>(self, callback: F) -> Self
where 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.

Source

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.

Source

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")
Source

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.

Source

pub fn total_padding(&self) -> f32

Source

pub fn explicit_size(&self) -> Option<Size>

Source

pub fn padding_values(&self) -> EdgeInsets

Source

pub fn box_alignment(&self) -> Option<Alignment>

Source

pub fn column_alignment(&self) -> Option<HorizontalAlignment>

Source

pub fn row_alignment(&self) -> Option<VerticalAlignment>

Source

pub fn draw_commands(&self) -> Vec<DrawCommand>

Source

pub fn clips_to_bounds(&self) -> bool

Source

pub fn collect_inspector_records(&self) -> Vec<ModifierInspectorRecord>

Returns structured inspector records for each modifier element.

Source

pub fn resolved_modifiers(&self) -> ResolvedModifiers

Source

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.

Trait Implementations§

Source§

impl Clone for Modifier

Source§

fn clone(&self) -> Modifier

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Modifier

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Modifier

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Modifier

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Modifier

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Modifier

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.