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>
impl<Id: Copy> Response<Id>
Sourcepub const fn id(&self) -> Id
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>
impl<Id> Response<Id>
Sourcepub const fn hovered(&self) -> bool
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.
Sourcepub const fn pressed(&self) -> bool
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.
Sourcepub const fn released(&self) -> bool
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).
Sourcepub const fn clicked(&self) -> bool
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.
Sourcepub const fn double_clicked(&self) -> bool
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.
Sourcepub const fn held(&self) -> bool
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.
Sourcepub const fn dragging(&self) -> bool
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.
Sourcepub const fn focused(&self) -> bool
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.
Sourcepub const fn gained_focus(&self) -> bool
pub const fn gained_focus(&self) -> bool
Sourcepub const fn lost_focus(&self) -> bool
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.
Sourcepub const fn secondary_clicked(&self) -> bool
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”.
Sourcepub const fn scroll_delta(&self) -> i32
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.
Sourcepub const fn disabled(&self) -> bool
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.
Sourcepub const fn pointer_pos(&self) -> Option<Pos>
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.
Sourcepub const fn press_origin(&self) -> Option<Pos>
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.
Sourcepub const fn drag_delta(&self) -> Option<(i32, i32)>
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.
Sourcepub const fn rect(&self) -> Rect
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: PartialEq> PartialEq for Response<Id>
impl<Id: PartialEq> PartialEq for Response<Id>
impl<Id: Copy> Copy for Response<Id>
impl<Id: Eq> Eq for Response<Id>
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).