Skip to main content

Response

Struct Response 

Source
pub struct Response<Id> { /* private fields */ }
Expand description

What happened to a widget this frame, as reported by Interaction::interact.

Every field is scoped to this frame only (e.g. clicked is true for exactly the one frame the release lands on), except focused, which stays true across frames until focus moves elsewhere. Fields a widget didn’t ask for via Sense are always false/0: a widget sensed with only Sense::HOVER never reports clicked, for instance.

Implementations§

Source§

impl<Id: Copy> Response<Id>

Source

pub const fn id(&self) -> Id

The id passed to Interaction::interact this frame, echoed back so a call site that only has the resolved Response in hand (e.g. one returned from a widget it drew in a loop) can still tell which id it belongs to. For a Response::default built directly rather than through interact, this is just Id::default(), not a real widget’s id.

Source§

impl<Id> Response<Id>

Source

pub const fn hovered(&self) -> bool

The pointer is over this widget’s rect, resolved from last frame’s hit-test: see Interaction for why there’s a frame of latency.

Source

pub const fn pressed(&self) -> bool

The primary pointer button went down on this widget this frame, or (sensed with Sense::FOCUSABLE) Enter or Space was pressed while it was focused.

Source

pub const fn released(&self) -> bool

The primary pointer button (or an activating key) was released this frame while this widget was the active one. Fires whether or not the release also counts as a clicked (e.g. it doesn’t, if the gesture crossed the drag threshold first).

Source

pub const fn clicked(&self) -> bool

A full press-release cycle landed on this widget this frame: pressed and released while still hovered, never crossing the drag threshold. Also fires from keyboard activation (Enter/Space while focused) – terminals are frequently mouse-less, so Sense::click widgets are keyboard-operable by default.

Source

pub const fn double_clicked(&self) -> bool

A second clicked landed on this widget within Interaction::with_double_click_window frames of the first, e.g. to open a file on double-click while a single click just selects it. Implies clicked is also true this frame. A third click starts counting fresh rather than re-firing every frame after the second: each pair of qualifying clicks reports exactly one double_clicked frame.

Source

pub const fn held(&self) -> bool

The primary pointer button is down and the pointer is currently over this widget’s rect, re-checked live every frame, unlike pressed, which fires once on the down edge and never re-checks position. Automatically cancels (goes false) the instant the pointer slides off this widget’s rect, even before release, without waiting for a release event: the same “slide-to-cancel” feedback is_pointer_button_down_on gives egui widgets and IsItemHovered() && IsItemActive() gives Dear ImGui widgets. Only ever true for widgets sensed with Sense::CLICK.

Source

pub const fn dragging(&self) -> bool

The pointer moved past the drag threshold while pressed on this widget. Only ever true for widgets sensed with Sense::DRAG.

Source

pub const fn focused(&self) -> bool

This widget holds keyboard focus. Unlike the other fields, this is level state, not a one-shot “this happened” flag: it stays true across frames until focus moves to another widget or is cleared.

Source

pub const fn gained_focus(&self) -> bool

This widget just became focused this frame, having not been focused last frame: a one-shot edge for a widget that wants to react only on the transition (e.g. select-all-on-focus for a text input), rather than every frame focused happens to be true.

Source

pub const fn lost_focus(&self) -> bool

This widget was focused last frame but isn’t anymore: the mirror of gained_focus, e.g. to commit a text input’s edits when focus moves away.

Source

pub const fn secondary_clicked(&self) -> bool

The secondary (right) mouse button pressed and released on this widget this frame while still hovered. Only ever true for widgets sensed with Sense::SECONDARY_CLICK. Unlike clicked, there’s no keyboard equivalent – a secondary action needs its own trigger (a modifier+Enter, a menu key, whatever fits the app) since Enter/Space already means “primary activate”.

Source

pub const fn scroll_delta(&self) -> i32

Scroll wheel delta accumulated this frame while the pointer was within this widget’s rect (regardless of what else was drawn on top of it; see Sense::SCROLL): positive scrolls forward/down, negative scrolls backward/up. Feeds straight into ListState::scroll_by. Zero unless sensed with SCROLL and something scrolled.

Source

pub const fn disabled(&self) -> bool

This widget was interacted with via a Sense that had Sense::DISABLED set. hovered still works, so a disabled control can show a tooltip explaining why; every other field above is false (or 0) regardless of what the pointer/keyboard did. Widgets should read this instead of threading a parallel enabled bool into their own draw call.

Source

pub const fn pointer_pos(&self) -> Option<Pos>

Where the pointer is, in grid coordinates, resolved from the same last-frame snapshot hovered is computed from: Some exactly when this widget’s rect contains the pointer, None when it’s elsewhere or this widget wasn’t sensed with a pointer-registering Sense. Lets a composite widget shown under a single id (a list of rows, a strip of tabs) resolve which of its own parts the pointer is over, without needing a distinct id per part.

Source

pub const fn press_origin(&self) -> Option<Pos>

Where the pointer was when the press currently active on this widget landed. Unlike pointer_pos, this stays put for the duration of a press or drag rather than tracking the pointer’s current position: useful for a composite widget (e.g. a scrollbar thumb) that needs to measure a drag’s total displacement from where it started. None unless this widget is the one a press is currently active on.

Source

pub const fn drag_delta(&self) -> Option<(i32, i32)>

How far the pointer has moved from press_origin, signed and in grid cells: (pointer.x - press_origin.x, pointer.y - press_origin.y). Unlike pointer_pos, this keeps reporting once the pointer slides outside this widget’s own rect, which is the common case for a Sense::DRAG widget like a scrollbar thumb or a resizable pane divider: both need the drag’s full displacement, not just the part of it that stayed over the thumb. None under the same condition press_origin is None: no press is currently active on this widget.

Source

pub const fn rect(&self) -> Rect

The area this widget was shown at, as passed to Interaction::interact this frame. Useful for anything that draws relative to where this widget landed, e.g. a tooltip anchored under its trigger.

Trait Implementations§

Source§

impl<Id: Clone> Clone for Response<Id>

Source§

fn clone(&self) -> Response<Id>

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<Id: Debug> Debug for Response<Id>

Source§

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

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

impl Default for Response<()>

Source§

fn default() -> Self

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

impl<Id: PartialEq> PartialEq for Response<Id>

Source§

fn eq(&self, other: &Response<Id>) -> 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<Id: Copy> Copy for Response<Id>

Source§

impl<Id: Eq> Eq for Response<Id>

Source§

impl<Id> StructuralPartialEq for Response<Id>

Auto Trait Implementations§

§

impl<Id> Freeze for Response<Id>
where Id: Freeze,

§

impl<Id> RefUnwindSafe for Response<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for Response<Id>
where Id: Send,

§

impl<Id> Sync for Response<Id>
where Id: Sync,

§

impl<Id> Unpin for Response<Id>
where Id: Unpin,

§

impl<Id> UnsafeUnpin for Response<Id>
where Id: UnsafeUnpin,

§

impl<Id> UnwindSafe for Response<Id>
where Id: UnwindSafe,

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]).