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: boolWhether the widget was left-clicked this frame.
right_clicked: boolWhether 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: boolWhether the mouse is hovering over the widget.
changed: boolWhether the widget’s value changed this frame.
focused: boolWhether the widget currently has keyboard focus.
gained_focus: boolWhether 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: boolWhether 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: boolWhether 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: boolWhether 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: i32Net 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: RectThe rectangle the widget occupies after layout.
Implementations§
Source§impl Response
impl Response
Sourcepub fn on_hover(self, ctx: &mut Context, text: impl Into<String>) -> Self
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.
Sourcepub fn on_hover_ui(
self,
ctx: &mut Context,
f: impl FnOnce(&mut Context),
) -> Self
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");
});
});Sourcepub fn on_click(self, ctx: &mut Context, f: impl FnOnce(&mut Context)) -> Self
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());Sourcepub fn on_changed(self, ctx: &mut Context, f: impl FnOnce(&mut Context)) -> Self
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.
Sourcepub fn on_focus(self, ctx: &mut Context, f: impl FnOnce(&mut Context)) -> Self
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.
Sourcepub fn on_submit(self, ctx: &mut Context, f: impl FnOnce(&mut Context)) -> Self
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.
Sourcepub fn on_double_click(
self,
ctx: &mut Context,
f: impl FnOnce(&mut Context),
) -> Self
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.