pub struct Modifier { /* private fields */ }Expand description
What sits around a widget: its size, its surface, its outline, how far its content
is inset, and what the Renderer reports about it. Compose’s Modifier.
Written the way Compose writes it, from the empty value Modifier:
Card().modifier(Modifier.fill_max_width().padding(16.0).background(Paint::Role(ColorRole::Surface)))The order of the calls does not matter. Each kind of Modifier has a fixed slot in the
node’s chain, outside in: size, shape, fill, outline, lift, press, inset. That is what
the rsx! attributes do too, so the same Modifier draws the same either way.
Implementations§
Source§impl Modifier
impl Modifier
pub const fn width(self, dp: f32) -> Self
pub const fn height(self, dp: f32) -> Self
Sourcepub const fn width_if(self, dp: Option<f32>) -> Self
pub const fn width_if(self, dp: Option<f32>) -> Self
A width that may be unset, for a screen whose measure depends on the window.
Sourcepub const fn match_parent_size(self) -> Self
pub const fn match_parent_size(self) -> Self
Matches the bounds of a Box parent without affecting its size.
pub const fn fill_max_width(self) -> Self
pub const fn fill_max_height(self) -> Self
pub const fn fill_max_size(self) -> Self
Sourcepub const fn fill_max_width_if(self, fill: bool) -> Self
pub const fn fill_max_width_if(self, fill: bool) -> Self
Fills the width only when fill is true.
Sourcepub const fn padding_role(self, role: SpaceRole) -> Self
pub const fn padding_role(self, role: SpaceRole) -> Self
An inset from the design system’s spacing ladder. Wins over padding.
Sourcepub const fn padding_role_if(self, role: Option<SpaceRole>) -> Self
pub const fn padding_role_if(self, role: Option<SpaceRole>) -> Self
The same, when the inset may be unset.
pub const fn background(self, paint: Paint) -> Self
Sourcepub const fn background_if(self, paint: Option<Paint>) -> Self
pub const fn background_if(self, paint: Option<Paint>) -> Self
The same, when there may be no background.
Sourcepub const fn shape_role(self, role: ShapeRole) -> Self
pub const fn shape_role(self, role: ShapeRole) -> Self
A shape from the design system’s ladder.
Sourcepub const fn corner_radius(self, dp: f32) -> Self
pub const fn corner_radius(self, dp: f32) -> Self
A literal corner, in dp. Wins over shape_role.
Sourcepub const fn corner_radii(self, radii: [f32; 4]) -> Self
pub const fn corner_radii(self, radii: [f32; 4]) -> Self
Individual corner radii [top_start, top_end, bottom_end, bottom_start], in dp.
Wins over shape_role and corner_radius.
Sourcepub const fn clip(self, clip: bool) -> Self
pub const fn clip(self, clip: bool) -> Self
Clips the node and its children to its shape, or to its rectangle when it has none.
Sourcepub const fn window_drag(self, enabled: bool) -> Self
pub const fn window_drag(self, enabled: bool) -> Self
Includes or excludes this node from window dragging.
pub const fn border(self, width: f32, paint: Paint) -> Self
Sourcepub const fn elevation(self, dp: f32) -> Self
pub const fn elevation(self, dp: f32) -> Self
A resting height above the default, in dp. How it is drawn is the design system’s.
Sourcepub const fn observe_size(self, token: i64) -> Self
pub const fn observe_size(self, token: i64) -> Self
Asks the Renderer to report this node’s size under the token from
crate::runtime::remember_node_size.
A report goes out on the first measurement and then whenever the width or height
class changes. A resize inside one class says nothing; use
Modifier::observe_size_every_dp for that.
Sourcepub const fn observe_size_every_dp(self, token: i64) -> Self
pub const fn observe_size_every_dp(self, token: i64) -> Self
Like Modifier::observe_size, and also reports whenever the width or height,
rounded to the nearest whole dp, changes inside one class. Several changes in one
frame are one report carrying the last size.
Sourcepub const fn motion(self, role: MotionRole) -> Self
pub const fn motion(self, role: MotionRole) -> Self
How important this node’s changes are. The curve is the design system’s.
Sourcepub const fn material(self, role: MaterialRole) -> Self
pub const fn material(self, role: MaterialRole) -> Self
What this node’s surface is made of. The effect is the design system’s.
Sourcepub const fn offset(self, x: f32, y: f32) -> Self
pub const fn offset(self, x: f32, y: f32) -> Self
Moves the node from where it was laid out, in dp, without moving anything else.
Sourcepub const fn shadow(self, shadow: Shadow) -> Self
pub const fn shadow(self, shadow: Shadow) -> Self
Adds a shadow layer. Layers are drawn in the order they are added, the first at
the bottom. A node takes at most MAX_SHADOWS; a layer past that is ignored.
Sourcepub fn shadows(self, shadows: impl IntoIterator<Item = Shadow>) -> Self
pub fn shadows(self, shadows: impl IntoIterator<Item = Shadow>) -> Self
Adds several shadow layers, in order.
Sourcepub const fn alpha(self, alpha: f32) -> Self
pub const fn alpha(self, alpha: f32) -> Self
An opacity for the node and everything in it, faded as one group.
Sourcepub fn corner_curve(self, smoothing: f32) -> Self
pub fn corner_curve(self, smoothing: f32) -> Self
How the node’s rounded corners curve, from 0 (a circular arc, the default) to 1.
Above 0 the curve eases in from each side with continuously changing curvature, as
Figma’s corner smoothing does; 0.6 is the look of iOS. The radius stays whatever
corner_radius, corner_radii or shape_role made it, and the background, border,
shadow and clip all follow the same curve. A value outside 0..=1 is taken as the
nearer end, and NaN as 0.
Sourcepub const fn press_feedback(self, scale: f32, tint_alpha: f32) -> Self
pub const fn press_feedback(self, scale: f32, tint_alpha: f32) -> Self
Sets the pressed scale and tint opacity.
Sourcepub fn label(self, label: &str) -> Self
pub fn label(self, label: &str) -> Self
The name assistive technology reads for this node. On a widget with a visible label it replaces that label; an empty name is the same as none.
Names are kept for the life of the program, and at most 4096 distinct names are kept. A name past that limit is left off (debug builds print a warning once), so use a fixed set of names rather than one built from changing data.
Sourcepub const fn role(self, role: Role) -> Self
pub const fn role(self, role: Role) -> Self
What this node is to assistive technology, for a node that is not a widget with
a role of its own: a Box that is pressed is a button.
Sourcepub const fn checked(self, checked: bool) -> Self
pub const fn checked(self, checked: bool) -> Self
Whether the node is checked, as a toggle announces it.
Sourcepub const fn selected(self, selected: bool) -> Self
pub const fn selected(self, selected: bool) -> Self
Whether the node is the selected one of its group.
Sourcepub const fn expanded(self, expanded: bool) -> Self
pub const fn expanded(self, expanded: bool) -> Self
Whether the node is expanded, as a disclosure or a tree item announces it.
Sourcepub const fn disabled(self, disabled: bool) -> Self
pub const fn disabled(self, disabled: bool) -> Self
Whether the node is disabled for assistive technology.
Sourcepub const fn focused(self, focused: bool) -> Self
pub const fn focused(self, focused: bool) -> Self
Whether the node holds the focus, as assistive technology reads it.
Leaves the node out of the accessibility tree when true.
Sourcepub const fn click_action(self, exposed: bool) -> Self
pub const fn click_action(self, exposed: bool) -> Self
Exposes a click action on the node, which runs the node’s click handler.
Sourcepub const fn focus_action(self, exposed: bool) -> Self
pub const fn focus_action(self, exposed: bool) -> Self
Exposes a focus action on the node.
Sourcepub fn semantics(self, role: Role, label: &str, state: SemanticsState) -> Self
pub fn semantics(self, role: Role, label: &str, state: SemanticsState) -> Self
The role, the name and the state in one call.
Sourcepub fn graphics_layer(self, layer: GraphicsLayer) -> Self
pub fn graphics_layer(self, layer: GraphicsLayer) -> Self
Compose’s graphicsLayer: a rotation, a scale and a translation about an origin,
drawn without moving the layout, and an opacity for the whole group. A pointer is
tested against the shape that is drawn.
Sourcepub const fn animated_alpha(self, value: Animated<f32>) -> Self
pub const fn animated_alpha(self, value: Animated<f32>) -> Self
An opacity the Renderer animates to, from crate::animate_float_as_state. It
takes the place of alpha.
Sourcepub const fn animated_background(self, value: Animated<Paint>) -> Self
pub const fn animated_background(self, value: Animated<Paint>) -> Self
A background the Renderer animates to, from crate::animate_color_as_state. It
takes the place of background.
Sourcepub const fn animated_offset(self, value: Animated<(f32, f32)>) -> Self
pub const fn animated_offset(self, value: Animated<(f32, f32)>) -> Self
A translation the Renderer animates to, from crate::animate_offset_as_state.
It takes the place of the transform a graphics_layer would draw.
Sourcepub const fn cursor(self, cursor: Cursor) -> Self
pub const fn cursor(self, cursor: Cursor) -> Self
The cursor the platform shows over the node. CSS cursor: the deepest node under
the pointer that names one other than Cursor::Auto wins, and while a node holds a
pointer capture its cursor stays.
Sourcepub const fn user_select(self, user_select: UserSelect) -> Self
pub const fn user_select(self, user_select: UserSelect) -> Self
Whether the text under the node can be selected. CSS user-select; Auto follows
the parent.