Skip to main content

OverlaySlot

Struct OverlaySlot 

Source
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:

  1. rebuild from the owner’s View::rebuild, with the overlay view it wants mounted (or None to drop it).
  2. layout from the owner’s Widget::layout — the pod is laid out loosely against the window, never the owner’s own constraints, because it escapes the owner’s box entirely.
  3. paint from the owner’s Widget::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.
  4. event (or event_ambient) from the owner’s Widget::event, before the owner routes to its own children. None means “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_portal does): use event_ambient, which forwards through the owner’s own EventCtx so 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: use event and 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,

Source

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.

Source

pub fn key(&self) -> OverlayKey

This surface’s identity.

Source

pub fn is_open(&self) -> bool

Whether a pod is currently mounted.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn set_band(&mut self, band: OverlayBand)

Which z-band the surface paints and hit-tests in.

Source

pub fn set_input(&mut self, input: OverlayInput)

Whether the surface takes pointer input at all.

Source

pub fn set_outside_tap(&mut self, outside_tap: OutsideTap)

What a press outside every floated surface delivers here.

Source

pub fn set_placement(&mut self, placement: OverlayPlacement)

Where the surface sits relative to its anchor.

Source

pub fn set_anchor(&mut self, anchor: OverlayAnchor)

What the surface is placed against.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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,

Source§

fn default() -> OverlaySlot<PodState>

Returns the “default value” for a type. Read more

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> 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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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