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