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 form a persistent tree structure (via CombinedModifier pattern) to enable O(1) composition and structural sharing during recomposition.

Implementations§

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 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 content with overlay.

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: GraphicsLayer) -> Self

Apply a graphics layer with transformations and alpha.

Example: Modifier::empty().graphics_layer(GraphicsLayer { alpha: 0.5, ..Default::default() })

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§

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 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.

This creates a persistent tree structure (CombinedModifier pattern) rather than eagerly flattening into a vector, enabling O(1) composition and structural sharing.

Mirrors Jetpack Compose: infix fun then(other: Modifier): Modifier = if (other === Modifier) this else CombinedModifier(this, other)

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 · 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 · 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.