Skip to main content

AtomLayoutResponse

Struct AtomLayoutResponse 

Source
pub struct AtomLayoutResponse {
    pub response: Response,
    /* private fields */
}
Expand description

Response from a AtomLayout::show or AllocatedAtomLayout::paint.

Use AtomLayoutResponse::rect to get the response rects from crate::Atom::custom.

Fields§

§response: Response

Implementations§

Source§

impl AtomLayoutResponse

Source

pub fn empty(response: Response) -> Self

Source

pub fn custom_rects(&self) -> impl Iterator<Item = (Id, Rect)> + '_

Source

pub fn rect(&self, id: Id) -> Option<Rect>

Use this together with crate::Atom::custom to add custom painting / child widgets.

NOTE: Don’t unwrap rects, they might be empty when the widget is not visible.

Methods from Deref<Target = Response>§

Source

pub fn parent_id(&self) -> Id

The Id of the parent crate::Ui that hosts this widget.

Looks up the WidgetRect from the current (or previous) pass.

Source

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.

Source

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.

Source

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.

Source

pub fn long_touched(&self) -> bool

Was this long-pressed on a touch screen?

Usually you want to check Self::secondary_clicked instead.

Source

pub fn middle_clicked(&self) -> bool

Returns true if this widget was clicked this frame by the middle mouse button.

Source

pub fn double_clicked(&self) -> bool

Returns true if this widget was double-clicked this frame by the primary button.

Source

pub fn triple_clicked(&self) -> bool

Returns true if this widget was triple-clicked this frame by the primary button.

Source

pub fn double_clicked_by(&self, button: PointerButton) -> bool

Returns true if this widget was double-clicked this frame by the given button.

Source

pub fn triple_clicked_by(&self, button: PointerButton) -> bool

Returns true if this widget was triple-clicked this frame by the given button.

Source

pub fn clicked_with_open_in_background(&self) -> bool

Was this widget middle-clicked or clicked while holding down a modifier key?

This is used by crate::Hyperlink to check if a URL should be opened in a new tab, using crate::OpenUrl::new_tab.

Source

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.

Clicks on other layers above this widget will be considered as clicking elsewhere.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn gained_focus(&self) -> bool

True if this widget has keyboard focus this frame, but didn’t last frame.

Source

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);
}
Source

pub fn request_focus(&self)

Request that this widget get keyboard focus.

Source

pub fn surrender_focus(&self)

Surrender keyboard focus for this widget.

Source

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.

Source

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.

Source

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.

Source

pub fn dragged_by(&self, button: PointerButton) -> bool

Source

pub fn drag_stopped(&self) -> bool

The widget was being dragged, but now it has been released.

Source

pub fn drag_stopped_by(&self, button: PointerButton) -> bool

The widget was being dragged by the button, but now it has been released.

Source

pub fn drag_delta(&self) -> Vec2

If dragged, how many points were we dragged in since last frame?

Source

pub fn total_drag_delta(&self) -> Option<Vec2>

If dragged, how many points have we been dragged since the start of the drag?

Source

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

Source

pub fn dnd_set_drag_payload<Payload: Any + Send + Sync>(&self, payload: Payload)

If the user started dragging this widget this frame, store the payload for drag-and-drop.

Source

pub fn dnd_hover_payload<Payload: Any + Send + Sync>( &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.

Source

pub fn dnd_release_payload<Payload: Any + Send + Sync>( &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.

Source

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.

Source

pub fn intrinsic_size(&self) -> Option<Vec2>

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 Self::rect instead.

Source

pub fn set_intrinsic_size(&mut self, size: Vec2)

Set the intrinsic / desired size of the widget.

Source

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.

Source

pub fn 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?”.

Source

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.

Source

pub fn mark_changed(&mut self)

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 crate::TextEdit, but not when the cursor changes.

Source

pub fn 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 Self::set_close.

Source

pub fn set_close(&mut self)

Set the [Flags::CLOSE] flag.

Can be used to e.g. signal that a container should be closed.

Source

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.

Source

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.

Source

pub fn is_tooltip_open(&self) -> bool

Was the tooltip open last frame?

Source

pub fn interact(&self, sense: Sense) -> Self

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
}
Source

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));
        }
    }
});
Source

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.

Source

pub fn widget_info(&self, make_info: impl Fn() -> WidgetInfo)

For accessibility.

Call after interacting and potential calls to Self::mark_changed.

Source

pub fn output_event(&self, event: OutputEvent)

Source

pub fn context_menu( &self, add_contents: impl FnOnce(&mut Ui), ) -> Option<InnerResponse<()>>

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();
    }
});

See also: Ui::menu_button and Ui::close.

Source

pub fn context_menu_opened(&self) -> bool

Returns whether a context menu is currently open for this widget.

See Self::context_menu.

Source

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
Source

pub fn union(&self, other: Self) -> Self

A logical “or” operation. For instance a.union(b).hovered means “was either a or b hovered?”.

The resulting Self::id will come from the first (self) argument.

You may not call Self::interact on the resulting Response.

Source

pub fn widget_state(&self) -> WidgetState

Trait Implementations§

Source§

impl Clone for AtomLayoutResponse

Source§

fn clone(&self) -> AtomLayoutResponse

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 AtomLayoutResponse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for AtomLayoutResponse

Source§

type Target = Response

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for AtomLayoutResponse

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.