pub struct Popup<'a> { /* private fields */ }
Expand description
A popup container.
Implementations§
Source§impl<'a> Popup<'a>
impl<'a> Popup<'a>
Sourcepub fn new(
id: Id,
ctx: Context,
anchor: impl Into<PopupAnchor>,
layer_id: LayerId,
) -> Self
pub fn new( id: Id, ctx: Context, anchor: impl Into<PopupAnchor>, layer_id: LayerId, ) -> Self
Create a new popup
Sourcepub fn from_response(response: &Response) -> Self
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.
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.
Show a popup when the widget was clicked.
Sets the layout to Layout::top_down_justified(Align::Min)
.
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.
Sourcepub fn kind(self, kind: PopupKind) -> Self
pub fn kind(self, kind: PopupKind) -> Self
Set the kind of the popup. Used for Area::kind
and Area::order
.
Sourcepub fn info(self, info: UiStackInfo) -> Self
pub fn info(self, info: UiStackInfo) -> Self
Set the UiStackInfo
of the popup’s Ui
.
Sourcepub fn align(self, position_align: RectAlign) -> Self
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.
Sourcepub fn align_alternatives(self, alternatives: &'a [RectAlign]) -> Self
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
.
Sourcepub fn open_memory(self, set_state: impl Into<Option<SetOpenCommand>>) -> Self
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.
Sourcepub fn close_behavior(self, close_behavior: PopupCloseBehavior) -> Self
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.
Sourcepub fn at_pointer(self) -> Self
pub fn at_pointer(self) -> Self
Show the popup relative to the pointer.
Sourcepub fn at_pointer_fixed(self) -> Self
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.
Sourcepub fn at_position(self, position: Pos2) -> Self
pub fn at_position(self, position: Pos2) -> Self
Show the popup relative to a specific position.
Sourcepub fn anchor(self, anchor: impl Into<PopupAnchor>) -> Self
pub fn anchor(self, anchor: impl Into<PopupAnchor>) -> Self
Show the popup relative to the given PopupAnchor
.
Sourcepub fn width(self, width: f32) -> Self
pub fn width(self, width: f32) -> Self
The width that will be passed to Area::default_width
.
Sourcepub fn style(self, style: impl Into<StyleModifier>) -> Self
pub fn style(self, style: impl Into<StyleModifier>) -> Self
Set the style for the popup contents.
Default:
- is
menu_style
forSelf::menu
andSelf::context_menu
- is
None
otherwise
Sourcepub fn get_anchor(&self) -> PopupAnchor
pub fn get_anchor(&self) -> PopupAnchor
Return the PopupAnchor
of the popup.
Sourcepub fn get_anchor_rect(&self) -> Option<Rect>
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.
Sourcepub fn get_popup_rect(&self) -> Option<Rect>
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.
Sourcepub fn get_expected_size(&self) -> Option<Vec2>
pub fn get_expected_size(&self) -> Option<Vec2>
Get the expected size of the popup.
Sourcepub fn get_best_align(&self) -> RectAlign
pub fn get_best_align(&self) -> RectAlign
Calculate the best alignment for the popup, based on the last size and screen rect.
Source§impl Popup<'_>
§Static methods
impl Popup<'_>
§Static methods
Sourcepub fn default_response_id(response: &Response) -> Id
pub fn default_response_id(response: &Response) -> Id
The default ID when constructing a popup from the Response
of e.g. a button.
Sourcepub fn is_id_open(ctx: &Context, popup_id: Id) -> bool
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
.
Sourcepub fn is_any_open(ctx: &Context) -> bool
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.
Sourcepub fn open_id(ctx: &Context, popup_id: Id)
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.
Sourcepub fn toggle_id(ctx: &Context, popup_id: Id)
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.
Sourcepub fn close_id(ctx: &Context, popup_id: Id)
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.