Skip to main content

Modifier

Struct Modifier 

Source
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

Source

pub const fn new() -> Self

The empty Modifier. The same as the value Modifier.

Source

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

A share of the space left in a Row or Column.

Source

pub const fn width(self, dp: f32) -> Self

Source

pub const fn height(self, dp: f32) -> Self

Source

pub const fn size(self, width: f32, height: f32) -> Self

Both at once.

Source

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.

Source

pub const fn match_parent_size(self) -> Self

Matches the bounds of a Box parent without affecting its size.

Source

pub const fn fill_max_width(self) -> Self

Source

pub const fn fill_max_height(self) -> Self

Source

pub const fn fill_max_size(self) -> Self

Source

pub const fn fill_max_width_if(self, fill: bool) -> Self

Fills the width only when fill is true.

Source

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

The same inset on every side, in dp.

Source

pub const fn padding_role(self, role: SpaceRole) -> Self

An inset from the design system’s spacing ladder. Wins over padding.

Source

pub const fn padding_role_if(self, role: Option<SpaceRole>) -> Self

The same, when the inset may be unset.

Source

pub const fn background(self, paint: Paint) -> Self

Source

pub const fn background_if(self, paint: Option<Paint>) -> Self

The same, when there may be no background.

Source

pub const fn shape_role(self, role: ShapeRole) -> Self

A shape from the design system’s ladder.

Source

pub const fn corner_radius(self, dp: f32) -> Self

A literal corner, in dp. Wins over shape_role.

Source

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.

Source

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.

Source

pub const fn window_drag(self, enabled: bool) -> Self

Includes or excludes this node from window dragging.

Source

pub const fn border(self, width: f32, paint: Paint) -> Self

The same border on every side. It takes the place of border_each and border_side.

Source

pub const fn border_each( self, top: (f32, Paint), right: (f32, Paint), bottom: (f32, Paint), left: (f32, Paint), ) -> Self

A border whose sides each have their own width and paint, in CSS order: top, right, bottom, left. A side of width 0 draws nothing. It takes the place of border.

The sides are the screen’s, not the reading direction’s: right is the right side in a right-to-left window too.

Source

pub const fn border_side(self, side: Side, width: f32, paint: Paint) -> Self

A border on one side only, such as the guide line beside an indented row. The other sides have width 0, unless an earlier border_side or border_each in the same chain gave them one, so border_side(Side::Top, ..).border_side(Side::Start, ..) draws two sides. It takes the place of border.

Side::Start is the left side and Side::End the right one. The Host lays every screen out left to right and the Renderer draws a border on the screen’s sides, so a right-to-left window does not move a start border to the right.

Source

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.

Source

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.

Source

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.

Source

pub const fn motion(self, role: MotionRole) -> Self

How important this node’s changes are. The curve is the design system’s.

Source

pub const fn material(self, role: MaterialRole) -> Self

What this node’s surface is made of. The effect is the design system’s.

Source

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.

Source

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.

Source

pub fn shadows(self, shadows: impl IntoIterator<Item = Shadow>) -> Self

Adds several shadow layers, in order.

Source

pub const fn background_brush(self, layer: BackgroundBrush) -> Self

Adds a background brush layer. Layers are drawn in the order they are added, the first at the bottom, all of them over the background colour. A node takes at most MAX_BACKGROUND_BRUSHES; a layer past that is ignored.

Source

pub fn background_brushes( self, layers: impl IntoIterator<Item = BackgroundBrush>, ) -> Self

Adds several background brush layers, in order. CSS writes its list top first, so a list taken from CSS is added last to first.

Source

pub const fn alpha(self, alpha: f32) -> Self

An opacity for the node and everything in it, faded as one group.

Source

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.

Source

pub const fn press_feedback(self, scale: f32, tint_alpha: f32) -> Self

Sets the pressed scale and tint opacity.

Source

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.

Source

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.

Source

pub const fn checked(self, checked: bool) -> Self

Whether the node is checked, as a toggle announces it.

Source

pub const fn selected(self, selected: bool) -> Self

Whether the node is the selected one of its group.

Source

pub const fn expanded(self, expanded: bool) -> Self

Whether the node is expanded, as a disclosure or a tree item announces it.

Source

pub const fn disabled(self, disabled: bool) -> Self

Whether the node is disabled for assistive technology.

Source

pub const fn focused(self, focused: bool) -> Self

Whether the node holds the focus, as assistive technology reads it.

Source

pub const fn hidden(self, hidden: bool) -> Self

Leaves the node out of the accessibility tree when true.

Source

pub const fn click_action(self, exposed: bool) -> Self

Exposes a click action on the node, which runs the node’s click handler.

Source

pub const fn focus_action(self, exposed: bool) -> Self

Exposes a focus action on the node.

Source

pub fn semantics(self, role: Role, label: &str, state: SemanticsState) -> Self

The role, the name and the state in one call.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Modifier

Source§

fn clone(&self) -> Self

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 Copy for Modifier

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 PartialEq for Modifier

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.