Skip to main content

OverlayRequest

Struct OverlayRequest 

Source
#[non_exhaustive]
pub struct OverlayRequest { pub content_id: WidgetId, pub anchor: WidgetId, pub placement: OverlayPlacement, pub dismiss: DismissBehavior, pub layer: OverlayLayer, pub parent_overlay: Option<OverlayId>, pub on_dismiss: Option<OverlayDismissCallback>, pub fade_duration: Option<Duration>, pub inert: bool, }
Expand description

A request to show an overlay.

Built with new, which takes what every overlay has to decide, and the builder methods for the rest. The fields stay public, so a request can still be adjusted after it is built: that is how a value that is already an Option is set, since the builders take the bare value.

Non-exhaustive, so that a field added later reaches every caller as its default instead of breaking each struct literal.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§content_id: WidgetId

The root widget of the overlay content.

§anchor: WidgetId

The widget this overlay is anchored to.

§placement: OverlayPlacement

Positioning relative to the anchor.

§dismiss: DismissBehavior

How the overlay is dismissed.

§layer: OverlayLayer

Rendering layer.

§parent_overlay: Option<OverlayId>

Parent overlay (for submenu cascading).

§on_dismiss: Option<OverlayDismissCallback>

Invoked when the overlay is dismissed by any path. Use this to reset anchor-side state (e.g. ComboBox.interaction) when the framework tears down the overlay without going through the anchor’s own key/tap handlers.

§fade_duration: Option<Duration>

Optional fade-in / fade-out duration. When Some, the framework attaches an animated opacity scope to content_id at show time (using the existing set_opacity rendering pipeline — no Fade widget required from the caller), tweens the opacity from 0 → 1 over duration, and on dismiss reverses the tween and defers the actual stack removal by duration. Set with OverlayRequest::with_fade.

§inert: bool

The overlay takes no input. Set with OverlayRequest::inert, which says what that means.

Implementations§

Source§

impl OverlayRequest

Source

pub fn new( content_id: WidgetId, anchor: WidgetId, placement: OverlayPlacement, dismiss: DismissBehavior, ) -> Self

A request to show content_id at placement relative to anchor, taken down the way dismiss says.

dismiss is an argument rather than a default because no one value suits most overlays, and the likeliest default is the worst one to inherit unawares: a Manual overlay that takes input is opaque to Escape, for itself and for every overlay beneath it (see OverlayManager::try_dismiss_top_on_escape).

Everything else starts at the value nearly every overlay uses:

use std::time::Duration;
use teksilo_core::WidgetId;
use teksilo_core::overlay::{DismissBehavior, OverlayPlacement, OverlayRequest};

let request = OverlayRequest::new(
    popup,
    trigger,
    OverlayPlacement::BelowPreferred,
    DismissBehavior::EscapeOrClickOutside,
)
.with_fade(Duration::from_millis(150));
assert_eq!(request.fade_duration, Some(Duration::from_millis(150)));
Source

pub fn layer(self, layer: OverlayLayer) -> Self

Render the overlay on layer. Default: OverlayLayer::InTree.

Source

pub fn parent_overlay(self, parent: OverlayId) -> Self

Nest the overlay under parent, so that dismissing parent takes this one down with it, the way a menu takes its submenu. Default: None, a top-level overlay.

A parent that is already an Option is assigned to the parent_overlay field instead.

Source

pub fn on_dismiss(self, callback: OverlayDismissCallback) -> Self

Run callback when the overlay is dismissed, whatever the path. Default: None.

It takes the shared OverlayDismissCallback rather than a closure because an anchor usually installs one callback on every route that opens its overlay; a one-off closure is wrapped in Rc::new.

Source

pub fn with_fade(self, duration: Duration) -> Self

Attach a fade-in / fade-out animation to this request. duration controls both directions. The framework wires everything internally — caller does not create a Fade widget or manage a signal. Default: no fade.

A duration that is already an Option (no fade under reduced motion, say) is assigned to the fade_duration field instead.

Source

pub fn inert(self) -> Self

Make the overlay inert: something to look at, never to work. Default: not inert.

An inert overlay:

  • lets pointer input through to what is under it, whether that is another overlay or the window: a press or a hover over it is the press or the hover of the widget beneath, and a press there is outside every overlay it is outside of, so it still closes a click-outside popover;
  • is closed by Escape without consuming the key, if its dismiss is one Escape closes (EscapeKey, EscapeOrClickOutside, PointerLeave); whatever its dismiss, Manual included, the key goes on to what it would have reached with the overlay gone;
  • never records or restores focus: focus stays where it is when the overlay appears and when it goes;
  • does not close when focus leaves its anchor: the code that raised it decides when it goes.

For an overlay that only reports, such as a slider’s value readout. It is a property of the request, read once when the overlay is shown. The content root’s hit_transparent and event_pass_through keep their own meanings and play no part in it: an inert overlay needs neither, and setting both does not make an overlay inert.

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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