pub struct Popup<T> { /* private fields */ }Expand description
Popup state with an exit phase. gpui unmounts an element the frame its
state drops, so a closing animation needs the state held alive while
motion::menu_out plays: open → begin_close (render keeps mounting,
with the out animation and dead hit-testing) → reap_popup’s timer
finish_closees ~motion::MENU_OUT later. Use Self::is_open for
logic (a closing popup already reads as closed) and Self::get /
Self::is_closing for rendering.
Implementations§
Source§impl<T> Popup<T>
impl<T> Popup<T>
pub fn open(&mut self, value: T)
pub fn is_closing(&self) -> bool
Sourcepub fn closing_since(&self) -> Option<Instant>
pub fn closing_since(&self) -> Option<Instant>
When the exit phase began — what the render path hands to the popover wrappers, which derive the eased exit progress from it each frame.
Sourcepub fn get(&self) -> Option<&T>
pub fn get(&self) -> Option<&T>
The state while mounted — open OR playing the exit animation. Render
paths use this; logic paths use Self::as_open/Self::open_mut.
Sourcepub fn as_open(&self) -> Option<&T>
pub fn as_open(&self) -> Option<&T>
The state only while genuinely open — None during the exit phase, so
event handlers on a dying popup fall through.
pub fn open_mut(&mut self) -> Option<&mut T>
Sourcepub fn close(&mut self)
pub fn close(&mut self)
Unmount now, with no exit phase.
For a surface that has no exit animation to play — modal, which
takes no closing and paints the same either way. Sending one of those
through Self::begin_close buys nothing and costs everything: it
stays fully painted for the animation’s span, and if the reap never
lands it stays forever, because nothing retries.
Not for a popup something toggles: unmounting on the press erases what
Self::note_trigger_press has to read, so the note comes back false
and the trigger reopens what it just shut. Those close through
close_popup.
Sourcepub fn begin_close(&mut self) -> bool
pub fn begin_close(&mut self) -> bool
Enter the exit phase. Returns true when this call started it (the
caller then schedules reap_popup); false if already closing or
closed.
Sourcepub fn note_trigger_press(&mut self)
pub fn note_trigger_press(&mut self)
Record, from the trigger’s on_mouse_down, whether this popup is
still mounted. The anchored card’s on_mouse_down_out fires on that
same press and begins the close, so by click (mouse-up) time the
popup already reads as closed — the click handler alone cannot tell
“this press dismissed it; stay closed” from “open fresh”, and a
plain toggle closes-and-reopens (user report). Both handler orders
work: open and mid-exit each count as mounted. Every trigger click
is preceded by a trigger mouse-down, so the note is never stale.
menu_trigger wires this and the matching click together. Reach for
it directly only when the open is not a click — a gutter handle whose
menu belongs to the release of a possible drag.
Sourcepub fn note_trigger_press_matching(&mut self, owns: impl FnOnce(&T) -> bool)
pub fn note_trigger_press_matching(&mut self, owns: impl FnOnce(&T) -> bool)
Self::note_trigger_press for popups whose state distinguishes
which trigger owns them (e.g. one Popup<PickerKind> shared by
several triggers): only a press on the OWNING trigger counts, so
clicking a different trigger switches menus instead of swallowing.
Sourcepub fn take_press_was_open(&mut self) -> bool
pub fn take_press_was_open(&mut self) -> bool
Consume the press note: true when the press that produced the
current click found the popup mounted — the click should leave it
closed rather than reopen it.
Sourcepub fn finish_close(&mut self)
pub fn finish_close(&mut self)
Drop the state now the exit phase has run its course. A popup reopened
since the matching Self::begin_close is left alone — it is None
again in the second slot, and the newer phase’s own reap handles it.
It does not re-check the clock. reap_popup already waited out the
span on the executor’s timer, and asking Instant::elapsed to agree
makes one deadline depend on two clocks — where they disagree, and a
throttled executor is where, the popup is stranded open with nothing
left to retry.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Popup<T>
impl<T> RefUnwindSafe for Popup<T>
impl<T> Send for Popup<T>
impl<T> Sync for Popup<T>
impl<T> Unpin for Popup<T>
impl<T> UnsafeUnpin for Popup<T>
impl<T> UnwindSafe for Popup<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().