Skip to main content

Response

Struct Response 

Source
pub struct Response {
    pub clicked: bool,
    pub right_clicked: bool,
    pub hovered: bool,
    pub changed: bool,
    pub focused: bool,
    pub gained_focus: bool,
    pub lost_focus: bool,
    pub double_clicked: bool,
    pub submitted: bool,
    pub scroll_delta: i32,
    pub rect: Rect,
}
Expand description

Interaction response returned by all widgets.

Container methods return a Response. Check .clicked, .changed, etc. to react to user interactions. rect is meaningful after the widget has participated in layout. Container responses describe the container’s own interaction area, not automatically the focus state of every child widget.

§Examples

let r = ui.row(|ui| {
    ui.text("Save");
});
if r.clicked {
    // handle save
}

Fields§

§clicked: bool

Whether the widget was left-clicked this frame.

§right_clicked: bool

Whether the widget was right-clicked this frame.

Detected when a MouseButton::Right Down event lands inside the widget’s rect. Suppressed for non-overlay widgets while a modal is active (consistent with the existing modal-suppression behavior of clicked / hovered). Available since v0.20.0.

§hovered: bool

Whether the mouse is hovering over the widget.

§changed: bool

Whether the widget’s value changed this frame.

§focused: bool

Whether the widget currently has keyboard focus.

§gained_focus: bool

Whether the widget just received keyboard focus this frame.

true only on the first frame after focus moved to this widget; false thereafter (until focus moves away and returns). Mutually exclusive with lost_focus. Available since v0.20.0.

§lost_focus: bool

Whether the widget just lost keyboard focus this frame.

true only on the first frame after focus moved away from this widget; false on subsequent frames. Mutually exclusive with gained_focus. Available since v0.20.0.

§double_clicked: bool

Whether the widget was double-clicked this frame.

Detected when two MouseButton::Left Down events land on the same terminal cell within the double-click window (~400ms). When true, clicked is also true for the same frame (the second click is still a click). This is the standard open/activate gesture for file pickers, lists, tables, and trees. Suppressed for non-overlay widgets while a modal is active, consistent with clicked. Available since v0.21.1.

§submitted: bool

Whether the widget submitted its value this frame.

Set by widgets that have an explicit submit gesture — e.g. pressing Enter in a focused single-line text_input. Always false for widgets with no submit semantics. Available since v0.21.1.

§scroll_delta: i32

Net vertical scroll-wheel delta over this widget this frame.

Positive = wheel scrolled up, negative = down, 0 when the wheel did not move while the cursor was over the widget’s rect. Hover-gated, so each widget consumes only the wheel motion that occurred above it — a chart, canvas, or custom viewport can scroll/zoom locally without a frame-global scroll handler. Available since v0.21.1.

§rect: Rect

The rectangle the widget occupies after layout.

Implementations§

Source§

impl Response

Source

pub fn none() -> Self

Create a Response with all fields false/default.

Source

pub fn on_hover(self, ctx: &mut Context, text: impl Into<String>) -> Self

Attach a tooltip to this widget. Renders only when the widget is currently hovered.

Equivalent to calling Context::tooltip immediately after the widget, but composes cleanly with the chained Response style:

if ui.button("Save").on_hover(ui, "Saves the file").clicked {
    save();
}

text is wrapped at 38 columns and rendered in an overlay panel anchored under (or above, if no room below) the widget’s rect. Empty strings, zero-area rects, and non-hovered responses are silently skipped — no allocation in the cold path.

Unlike Context::tooltip, the binding is not order-sensitive: the tooltip is attached to this response specifically, so chaining further widgets afterward does not strip it.

Source

pub fn on_hover_ui( self, ctx: &mut Context, f: impl FnOnce(&mut Context), ) -> Self

Run a closure to render arbitrary tooltip content when the widget is hovered.

The closure receives the same &mut Context and runs immediately (in-place — not deferred). This means the closure can issue any UI commands; positioning is the caller’s responsibility (use Context::overlay / Context::overlay_at inside the closure for floating panels).

For simple text tooltips, prefer Response::on_hover which auto-positions the tooltip under the widget.

ui.button("Help").on_hover_ui(ui, |ui| {
    let _ = ui.overlay(|ui| {
        ui.text("Custom tooltip body");
    });
});
Source

pub fn on_click(self, ctx: &mut Context, f: impl FnOnce(&mut Context)) -> Self

Run f if the widget was clicked this frame, then return the Response for further chaining.

The closure receives the same &mut Context so it can issue UI commands (e.g. queue a toast); ignore the argument with |_| if you only need to mutate application state.

ui.button("Save").on_click(ui, |_| save());
Source

pub fn on_changed(self, ctx: &mut Context, f: impl FnOnce(&mut Context)) -> Self

Run f if the widget’s value changed this frame, then return the Response for chaining. See on_click for the closure argument convention. Available since v0.21.1.

Source

pub fn on_focus(self, ctx: &mut Context, f: impl FnOnce(&mut Context)) -> Self

Run f on the frame the widget gained keyboard focus, then return the Response for chaining. Fires once per focus acquisition (mirrors gained_focus). Available since v0.21.1.

Source

pub fn on_submit(self, ctx: &mut Context, f: impl FnOnce(&mut Context)) -> Self

Run f if the widget submitted this frame (e.g. Enter in a focused single-line text input), then return the Response for chaining. Mirrors submitted. Available since v0.21.1.

Source

pub fn on_double_click( self, ctx: &mut Context, f: impl FnOnce(&mut Context), ) -> Self

Run f if the widget was double-clicked this frame, then return the Response for chaining. Mirrors double_clicked. Available since v0.21.1.

Trait Implementations§

Source§

impl Clone for Response

Source§

fn clone(&self) -> Response

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 Response

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() -> Response

Returns the “default value” for a type. 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> 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.