pub struct Pressable<Msg: Clone> {
pub child: Box<Element<Msg>>,
pub on_press: Option<Msg>,
pub on_long_press: Option<Msg>,
pub on_drag_start: Option<Msg>,
pub on_escape: Option<Msg>,
pub swallow: bool,
pub id: Option<WidgetId>,
pub cursor: Option<CursorShape>,
}Expand description
Wraps any Element and emits a message on tap. Use when you want
click-to-emit on something richer than a Button
— for example a Container styled as a
card holding a row of icon + labels.
The wrapper is invisible to drawing: it delegates preferred_size and
rendering to the child. It does record a hit rect covering its full
allocated rect so taps anywhere inside fire on_press. Inner widgets
that are themselves interactive (e.g. a button nested inside the
pressable) keep priority — the layout pass pushes the wrapper’s hit
rect before recursing into the child, and hit testing iterates in
reverse, so deeper widgets win.
No visual press feedback is applied — for state-driven appearance
changes use a Button or compose with a
container that reacts to focus/press signals.
pressable(
container( row()
.push( icon )
.push( column().push( title ).push( subtitle ) ) )
.surface( "surface-card" )
.radius( 32.0 )
.padding_h( 16.5 )
.padding_v( 24.0 ),
)
.on_press( Msg::OpenWifiPicker )Fields§
§child: Box<Element<Msg>>§on_press: Option<Msg>§on_long_press: Option<Msg>§on_drag_start: Option<Msg>Drag-arm message. Fired alongside on_long_press when the touch
hold timer elapses, AND fired by mouse left-button motion past
the drag-promotion threshold without waiting for the timer. The
caller uses this to arm any per-app drag state (in crustace,
dragging_item); a widget that opens a context menu but isn’t
draggable leaves this None.
on_escape: Option<Msg>Keyboard Escape-key message. The runtime scans every laid-out
pressable’s snapshot and fires the topmost (highest flat_idx)
on_escape it finds before the default ESC fallthrough chain.
Used by crate::widget::dialog::Dialog to make Esc cancel a
modal dialog without each app having to wire a global keyboard
hook — but available to any composite that needs the same
semantics.
swallow: boolMake the pressable hit-testable even when no callback is set.
A swallow=true pressable consumes pointer events at its hit
rect and emits no message — used by
crate::widget::dialog::Dialog for the modal scrim plus the
card-area swallow that prevents dismiss_on_scrim from firing
when the user clicks on the dialog body itself. Has no effect
when any handler is also set; in that case the handler determines
the message and swallow is implicit.
id: Option<WidgetId>§cursor: Option<CursorShape>Implementations§
Source§impl<Msg: Clone> Pressable<Msg>
impl<Msg: Clone> Pressable<Msg>
pub fn new(child: impl Into<Element<Msg>>) -> Self
Sourcepub fn cursor(self, shape: CursorShape) -> Self
pub fn cursor(self, shape: CursorShape) -> Self
Override the pointer cursor shape shown on hover.
pub fn on_press(self, msg: Msg) -> Self
pub fn on_long_press(self, msg: Msg) -> Self
Sourcepub fn on_drag_start(self, msg: Msg) -> Self
pub fn on_drag_start(self, msg: Msg) -> Self
Attach a drag-arm message. Fires when the press transitions into
drag mode — touch on hold-timer expiry, mouse on motion past the
drag-promotion threshold. Independent of on_long_press so a
widget can open a menu without becoming draggable, or be
draggable without opening a menu.
Sourcepub fn on_escape(self, msg: Msg) -> Self
pub fn on_escape(self, msg: Msg) -> Self
Bind a keyboard-Escape message to this pressable. See
Pressable::on_escape for the dispatch order semantics.
Sourcepub fn swallow(self, on: bool) -> Self
pub fn swallow(self, on: bool) -> Self
Make the pressable hit-testable even when no on_press /
on_long_press / on_drag_start is configured. See
Pressable::swallow.
pub fn id(self, id: WidgetId) -> Self
pub fn preferred_size(&self, max_width: f32, canvas: &Canvas) -> (f32, f32)
Sourcepub fn has_handler(&self) -> bool
pub fn has_handler(&self) -> bool
True when the wrapper participates in hit-testing — has at least
one pointer / keyboard handler set, or has been opted in to
silent swallow via Pressable::swallow. Used by the layout
pass to skip pushing a hit rect for a no-op pressable.
Trait Implementations§
Auto Trait Implementations§
impl<Msg> Freeze for Pressable<Msg>where
Msg: Freeze,
impl<Msg> !RefUnwindSafe for Pressable<Msg>
impl<Msg> !Send for Pressable<Msg>
impl<Msg> !Sync for Pressable<Msg>
impl<Msg> Unpin for Pressable<Msg>where
Msg: Unpin,
impl<Msg> !UnwindSafe for Pressable<Msg>
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more