Skip to main content

Sense

Struct Sense 

Source
pub struct Sense(/* private fields */);
Expand description

Which of a Response’s fields Interaction::interact should actually populate for a given widget call.

A manual bitflag over u8: mirrors KeyModifiers’s shape rather than pulling in the bitflags crate for a handful of bits. Combine raw flags with | (Sense::HOVER | Sense::FOCUSABLE), or reach for one of the named constructors (click, drag, hover, scroll) for the common cases. DISABLED is the exception: it’s a modifier over an existing sense, not a capability of its own.

Implementations§

Source§

impl Sense

Source

pub const HOVER: Self

Register the widget’s rect for hit-testing and report Response::hovered.

Source

pub const CLICK: Self

Source

pub const DRAG: Self

Report Response::dragging once the pointer moves past the drag threshold while pressed on this widget.

Source

pub const FOCUSABLE: Self

Register the widget in the FocusRing’s Tab/Shift+Tab order and report Response::focused. Combined with CLICK, Enter/Space also activate the widget while it’s focused: terminals are frequently mouse-less.

Source

pub const SCROLL: Self

Report Response::scroll_delta whenever the pointer is within this widget’s rect. Unlike the other pointer senses, this is not limited to the single topmost widget under the pointer: see Interaction::interact’s doc comment on scroll_delta for why.

Source

pub const SECONDARY_CLICK: Self

Report Response::secondary_clicked: the secondary (right) button pressed and released on this widget while still hovered. Independent of CLICK: combine them (Sense::click() | Sense::SECONDARY_CLICK) for a widget that wants both a primary action and a secondary one (e.g. a context menu). Unlike CLICK/DRAG, there’s no drag-threshold suppression for the secondary button: a press-and-release on the same widget always counts, since secondary-button drags aren’t a gesture this module resolves.

Source

pub const DISABLED: Self

Keeps this call’s hit-testing (so Response::hovered still works, most of the value of showing a disabled control at all) but suppresses everything else this sense would otherwise register or report: no FocusRing registration, and Response::pressed, released, clicked, held, dragging, focused, and secondary_clicked all report false, even if the gesture would otherwise satisfy them. SCROLL is suppressed too: a disabled row’s own Sense::SCROLL never fires, though this doesn’t stop an enclosing scrollable list (a separate widget) from scrolling past it.

A modifier, not a capability of its own: combine it with an existing sense rather than using it alone, e.g. Sense::click() | Sense::DISABLED. See disabled_if for the common call-site shape.

Source

pub const NONE: Self

Senses nothing: interact still registers the id nowhere and every Response field reports as if nothing happened, matching Response::default, with one exception: rect always echoes back the area passed to interact, useful for purely decorative widgets that still want layout echo.

Source

pub const fn click() -> Self

A clickable, hoverable, focusable widget: buttons, tabs, list rows. Equivalent to HOVER | CLICK | FOCUSABLE.

Source

pub const fn drag() -> Self

A draggable widget, e.g. a slider or scrollbar thumb. Equivalent to click | DRAG.

Source

pub const fn hover() -> Self

A hover-only widget with no click or focus behavior, e.g. a tooltip trigger. Equivalent to HOVER.

Source

pub const fn scroll() -> Self

A scrollable region, e.g. a list or log panel. Equivalent to HOVER | SCROLL.

Source

pub const fn secondary_click() -> Self

A widget with a secondary (right-click) action but no primary click, e.g. a context-menu-only trigger. Equivalent to HOVER | SECONDARY_CLICK. Combine with click (Sense::click() | Sense::SECONDARY_CLICK) for a widget with both a primary and a secondary action.

Source

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

self with DISABLED set if disabled is true, unchanged otherwise: the common call-site shape, Sense::click().disabled_if(!save_available), replacing what would otherwise be a branch between two Sense literals.

Source

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

true if every bit set in other is also set in self.

Source

pub const fn is_disabled(self) -> bool

true if DISABLED is set.

Source

pub const fn wants_pointer(self) -> bool

true if this sense wants pointer hit-testing at all (HOVER, CLICK, DRAG, SCROLL, or SECONDARY_CLICK).

Trait Implementations§

Source§

impl BitOr for Sense

Source§

type Output = Sense

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
Source§

impl BitOrAssign for Sense

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl Clone for Sense

Source§

fn clone(&self) -> Sense

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 Sense

Source§

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

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

impl Default for Sense

Source§

fn default() -> Sense

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

impl Hash for Sense

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Sense

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Sense

Source§

impl Eq for Sense

Source§

impl StructuralPartialEq for Sense

Auto Trait Implementations§

§

impl Freeze for Sense

§

impl RefUnwindSafe for Sense

§

impl Send for Sense

§

impl Sync for Sense

§

impl Unpin for Sense

§

impl UnsafeUnpin for Sense

§

impl UnwindSafe for Sense

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 = Infallible

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.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).