#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.content_id: WidgetIdThe root widget of the overlay content.
anchor: WidgetIdThe widget this overlay is anchored to.
placement: OverlayPlacementPositioning relative to the anchor.
dismiss: DismissBehaviorHow the overlay is dismissed.
layer: OverlayLayerRendering 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: boolThe overlay takes no input. Set with OverlayRequest::inert, which
says what that means.
Implementations§
Source§impl OverlayRequest
impl OverlayRequest
Sourcepub fn new(
content_id: WidgetId,
anchor: WidgetId,
placement: OverlayPlacement,
dismiss: DismissBehavior,
) -> Self
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:
layer:OverlayLayer::InTree.parent_overlay:None, a top-level overlay.on_dismiss:None.with_fade:None, so the overlay appears and goes without a fade.inert:false, an overlay that takes input.
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)));Sourcepub fn layer(self, layer: OverlayLayer) -> Self
pub fn layer(self, layer: OverlayLayer) -> Self
Render the overlay on layer. Default: OverlayLayer::InTree.
Sourcepub fn parent_overlay(self, parent: OverlayId) -> Self
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.
Sourcepub fn on_dismiss(self, callback: OverlayDismissCallback) -> Self
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.
Sourcepub fn with_fade(self, duration: Duration) -> Self
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.
Sourcepub fn inert(self) -> Self
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
dismissis one Escape closes (EscapeKey,EscapeOrClickOutside,PointerLeave); whatever itsdismiss,Manualincluded, 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.