Skip to main content

Popup

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, ) -> Popup<'a>

Create a new popup

Source

pub fn from_response(response: &Response) -> Popup<'a>

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) -> Popup<'a>

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) -> Popup<'a>

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) -> Popup<'a>

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) -> Popup<'a>

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

Source

pub fn info(self, info: UiStackInfo) -> Popup<'a>

Set the UiStackInfo of the popup’s Ui.

Source

pub fn align(self, position_align: RectAlign) -> Popup<'a>

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]) -> Popup<'a>

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) -> Popup<'a>

Force the popup to be open or closed.

Source

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

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) -> Popup<'a>

Store the open state via a mutable bool.

Source

pub fn close_behavior(self, close_behavior: PopupCloseBehavior) -> Popup<'a>

Set the close behavior of the popup.

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

Source

pub fn at_pointer(self) -> Popup<'a>

Show the popup relative to the pointer.

Source

pub fn at_pointer_fixed(self) -> Popup<'a>

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) -> Popup<'a>

Show the popup relative to a specific position.

Source

pub fn anchor(self, anchor: impl Into<PopupAnchor>) -> Popup<'a>

Show the popup relative to the given PopupAnchor.

Source

pub fn anchor_widget(self, widget_id: Id) -> Popup<'a>

The widget this popup belongs to.

The popup is nested under it in the accessibility tree. Set automatically by Self::from_response and everything built on it.

Source

pub fn accessible_name(self, name: impl Into<String>) -> Popup<'a>

Name the popup in the accessibility tree.

See Area::accessible_name.

Source

pub fn gap(self, gap: f32) -> Popup<'a>

Set the gap between the anchor and the popup.

Source

pub fn frame(self, frame: Frame) -> Popup<'a>

Set the frame of the popup.

Source

pub fn interactable(self, interactable: bool) -> Popup<'a>

If false, the pointer goes straight through the popup and it’s widgets to whatever is behind it.

Default: true.

Source

pub fn sense(self, sense: Sense) -> Popup<'a>

Set the sense of the popup.

Source

pub fn layout(self, layout: Layout) -> Popup<'a>

Set the layout of the popup.

Source

pub fn width(self, width: f32) -> Popup<'a>

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

Source

pub fn sizing_pass(self, sizing_pass: bool) -> Popup<'a>

Force the popup’s underlying Area to run an invisible sizing pass.

Popups automatically run a sizing pass when they open or reopen. Set this to true for one frame when the contents of an already open popup change and its cached size may no longer fit. Do not leave it enabled continuously, because the popup would remain invisible.

Default: false.

Source

pub fn id(self, id: Id) -> Popup<'a>

Set the id of the Area.

Source

pub fn style(self, style: impl Into<StyleModifier>) -> Popup<'a>

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.

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> !RefUnwindSafe for Popup<'a>

§

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

§

impl<'a> Forget for Popup<'a>

§

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

§

impl<'a> Move for Popup<'a>

§

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

§

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

§

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

§

impl<'a> UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

fn simd_from(_simd: S, value: T) -> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more