pub struct OutlinerResponse<Id>{
pub inner: Response,
pub changed: bool,
pub selected: Option<Id>,
pub double_clicked: Option<Id>,
pub context_menu: Option<Id>,
pub renamed: Option<(Id, String)>,
pub drag_started: Option<Id>,
pub dragging_nodes: Vec<Id>,
pub drop_event: Option<DropEvent<Id>>,
}Expand description
The response from rendering an outliner widget.
This type wraps an egui::Response and provides additional information about
outliner-specific events that occurred during the frame, such as node selection,
double-clicks, context menu requests, renaming, and drag-drop operations.
§Generic Parameters
§Examples
let response = outliner.show(ui, &mut state);
if let Some(id) = response.selected() {
println!("Node selected: {:?}", id);
}
if let Some((id, new_name)) = response.renamed() {
println!("Node {} renamed to: {}", id, new_name);
}
if let Some(drop_event) = response.drop_event() {
println!("Dropped {:?} onto {:?}", drop_event.source, drop_event.target);
}Fields§
§inner: ResponseThe underlying egui widget response.
This can be accessed directly via Deref to check standard widget properties
like hover state, clicks, etc.
changed: boolWhether any outliner state changed this frame.
This includes selection changes, expansion/collapse, renaming, etc. Useful for determining if you need to save state or trigger updates.
selected: Option<Id>ID of the node that was newly selected this frame, if any.
This is Some only when the selection changes, not on every frame
where a node is selected.
double_clicked: Option<Id>ID of the node that was double-clicked this frame, if any.
Double-clicking typically triggers an action like opening or editing a node.
ID of the node for which a context menu was requested this frame, if any.
This is typically triggered by right-clicking on a node.
renamed: Option<(Id, String)>ID and new name of a node that was renamed this frame, if any.
The tuple contains (node_id, new_name).
drag_started: Option<Id>ID of the node where a drag operation started this frame, if any.
This indicates the user began dragging a node.
dragging_nodes: Vec<Id>IDs of all nodes being dragged (includes the primary drag node and any selected nodes).
When dragging with multiple selections, this contains all selected node IDs.
drop_event: Option<DropEvent<Id>>Details of a drop event that occurred this frame, if any.
This contains information about the source node, target node, and drop position.
Implementations§
Source§impl<Id> OutlinerResponse<Id>
impl<Id> OutlinerResponse<Id>
Sourcepub fn new(inner: Response) -> Self
pub fn new(inner: Response) -> Self
Creates a new outliner response with no events.
All event fields are initialized to None and changed is set to false.
The widget implementation will populate these fields as events occur.
§Arguments
inner- The underlying egui response from the widget
§Examples
let response = OutlinerResponse::new(ui.allocate_response(size, Sense::click()));Sourcepub fn double_clicked(&self) -> Option<&Id>
pub fn double_clicked(&self) -> Option<&Id>
Sourcepub fn drag_started(&self) -> Option<&Id>
pub fn drag_started(&self) -> Option<&Id>
Sourcepub fn dragging_nodes(&self) -> &[Id]
pub fn dragging_nodes(&self) -> &[Id]
Methods from Deref<Target = Response>§
Sourcepub fn clicked(&self) -> bool
pub fn clicked(&self) -> bool
Returns true if this widget was clicked this frame by the primary button.
A click is registered when the mouse or touch is released within a certain amount of time and distance from when and where it was pressed.
This will also return true if the widget was clicked via accessibility integration, or if the widget had keyboard focus and the use pressed Space/Enter.
Note that the widget must be sensing clicks with Sense::click.
crate::Button senses clicks; crate::Label does not (unless you call crate::Label::sense).
You can use Self::interact to sense more things after adding a widget.
Sourcepub fn clicked_by(&self, button: PointerButton) -> bool
pub fn clicked_by(&self, button: PointerButton) -> bool
Returns true if this widget was clicked this frame by the given mouse button.
This will NOT return true if the widget was “clicked” via
some accessibility integration, or if the widget had keyboard focus and the
user pressed Space/Enter. For that, use Self::clicked instead.
This will likewise ignore the press-and-hold action on touch screens.
Use Self::secondary_clicked instead to also detect that.
Sourcepub fn secondary_clicked(&self) -> bool
pub fn secondary_clicked(&self) -> bool
Returns true if this widget was clicked this frame by the secondary mouse button (e.g. the right mouse button).
This also returns true if the widget was pressed-and-held on a touch screen.
Sourcepub fn long_touched(&self) -> bool
pub fn long_touched(&self) -> bool
Was this long-pressed on a touch screen?
Usually you want to check Self::secondary_clicked instead.
Sourcepub fn middle_clicked(&self) -> bool
pub fn middle_clicked(&self) -> bool
Returns true if this widget was clicked this frame by the middle mouse button.
Sourcepub fn double_clicked(&self) -> bool
pub fn double_clicked(&self) -> bool
Returns true if this widget was double-clicked this frame by the primary button.
Sourcepub fn triple_clicked(&self) -> bool
pub fn triple_clicked(&self) -> bool
Returns true if this widget was triple-clicked this frame by the primary button.
Sourcepub fn double_clicked_by(&self, button: PointerButton) -> bool
pub fn double_clicked_by(&self, button: PointerButton) -> bool
Returns true if this widget was double-clicked this frame by the given button.
Sourcepub fn triple_clicked_by(&self, button: PointerButton) -> bool
pub fn triple_clicked_by(&self, button: PointerButton) -> bool
Returns true if this widget was triple-clicked this frame by the given button.
Sourcepub fn clicked_elsewhere(&self) -> bool
pub fn clicked_elsewhere(&self) -> bool
true if there was a click outside the rect of this widget.
Clicks on widgets contained in this one counts as clicks inside this widget, so that clicking a button in an area will not be considered as clicking “elsewhere” from the area.
Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Was the widget enabled? If false, there was no interaction attempted and the widget should be drawn in a gray disabled look.
Sourcepub fn hovered(&self) -> bool
pub fn hovered(&self) -> bool
The pointer is hovering above this widget or the widget was clicked/tapped this frame.
In contrast to Self::contains_pointer, this will be false whenever some other widget is being dragged.
hovered is always false for disabled widgets.
Sourcepub fn contains_pointer(&self) -> bool
pub fn contains_pointer(&self) -> bool
Returns true if the pointer is contained by the response rect, and no other widget is covering it.
In contrast to Self::hovered, this can be true even if some other widget is being dragged.
This means it is useful for styling things like drag-and-drop targets.
contains_pointer can also be true for disabled widgets.
This is slightly different from Ui::rect_contains_pointer and Context::rect_contains_pointer, in that
Self::contains_pointer also checks that no other widget is covering this response rectangle.
Sourcepub fn has_focus(&self) -> bool
pub fn has_focus(&self) -> bool
This widget has the keyboard focus (i.e. is receiving key presses).
This function only returns true if the UI as a whole (e.g. window) also has the keyboard focus. That makes this function suitable for style choices, e.g. a thicker border around focused widgets.
Sourcepub fn gained_focus(&self) -> bool
pub fn gained_focus(&self) -> bool
True if this widget has keyboard focus this frame, but didn’t last frame.
Sourcepub fn lost_focus(&self) -> bool
pub fn lost_focus(&self) -> bool
The widget had keyboard focus and lost it,
either because the user pressed tab or clicked somewhere else,
or (in case of a crate::TextEdit) because the user pressed enter.
let response = ui.text_edit_singleline(&mut my_text);
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
do_request(&my_text);
}Sourcepub fn request_focus(&self)
pub fn request_focus(&self)
Request that this widget get keyboard focus.
Sourcepub fn surrender_focus(&self)
pub fn surrender_focus(&self)
Surrender keyboard focus for this widget.
Sourcepub fn drag_started(&self) -> bool
pub fn drag_started(&self) -> bool
Did a drag on this widget begin this frame?
This is only true if the widget sense drags. If the widget also senses clicks, this will only become true if the pointer has moved a bit.
This will only be true for a single frame.
Sourcepub fn drag_started_by(&self, button: PointerButton) -> bool
pub fn drag_started_by(&self, button: PointerButton) -> bool
Did a drag on this widget by the button begin this frame?
This is only true if the widget sense drags. If the widget also senses clicks, this will only become true if the pointer has moved a bit.
This will only be true for a single frame.
Sourcepub fn dragged(&self) -> bool
pub fn dragged(&self) -> bool
The widget is being dragged.
To find out which button(s), use Self::dragged_by.
If the widget is only sensitive to drags, this is true as soon as the pointer presses down on it.
If the widget also senses clicks, this won’t be true until the pointer has moved a bit,
or the user has pressed down for long enough.
See crate::input_state::PointerState::is_decidedly_dragging for details.
If you want to avoid the delay, use Self::is_pointer_button_down_on instead.
If the widget is NOT sensitive to drags, this will always be false.
crate::DragValue senses drags; crate::Label does not (unless you call crate::Label::sense).
You can use Self::interact to sense more things after adding a widget.
Sourcepub fn dragged_by(&self, button: PointerButton) -> bool
pub fn dragged_by(&self, button: PointerButton) -> bool
See Self::dragged.
Sourcepub fn drag_stopped(&self) -> bool
pub fn drag_stopped(&self) -> bool
The widget was being dragged, but now it has been released.
Sourcepub fn drag_stopped_by(&self, button: PointerButton) -> bool
pub fn drag_stopped_by(&self, button: PointerButton) -> bool
The widget was being dragged by the button, but now it has been released.
Sourcepub fn drag_released(&self) -> bool
👎Deprecated: Renamed ‘drag_stopped’
pub fn drag_released(&self) -> bool
The widget was being dragged, but now it has been released.
Sourcepub fn drag_released_by(&self, button: PointerButton) -> bool
👎Deprecated: Renamed ‘drag_stopped_by’
pub fn drag_released_by(&self, button: PointerButton) -> bool
The widget was being dragged by the button, but now it has been released.
Sourcepub fn drag_delta(&self) -> Vec2
pub fn drag_delta(&self) -> Vec2
If dragged, how many points were we dragged and in what direction?
Sourcepub fn drag_motion(&self) -> Vec2
pub fn drag_motion(&self) -> Vec2
If dragged, how far did the mouse move?
This will use raw mouse movement if provided by the integration, otherwise will fall back to Response::drag_delta
Raw mouse movement is unaccelerated and unclamped by screen boundaries, and does not relate to any position on the screen.
This may be useful in certain situations such as draggable values and 3D cameras, where screen position does not matter.
Sourcepub fn dnd_set_drag_payload<Payload>(&self, payload: Payload)
pub fn dnd_set_drag_payload<Payload>(&self, payload: Payload)
If the user started dragging this widget this frame, store the payload for drag-and-drop.
Sourcepub fn dnd_hover_payload<Payload>(&self) -> Option<Arc<Payload>>
pub fn dnd_hover_payload<Payload>(&self) -> Option<Arc<Payload>>
Drag-and-Drop: Return what is being held over this widget, if any.
Only returns something if Self::contains_pointer is true,
and the user is drag-dropping something of this type.
Sourcepub fn dnd_release_payload<Payload>(&self) -> Option<Arc<Payload>>
pub fn dnd_release_payload<Payload>(&self) -> Option<Arc<Payload>>
Drag-and-Drop: Return what is being dropped onto this widget, if any.
Only returns something if Self::contains_pointer is true,
the user is drag-dropping something of this type,
and they released it this frame
Sourcepub fn interact_pointer_pos(&self) -> Option<Pos2>
pub fn interact_pointer_pos(&self) -> Option<Pos2>
Where the pointer (mouse/touch) were when this widget was clicked or dragged.
None if the widget is not being interacted with.
Sourcepub fn hover_pos(&self) -> Option<Pos2>
pub fn hover_pos(&self) -> Option<Pos2>
If it is a good idea to show a tooltip, where is pointer?
None if the pointer is outside the response area.
Is the pointer button currently down on this widget?
This is true if the pointer is pressing down or dragging a widget, even when dragging outside the widget.
This could also be thought of as “is this widget being interacted with?”.
Sourcepub fn changed(&self) -> bool
pub fn changed(&self) -> bool
Was the underlying data changed?
e.g. the slider was dragged, text was entered in a TextEdit etc.
Always false for something like a Button.
Can sometimes be true even though the data didn’t changed
(e.g. if the user entered a character and erased it the same frame).
This is not set if the view of the data was changed.
For instance, moving the cursor in a TextEdit does not set this to true.
Note that this can be true even if the user did not interact with the widget,
for instance if an existing slider value was clamped to the given range.
Sourcepub fn show_tooltip_ui(&self, add_contents: impl FnOnce(&mut Ui))
pub fn show_tooltip_ui(&self, add_contents: impl FnOnce(&mut Ui))
Always show this tooltip, even if disabled and the user isn’t hovering it.
This can be used to give attention to a widget during a tutorial.
Sourcepub fn show_tooltip_text(&self, text: impl Into<WidgetText>)
pub fn show_tooltip_text(&self, text: impl Into<WidgetText>)
Always show this tooltip, even if disabled and the user isn’t hovering it.
This can be used to give attention to a widget during a tutorial.
Sourcepub fn is_tooltip_open(&self) -> bool
pub fn is_tooltip_open(&self) -> bool
Was the tooltip open last frame?
Sourcepub fn interact(&self, sense: Sense) -> Response
pub fn interact(&self, sense: Sense) -> Response
Sense more interactions (e.g. sense clicks on a Response returned from a label).
The interaction will occur on the same plane as the original widget, i.e. if the response was from a widget behind button, the interaction will also be behind that button. egui gives priority to the last added widget (the one on top gets clicked first).
Note that this call will not add any hover-effects to the widget, so when possible
it is better to give the widget a Sense instead, e.g. using crate::Label::sense.
Using this method on a Response that is the result of calling union on multiple Responses
is undefined behavior.
let horiz_response = ui.horizontal(|ui| {
ui.label("hello");
}).response;
assert!(!horiz_response.clicked()); // ui's don't sense clicks by default
let horiz_response = horiz_response.interact(egui::Sense::click());
if horiz_response.clicked() {
// The background behind the label was clicked
}Sourcepub fn scroll_to_me(&self, align: Option<Align>)
pub fn scroll_to_me(&self, align: Option<Align>)
Adjust the scroll position until this UI becomes visible.
If align is Align::TOP it means “put the top of the rect at the top of the scroll area”, etc.
If align is None, it’ll scroll enough to bring the UI into view.
See also: Ui::scroll_to_cursor, Ui::scroll_to_rect. Ui::scroll_with_delta.
egui::ScrollArea::vertical().show(ui, |ui| {
for i in 0..1000 {
let response = ui.button("Scroll to me");
if response.clicked() {
response.scroll_to_me(Some(egui::Align::Center));
}
}
});Sourcepub fn scroll_to_me_animation(
&self,
align: Option<Align>,
animation: ScrollAnimation,
)
pub fn scroll_to_me_animation( &self, align: Option<Align>, animation: ScrollAnimation, )
Like Self::scroll_to_me, but allows you to specify the crate::style::ScrollAnimation.
Sourcepub fn widget_info(&self, make_info: impl Fn() -> WidgetInfo)
pub fn widget_info(&self, make_info: impl Fn() -> WidgetInfo)
For accessibility.
Call after interacting and potential calls to Self::mark_changed.
pub fn output_event(&self, event: OutputEvent)
Response to secondary clicks (right-clicks) by showing the given menu.
Make sure the widget senses clicks (e.g. crate::Button does, crate::Label does not).
let response = ui.add(Label::new("Right-click me!").sense(Sense::click()));
response.context_menu(|ui| {
if ui.button("Close the menu").clicked() {
ui.close_menu();
}
});See also: Ui::menu_button and Ui::close_menu.
Returns whether a context menu is currently open for this widget.
See Self::context_menu.
Sourcepub fn paint_debug_info(&self)
pub fn paint_debug_info(&self)
Draw a debug rectangle over the response displaying the response’s id and whether it is enabled and/or hovered.
This function is intended for debugging purpose and can be useful, for example, in case of widget id instability.
Color code:
- Blue: Enabled but not hovered
- Green: Enabled and hovered
- Red: Disabled
Trait Implementations§
Source§impl<Id> Debug for OutlinerResponse<Id>
impl<Id> Debug for OutlinerResponse<Id>
Source§impl<Id> Deref for OutlinerResponse<Id>
impl<Id> Deref for OutlinerResponse<Id>
Source§fn deref(&self) -> &Self::Target
fn deref(&self) -> &Self::Target
Dereferences to the underlying egui::Response.
This allows convenient access to standard response methods like
hovered(), clicked(), rect, etc.
§Examples
let response = outliner.show(ui, &mut state);
// Access egui::Response methods directly
if response.hovered() {
ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);
}