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

§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");
    });
});

Trait Implementations§

Source§

impl Clone for Response

Source§

fn clone(&self) -> Response

Returns a duplicate of the value. Read more
1.0.0 · 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.