Struct Popup

Source
pub struct Popup<'a> { /* private fields */ }
Expand description

A popup container.

Implementations§

Source§

impl<'a> Popup<'a>

Source

pub fn new( id: Id, ctx: Context, anchor: impl Into<PopupAnchor>, layer_id: LayerId, ) -> Self

Create a new popup

Source

pub fn from_response(response: &Response) -> Self

Show a popup relative to some widget. The popup will be always open.

See Self::menu and Self::context_menu for common use cases.

Source

pub fn from_toggle_button_response(button_response: &Response) -> Self

Show a popup relative to some widget, toggling the open state based on the widget’s click state.

See Self::menu and Self::context_menu for common use cases.

Source

pub fn menu(button_response: &Response) -> Self

Show a popup when the widget was clicked. Sets the layout to Layout::top_down_justified(Align::Min).

Source

pub fn context_menu(response: &Response) -> Self

Show a context menu when the widget was secondary clicked. Sets the layout to Layout::top_down_justified(Align::Min). In contrast to Self::menu, this will open at the pointer position.

Source

pub fn kind(self, kind: PopupKind) -> Self

Set the kind of the popup. Used for Area::kind and Area::order.

Source

pub fn info(self, info: UiStackInfo) -> Self

Set the UiStackInfo of the popup’s Ui.

Source

pub fn align(self, position_align: RectAlign) -> Self

Set the RectAlign of the popup relative to the PopupAnchor. This is the default position, and will be used if it fits. See Self::align_alternatives for more on this.

Source

pub fn align_alternatives(self, alternatives: &'a [RectAlign]) -> Self

Set alternative positions to try if the default one doesn’t fit. Set to an empty slice to always use the position you set with Self::align. By default, this will try RectAlign::symmetries and then RectAlign::MENU_ALIGNS.

Source

pub fn open(self, open: bool) -> Self

Force the popup to be open or closed.

Source

pub fn open_memory(self, set_state: impl Into<Option<SetOpenCommand>>) -> Self

Store the open state via crate::Memory. You can set the state via the first SetOpenCommand param.

Source

pub fn open_bool(self, open: &'a mut bool) -> Self

Store the open state via a mutable bool.

Source

pub fn close_behavior(self, close_behavior: PopupCloseBehavior) -> Self

Set the close behavior of the popup.

This will do nothing if Popup::open was called.

Source

pub fn at_pointer(self) -> Self

Show the popup relative to the pointer.

Source

pub fn at_pointer_fixed(self) -> Self

Remember the pointer position at the time of opening the popup, and show the popup relative to that.

Source

pub fn at_position(self, position: Pos2) -> Self

Show the popup relative to a specific position.

Source

pub fn anchor(self, anchor: impl Into<PopupAnchor>) -> Self

Show the popup relative to the given PopupAnchor.

Source

pub fn gap(self, gap: f32) -> Self

Set the gap between the anchor and the popup.

Source

pub fn frame(self, frame: Frame) -> Self

Set the frame of the popup.

Source

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

Set the sense of the popup.

Source

pub fn layout(self, layout: Layout) -> Self

Set the layout of the popup.

Source

pub fn width(self, width: f32) -> Self

The width that will be passed to Area::default_width.

Source

pub fn id(self, id: Id) -> Self

Set the id of the Area.

Source

pub fn style(self, style: impl Into<StyleModifier>) -> Self

Set the style for the popup contents.

Default:

Source

pub fn ctx(&self) -> &Context

Get the Context

Source

pub fn get_anchor(&self) -> PopupAnchor

Return the PopupAnchor of the popup.

Source

pub fn get_anchor_rect(&self) -> Option<Rect>

Return the anchor rect of the popup.

Returns None if the anchor is PopupAnchor::Pointer and there is no pointer.

Source

pub fn get_popup_rect(&self) -> Option<Rect>

Get the expected rect the popup will be shown in.

Returns None if the popup wasn’t shown before or anchor is PopupAnchor::Pointer and there is no pointer.

Source

pub fn get_id(&self) -> Id

Get the id of the popup.

Source

pub fn is_open(&self) -> bool

Is the popup open?

Source

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

Get the expected size of the popup.

Source

pub fn get_best_align(&self) -> RectAlign

Calculate the best alignment for the popup, based on the last size and screen rect.

Source

pub fn show<R>( self, content: impl FnOnce(&mut Ui) -> R, ) -> Option<InnerResponse<R>>

Show the popup. Returns None if the popup is not open or anchor is PopupAnchor::Pointer and there is no pointer.

Source§

impl Popup<'_>

§Static methods
Source

pub fn default_response_id(response: &Response) -> Id

The default ID when constructing a popup from the Response of e.g. a button.

Source

pub fn is_id_open(ctx: &Context, popup_id: Id) -> bool

Is the given popup open?

This assumes the use of either:

The popup id should be the same as either you set with Self::id or the default one from Self::default_response_id.

Source

pub fn is_any_open(ctx: &Context) -> bool

Is any popup open?

This assumes the egui memory is being used to track the open state of popups.

Source

pub fn open_id(ctx: &Context, popup_id: Id)

Open the given popup and close all others.

If you are NOT using Popup::show, you must also call crate::Memory::keep_popup_open as long as you’re showing the popup.

Source

pub fn toggle_id(ctx: &Context, popup_id: Id)

Toggle the given popup between closed and open.

Note: At most, only one popup can be open at a time.

Source

pub fn close_all(ctx: &Context)

Close all currently open popups.

Source

pub fn close_id(ctx: &Context, popup_id: Id)

Close the given popup, if it is open.

See also Self::close_all if you want to close any / all currently open popups.

Source

pub fn position_of_id(ctx: &Context, popup_id: Id) -> Option<Pos2>

Get the position for this popup, if it is open.

Auto Trait Implementations§

§

impl<'a> Freeze for Popup<'a>

§

impl<'a> !RefUnwindSafe for Popup<'a>

§

impl<'a> Send for Popup<'a>

§

impl<'a> Sync for Popup<'a>

§

impl<'a> Unpin for Popup<'a>

§

impl<'a> !UnwindSafe for Popup<'a>

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> 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, 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.