Skip to main content

Pressable

Struct Pressable 

Source
pub struct Pressable {
Show 20 fields pub id: Option<WidgetId>, pub child: Widget, pub on_press: Option<ActionEnvelope>, pub label: Option<String>, pub semantics_identifier: Option<String>, pub hyperlink: Option<Hyperlink>, pub popover_target: Option<PopoverTarget>, pub role: PressableRole, pub focus_policy: FocusPolicy, pub disabled: bool, pub layout: BoxStyle, pub flex_grow: f32, pub flex_shrink: f32, pub style: PressableStyle, pub hover_style: Option<PressableStyle>, pub pressed_style: Option<PressableStyle>, pub focused_style: Option<PressableStyle>, pub disabled_style: Option<PressableStyle>, pub transition: Option<MotionTransition>, pub ripple: Option<RippleFx>,
}
Expand description

A visually neutral accessible interaction surface.

Pressable contributes no visual chrome or geometry unless explicitly supplied through PressableStyle or BoxStyle. It still provides semantic activation, focus handling, keyboard activation, pointer state, optional transitions, and optional ripple feedback.

§Example

Pressable::new(Text::new("Open report"))
    .id(WidgetId::explicit("report.open"))
    .semantics_identifier("report.open")
    .label("Open report")
    .role(PressableRole::Button)
    .on_press(open_report)
    .layout(BoxStyle::default().padding_symmetric(
        Length::points(tokens.spacing.m),
        Length::points(tokens.spacing.s),
    ))
    .into()

Fields§

§id: Option<WidgetId>

Optional stable identity used for interaction state, focus, and motion.

§child: Widget

Child content rendered inside the interaction surface.

§on_press: Option<ActionEnvelope>

Action dispatched when the pressable is activated.

§label: Option<String>

Accessible label exposed to assistive technologies.

§semantics_identifier: Option<String>

Stable semantic identifier used by tests and accessibility tooling.

§hyperlink: Option<Hyperlink>

Optional genuine navigation destination.

§popover_target: Option<PopoverTarget>

Optional standards-based HTML popover invocation.

§role: PressableRole

Accessibility role exposed by the semantic node.

§focus_policy: FocusPolicy

How pointer activation should affect keyboard focus.

§disabled: bool

Whether the pressable can receive focus or activation.

§layout: BoxStyle

Typed layout box model for size, margin, padding, and placement.

§flex_grow: f32

Legacy point-based flex grow factor.

§flex_shrink: f32

Legacy point-based flex shrink factor.

§style: PressableStyle

Base visual state.

§hover_style: Option<PressableStyle>

Style overlay while hovered.

§pressed_style: Option<PressableStyle>

Style overlay while actively pressed.

§focused_style: Option<PressableStyle>

Style overlay while focused.

§disabled_style: Option<PressableStyle>

Style overlay while disabled.

§transition: Option<MotionTransition>

Optional transition for state-style changes.

§ripple: Option<RippleFx>

Optional ripple feedback.

Implementations§

Source§

impl Pressable

Source

pub fn new(child: impl Into<Widget>) -> Self

Creates a neutral pressable around child.

Source

pub fn id(self, id: WidgetId) -> Self

Uses an explicit stable identity for interaction, focus, and motion.

Source

pub fn on_press(self, action: ActionEnvelope) -> Self

Dispatches action for pointer, keyboard, or accessibility activation.

Source

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

Enables or disables activation and focus participation.

Source

pub fn layout(self, style: BoxStyle) -> Self

Applies the shared typed box model without introducing visual defaults.

Source

pub fn focus_policy(self, policy: FocusPolicy) -> Self

Selects how pointer activation affects keyboard focus.

Source

pub fn style(self, style: PressableStyle) -> Self

Sets the base visual style.

Source

pub fn hover(self, style: PressableStyle) -> Self

Sets the style overlay while the pointer is over the pressable.

Source

pub fn pressed(self, style: PressableStyle) -> Self

Sets the style overlay while the pressable is active.

Source

pub fn focused(self, style: PressableStyle) -> Self

Sets the style overlay while the pressable owns keyboard focus.

Source

pub fn disabled_style(self, style: PressableStyle) -> Self

Sets the style overlay while activation is disabled.

Source

pub fn transition(self, transition: MotionTransition) -> Self

Animates supported properties between interaction states.

Source

pub fn ripple(self, ripple: RippleFx) -> Self

Enables optional ripple feedback.

Source

pub fn semantics_identifier(self, identifier: impl Into<String>) -> Self

Sets a stable semantic identifier for tests and accessibility tools.

Source

pub fn label(self, label: impl Into<String>) -> Self

Sets the accessible label.

Source

pub fn role(self, role: PressableRole) -> Self

Sets button, link, or menu-item semantics.

Source

pub fn href(self, href: impl Into<String>) -> Self

Makes this pressable a genuine hyperlink.

Source

pub fn popover_target( self, id: impl Into<String>, action: PopoverAction, ) -> Self

Trait Implementations§

Source§

impl Clone for Pressable

Source§

fn clone(&self) -> Pressable

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 Pressable

Source§

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

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

impl Default for Pressable

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Pressable

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Pressable> for Widget

Source§

fn from(pressable: Pressable) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Pressable

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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, <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.
Source§

impl<T> WidgetIdExt for T
where T: Into<Widget>,

Source§

fn id<I>(self, id: I) -> Widget
where I: Into<WidgetId>,