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
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 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 content with overlay.
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: GraphicsLayer) -> Self
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
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).
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 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.
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)
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.
Trait Implementations§
impl Eq for Modifier
Auto Trait Implementations§
impl Freeze for Modifier
impl !RefUnwindSafe for Modifier
impl !Send for Modifier
impl !Sync for Modifier
impl Unpin for Modifier
impl !UnwindSafe for Modifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.