SourceClass Response
from egui import Responseclass Response:The result of adding a widget to a Ui.
A Response lets you know whether a widget is being hovered, clicked or dragged.
It also lets you easily show a tooltip on hover.
Whenever something gets added to a Ui, a Response object is returned.
Ui.add returns a Response, as does Ui.button, and all similar shortcuts.
⚠️ The Response contains a clone of Context, and many methods lock the Context.
It can therefore be a deadlock to use Context from within a context-locking closures,
such as Context.input.
Properties§
@property
def ctx(self, /) -> Context§
@property
def flags(self, /) -> ResponseFlags§
@flags.setter
def flags(self, /, flags: ResponseFlags) -> None§
@property
def id(self, /) -> Id§
Source@property
def interact_pointer_pos(self, /) -> Pos2 |None§
Where the pointer (mouse/touch) were when this widget was clicked or dragged.
None if the widget is not being interacted with.
@property
def interact_pointer_pos_or_nan(self, /) -> Pos2§
@interact_pointer_pos_or_nan.setter
def interact_pointer_pos_or_nan(self, /, interact_pointer_pos_or_nan: Pos2) -> None§
@property
def interact_rect(self, /) -> Rect§
Source@property
def intrinsic_size(self, /) -> Vec2 |None§
The intrinsic / desired size of the widget.
This is the size that a non-wrapped, non-truncated, non-justified version of the widget would have.
If this is None, use egui.Response.rect instead.
@property
def intrinsic_size_or_nan(self, /) -> Vec2§
@intrinsic_size_or_nan.setter
def intrinsic_size_or_nan(self, /, intrinsic_size_or_nan: Vec2) -> None§
@property
def layer_id(self, /) -> LayerId§
@property
def rect(self, /) -> Rect§
@property
def sense(self, /) -> Sense§
Methods§
Sourcedef 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.
Sourcedef 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.
egui.Button senses clicks; egui.Label does not (unless you call egui.Label.sense).
You can use egui.Response.interact to sense more things after adding a widget.
Sourcedef 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 egui.Response.clicked instead.
This will likewise ignore the press-and-hold action on touch screens.
Use egui.Response.secondary_clicked instead to also detect that.
Sourcedef 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.
Clicks on other layers above this widget will be considered as clicking elsewhere.
Sourcedef clicked_with_open_in_background(self, /) -> bool§
Was this widget middle-clicked or clicked while holding down a modifier key?
This is used by egui.Hyperlink to check if a URL should be opened
in a new tab, using egui.OpenUrl.new_tab.
def clone_ref(self, /) -> Response§
Sourcedef 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 egui.Response.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
egui.Response.contains_pointer also checks that no other widget is covering this response rectangle.
Sourcedef dnd_hover_payload(self, /) -> Any |None§
Drag-and-Drop: Return what is being held over this widget, if any.
Only returns something if egui.Response.contains_pointer is true,
and the user is drag-dropping something of this type.
Sourcedef dnd_release_payload(self, /) -> Any |None§
Drag-and-Drop: Return what is being dropped onto this widget, if any.
Only returns something if egui.Response.contains_pointer is true,
the user is drag-dropping something of this type,
and they released it this frame.
Sourcedef dnd_set_drag_payload(self, /, payload: Any) -> None§
If the user started dragging this widget this frame, store the payload for drag-and-drop.
Sourcedef double_clicked(self, /) -> bool§
Returns true if this widget was double-clicked this frame by the primary button.
Sourcedef double_clicked_by(self, /, button: PointerButton) -> bool§
Returns true if this widget was double-clicked this frame by the given button.
Sourcedef drag_delta(self, /) -> Vec2§
If dragged, how many points were we dragged in since last frame?
Sourcedef drag_motion(self, /) -> Vec2§
If dragged, how far did the mouse move since last frame?
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.
Sourcedef 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.
Sourcedef 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.
Sourcedef drag_stopped(self, /) -> bool§
The widget was being dragged, but now it has been released.
Sourcedef drag_stopped_by(self, /, button: PointerButton) -> bool§
The widget was being dragged by the button, but now it has been released.
Sourcedef dragged(self, /) -> bool§
The widget is being dragged.
To find out which button(s), use egui.Response.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, the press could be either, so the
decision is postponed until whichever of these comes first:
* the pointer moves further than egui.InputOptions.max_click_dist,
* it is held longer than egui.InputOptions.max_click_duration,
* or it leaves the widget — a click has to be released on the widget, so
once the pointer is outside, the gesture can only be a drag. This is what
keeps a handle thinner than max_click_dist from spending the decision
window as neither hovered nor dragged.
See egui.input_state.PointerState.is_decidedly_dragging for details.
While the decision is pending the pointer is still on the widget, so
egui.Response.hovered is True throughout. If you want neither the delay nor
the distinction, use egui.Response.is_pointer_button_down_on.
If the widget is NOT sensitive to drags, this will always be False.
egui.DragValue senses drags; egui.Label does not (unless you call egui.Label.sense).
You can use egui.Response.interact to sense more things after adding a widget.
Sourcedef dragged_by(self, /, button: PointerButton) -> bool§
Sourcedef 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.
Sourcedef gained_focus(self, /) -> bool§
True if this widget has keyboard focus this frame, but didn't last frame.
Sourcedef 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.
Sourcedef highlight(self, /) -> Response§
Highlight this widget, to make it look like it is hovered, even if it isn't.
The highlight takes one frame to take effect if you call this after the widget has been fully rendered.
See also Context.highlight_widget.
Sourcedef highlighted(self, /) -> bool§
The widget is highlighted via a call to egui.Response.highlight or Context.highlight_widget.
Sourcedef hover_pos(self, /) -> Pos2 |None§
If it is a good idea to show a tooltip, where is pointer?
None if the pointer is outside the response area.
Sourcedef hovered(self, /) -> bool§
The pointer is hovering above this widget or the widget was clicked/tapped this frame.
In contrast to egui.Response.contains_pointer, this will be False whenever some other widget is being dragged.
hovered is always False for disabled widgets.
While a widget is being clicked or dragged it is the only hovered widget,
so this stays True even after the pointer moves off it. Together with
how egui.Response.dragged resolves a press that leaves the widget, that means
hovered() || dragged() holds for a whole press-drag-release gesture,
which is what you want for highlighting something like a drag handle.
Sourcedef 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 egui.Label.sense.
Using this method on a Response that is the result of calling union on multiple Responses
is undefined behavior.
Sourcedef is_pointer_button_down_on(self, /) -> bool§
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?".
Unlike egui.Response.dragged, this is True from the press frame onwards, with
no click-versus-drag decision window.
Sourcedef is_tooltip_open(self, /) -> bool§
Was the tooltip open last frame?
Sourcedef labelled_by(self, /, id: Id) -> Response§
Associate a label with a control for accessibility.
Example
Sourcedef long_touched(self, /) -> bool§
Was this long-pressed on a touch screen?
Usually you want to check egui.Response.secondary_clicked instead.
Sourcedef 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 egui.TextEdit) because the user pressed enter.
Sourcedef mark_changed(self, /) -> None§
Report the data shown by this widget changed.
This must be called by widgets that represent some mutable data, e.g. checkboxes, sliders etc.
This should be called when the content changes, but not when the view does.
So we call this when the text of a egui.TextEdit, but not when the cursor changes.
Sourcedef middle_clicked(self, /) -> bool§
Returns true if this widget was clicked this frame by the middle mouse 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.
Note that the widget must be sensing clicks with Sense.click.
egui.Button senses clicks; egui.Label does not (unless you call egui.Label.sense).
Sourcedef on_disabled_hover_text(self, /, text: str) -> Response§
Show this text when hovering if the widget is disabled.
Sourcedef on_disabled_hover_ui(self, /) -> Any§
Show this UI when hovering if the widget is disabled.
Sourcedef on_hover_and_drag_cursor(self, /, cursor: CursorIcon) -> Response§
When hovered or dragged, use this icon for the mouse cursor.
Sourcedef on_hover_cursor(self, /, cursor: CursorIcon) -> Response§
When hovered, use this icon for the mouse cursor.
Sourcedef on_hover_text(self, /, text: str) -> Response§
Show this text if the widget was hovered (i.e. a tooltip).
The text will not be visible if the widget is not enabled.
For that, use egui.Response.on_disabled_hover_text instead.
If you call this multiple times the tooltips will stack underneath the previous ones.
Sourcedef on_hover_text_at_pointer(self, /, text: str) -> Response§
Like on_hover_text, but show the text next to cursor.
Sourcedef on_hover_ui(self, /) -> Any§
Show this UI if the widget was hovered (i.e. a tooltip).
The text will not be visible if the widget is not enabled.
For that, use egui.Response.on_disabled_hover_ui instead.
If you call this multiple times the tooltips will stack underneath the previous ones.
The widget can contain interactive widgets, such as buttons and links.
If so, it will stay open as the user moves their pointer over it.
By default, the text of a tooltip is NOT selectable (i.e. interactive),
but you can change this by setting [style.Interaction.selectable_labels from within the tooltip:
Sourcedef on_hover_ui_at_pointer(self, /) -> Any§
Like on_hover_ui, but show the ui next to cursor.
Sourcedef output_event(self, /, event: OutputEvent) -> None§
Sourcedef paint_debug_info(self, /) -> None§
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
Sourcedef parent_id(self, /) -> Id§
The Id of the parent egui.Ui that hosts this widget.
Looks up the WidgetRect from the current (or previous) pass.
Sourcedef request_focus(self, /) -> None§
Request that this widget get keyboard focus.
Sourcedef scroll_to_me(self, /, align: Align |None) -> None§
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.
Sourcedef scroll_to_me_animation(self, /, align: Align |None, animation: ScrollAnimation) -> None§
Like egui.Response.scroll_to_me, but allows you to specify the egui.style.ScrollAnimation.
Sourcedef secondary_clicked(self, /) -> bool§
Returns true if this widget was clicked this frame by the secondary mouse button (e.g. the right mouse 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.
Note that the widget must be sensing clicks with Sense.click.
egui.Button senses clicks; egui.Label does not (unless you call egui.Label.sense).
This also returns true if the widget was pressed-and-held on a touch screen.
Sourcedef set_close(self, /) -> None§
Set the Flags.CLOSE flag.
Can be used to e.g. signal that a container should be closed.
Sourcedef set_intrinsic_size(self, /, size: Vec2) -> None§
Set the intrinsic / desired size of the widget.
Sourcedef should_close(self, /) -> bool§
Should the container be closed?
Will e.g. be set by calling Ui.close in a child Ui or by calling
egui.Response.set_close.
Sourcedef show_tooltip_text(self, /, text: str) -> None§
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.
Sourcedef show_tooltip_ui(self, /, add_contents: Any) -> bool§
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.
Sourcedef surrender_focus(self, /) -> None§
Surrender keyboard focus for this widget.
Sourcedef total_drag_delta(self, /) -> Vec2 |None§
If dragged, how many points have we been dragged since the start of the drag?
Sourcedef triple_clicked(self, /) -> bool§
Returns true if this widget was triple-clicked this frame by the primary button.
Sourcedef triple_clicked_by(self, /, button: PointerButton) -> bool§
Returns true if this widget was triple-clicked this frame by the given button.
Sourcedef union(self, /, other: Response) -> Response§
A logical "or" operation.
For instance a.union(b).hovered means "was either a or b hovered?".
The resulting egui.Response.id will come from the first (self) argument.
You may not call egui.Response.interact on the resulting Response.
Sourcedef widget_info(self, /, widget_info: WidgetInfo) -> None§
For accessibility.
Call after interacting and potential calls to egui.Response.mark_changed.
def widget_rect(self, /) -> WidgetRect§
def widget_state(self, /) -> WidgetState§
Sourcedef with_new_rect(self, /, rect: Rect) -> Response§
Returns a response with a modified egui.Response.rect.