pub struct OverlaySlot<PodState>where
PodState: 'static,{ /* private fields */ }Expand description
The overlay-portal authoring surface: the slot a widget that floats its own surface holds, what that surface is anchored to, and the placement geometry every anchored pattern needs.
Promoted here rather than left to each design system because all three of
them had derived the same geometry independently: a design system’s popover,
menu, tooltip and context menu place a surface through place and host it
through OverlaySlot, reaching both through frust::authoring alone.
One floated surface an owner hosts: the pod, where it goes, and the routing
of the input the root sends back to it.
§The four calls
An owner widget forwards four of its own lifecycle calls here, and the slot does nothing on its own:
rebuildfrom the owner’sView::rebuild, with the overlay view it wants mounted (orNoneto drop it).layoutfrom the owner’sWidget::layout— the pod is laid out loosely against the window, never the owner’s own constraints, because it escapes the owner’s box entirely.paintfrom the owner’sWidget::paint, which computes the placement and registers the pod. It paints nothing: the root paints every registered pod after the main tree, which is the only way a surface escapes its owner’s paint order and every ancestor’s clip.event(orevent_ambient) from the owner’sWidget::event, before the owner routes to its own children.Nonemeans “not mine” and the owner carries on.
§PodState
The state type the floated view is diffed against. Two shapes exist and the dispatch call differs between them:
- the pod is built over the ambient application state (what
overlay_portaldoes): useevent_ambient, which forwards through the owner’s ownEventCtxso focus, capture, hover and IME all bubble exactly as they do for any other child; - the pod is built over a different state —
()for a framework-built surface whose callbacks carry their own handles: useeventand hand it&mut PodState, which dispatches over a substituted context (see that method for what does and does not bubble through the substitution).
Implementations§
Source§impl<PodState> OverlaySlot<PodState>where
PodState: 'static,
impl<PodState> OverlaySlot<PodState>where
PodState: 'static,
Sourcepub fn new() -> OverlaySlot<PodState>
pub fn new() -> OverlaySlot<PodState>
A closed slot with a fresh identity: Floating, interactive, ignoring
outside taps, anchored to its owner’s own bounds.
Built once, when the owner widget is built, and kept: the key is the whole addressing mechanism between the root and this surface.
Sourcepub fn key(&self) -> OverlayKey
pub fn key(&self) -> OverlayKey
This surface’s identity.
Sourcepub fn window_rect(&self) -> Rect
pub fn window_rect(&self) -> Rect
Where the last paint placed the surface, in window space.
Rect::ZERO before the first paint of an open slot — a surface that
has never been painted has never been registered, so nothing routes to
it either.
Sourcepub fn pod_has_focus(&self) -> bool
pub fn pod_has_focus(&self) -> bool
Whether the pod holds a focus link on the live session — the read every routing decision here makes.
Not the raw recorded flag: a claim made from inside a floated surface reaches no container’s blur sweep, so a link this surface recorded survives the session moving away from it (see the module docs’ Focus lifetime). Asking the raw flag would keep routing the keyboard into a surface the user has left.
Sourcepub fn withdraw_pod_focus(&mut self)
pub fn withdraw_pod_focus(&mut self)
Drop the pod’s recorded focus link, so focus-routed events stop reaching it — the owner’s half of “the surface asked for focus, and the owner declined on its behalf”.
An owner’s decision, and the only reason this exists: a link the session has merely moved away from needs no call, since its stamp retires it on its own (see the module docs’ Focus lifetime).
Sourcepub fn take_outside_down(&mut self) -> bool
pub fn take_outside_down(&mut self) -> bool
Take the pending outside-press notification, clearing it.
true exactly once per press that landed outside every floated surface
while this one was registered OutsideTap::Notify — the light-dismiss
signal an owner closes on.
Sourcepub fn set_band(&mut self, band: OverlayBand)
pub fn set_band(&mut self, band: OverlayBand)
Which z-band the surface paints and hit-tests in.
Sourcepub fn set_input(&mut self, input: OverlayInput)
pub fn set_input(&mut self, input: OverlayInput)
Whether the surface takes pointer input at all.
Sourcepub fn set_outside_tap(&mut self, outside_tap: OutsideTap)
pub fn set_outside_tap(&mut self, outside_tap: OutsideTap)
What a press outside every floated surface delivers here.
Sourcepub fn set_placement(&mut self, placement: OverlayPlacement)
pub fn set_placement(&mut self, placement: OverlayPlacement)
Where the surface sits relative to its anchor.
Sourcepub fn set_anchor(&mut self, anchor: OverlayAnchor)
pub fn set_anchor(&mut self, anchor: OverlayAnchor)
What the surface is placed against.
Sourcepub fn rebuild(
&mut self,
prev: Option<&AnyView<PodState>>,
next: Option<&AnyView<PodState>>,
ctx: &mut BuildCtx<'_>,
) -> ChangeFlags
pub fn rebuild( &mut self, prev: Option<&AnyView<PodState>>, next: Option<&AnyView<PodState>>, ctx: &mut BuildCtx<'_>, ) -> ChangeFlags
Mount, reconcile or drop the floated view — the owner’s View::rebuild
half.
prev/next are the previous and current frame’s overlay views, in the
shape rebuild_child itself takes: a
None → Some transition builds the pod, Some → Some reconciles it
in place (so a kept-open surface keeps its own widget state), Some →
None tears it down, and None → None does nothing. An owner that
mounts a view it builds itself (from a process-global builder, say)
keeps the previous one and hands both in.
Dropping the pod also drops any capture it held: the widget that was mid-gesture no longer exists, so there is nothing to unwind and nothing to route follow-ups to.
Sourcepub fn layout(&mut self, ctx: &mut LayoutCtx<'_>)
pub fn layout(&mut self, ctx: &mut LayoutCtx<'_>)
Lay the pod out against the window — the owner’s Widget::layout half.
Loose constraints against
LayoutCtx::window_size, never the
owner’s own bc: the surface escapes the owner’s box, so the owner’s
constraints say nothing about how much room it has. The pod’s own origin
stays Point::ZERO — the root paints it at the registered rect’s
origin and adds the pod’s origin on top, and routing tests the registered
rect alone, so any other value would desynchronize paint from hit test.
Sourcepub fn paint(&mut self, ctx: &mut PaintCtx<'_>, owner_size: Size)
pub fn paint(&mut self, ctx: &mut PaintCtx<'_>, owner_size: Size)
Place and register the pod — the owner’s Widget::paint half.
Computes the anchor rect in window space from
PaintCtx::origin (plus the local rect,
for OverlayAnchor::Rect), places the pod against it with place,
records the result and hands the root a registration. It paints
nothing: an owner that also painted the pod would draw the surface
twice, once clipped in place and once floated.
Registration is per paint pass, so a surface stays alive exactly while its owner keeps painting — an owner that is culled, unmounted or simply stops registering disappears from the routing table after the next paint with nothing to unregister.
Sourcepub fn event(
&mut self,
ctx: &mut EventCtx<'_>,
event: &InputEvent,
state: &mut PodState,
) -> Option<EventResult>
pub fn event( &mut self, ctx: &mut EventCtx<'_>, event: &InputEvent, state: &mut PodState, ) -> Option<EventResult>
Route an event into the surface over a substituted state — the
owner’s Widget::event half for a pod whose PodState is not the
ambient application state (a ()-typed, framework-built surface).
Some(_) means the slot owned the event and the owner must not route it
on; None means it belongs to the owner’s ordinary routing.
§What crosses the substitution
The pod runs over a fresh EventCtx built on state, exactly as a
component boundary runs its subtree over its own local state, and the
results are mirrored back onto the owner’s context: a redraw request, a
pointer capture, and a focus claim or release (observed through the pod’s
own recorded link). A published IME surface and a hover claim do not
cross — an IME publish has no route back through a substituted context,
and an overlay event is a broadcast, which records no hover anywhere. A
surface that needs either is built over the ambient state instead (see
event_ambient).
Edit commands do cross, by a different road: they ride a pass-scoped
queue rather than the context, so a pod that calls
EventCtx::dispatch_edit_command
is drained by the owner’s
EventCtx::take_edit_commands
in the same pass.
Sourcepub fn event_ambient(
&mut self,
ctx: &mut EventCtx<'_>,
event: &InputEvent,
) -> Option<EventResult>
pub fn event_ambient( &mut self, ctx: &mut EventCtx<'_>, event: &InputEvent, ) -> Option<EventResult>
Route an event into the surface over the ambient application state —
the owner’s Widget::event half for a pod built over the same state the
owner itself is diffed against.
The pod is dispatched through the owner’s own EventCtx, so
everything a child normally bubbles (redraw, capture, focus, a published
IME surface) reaches the root unchanged, and the pod’s callbacks reach
the same application state every other widget sees. This is the route
overlay_portal takes.
Trait Implementations§
Source§impl<PodState> Default for OverlaySlot<PodState>where
PodState: 'static,
impl<PodState> Default for OverlaySlot<PodState>where
PodState: 'static,
Source§fn default() -> OverlaySlot<PodState>
fn default() -> OverlaySlot<PodState>
Auto Trait Implementations§
impl<PodState> !RefUnwindSafe for OverlaySlot<PodState>
impl<PodState> !Send for OverlaySlot<PodState>
impl<PodState> !Sync for OverlaySlot<PodState>
impl<PodState> !UnwindSafe for OverlaySlot<PodState>
impl<PodState> Freeze for OverlaySlot<PodState>
impl<PodState> Unpin for OverlaySlot<PodState>
impl<PodState> UnsafeUnpin for OverlaySlot<PodState>
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.