Skip to main content

Overlay

Struct Overlay 

Source
pub struct Overlay {
    pub key: Option<KeyRef>,
    pub initial_entries: Vec<Ref<OverlayEntry>>,
    pub clip_behavior: Clip,
    pub always_size_to_content: bool,
}
Expand description

A stack of entries that can be managed independently.

Overlays let independent child widgets “float” visual elements on top of other widgets by inserting them into the overlay’s stack. The overlay lets each of these widgets manage their participation in the overlay using OverlayEntry objects.

Although you can create an Overlay directly, it’s most common to use the overlay created by the Navigator. The navigator uses its overlay to manage the visual appearance of its routes.

The Overlay widget uses a custom stack implementation, which is very similar to the Stack widget. The main use case of Overlay is related to navigation and being able to insert widgets on top of the pages in an app. For layout purposes unrelated to navigation, consider using Stack instead.

An Overlay widget requires a Directionality widget to be in scope, so that it can resolve direction-sensitive coordinates of any Positioned::directional children.

See also:

  • OverlayEntry, the class that is used for describing the overlay entries.
  • OverlayState, which is used to insert the entries into the overlay.

Fields§

§key: Option<KeyRef>§initial_entries: Vec<Ref<OverlayEntry>>

The entries to include in the overlay initially.

These entries are only used when the OverlayState is initialized. If you are providing a new Overlay description for an overlay that’s already in the tree, then the new entries are ignored.

To add entries to an Overlay that is already in the tree, use Overlay::of to obtain the OverlayState, and then use OverlayState::insert or OverlayState::insert_all.

To remove an entry from an Overlay, use OverlayEntry::remove.

§clip_behavior: Clip

How to clip the entries that overflow the overlay.

Defaults to Clip::HardEdge.

§always_size_to_content: bool

Determines that the overlay should always size itself to content.

Normally overlay will only size itself to content if the incoming constraints are infinite and there is an OverlayEntry that can size the overlay. Setting this to true will force this behavior even for finite (but possibly loose) constraints.

Setting this to true requires an OverlayEntry that can size the overlay based on itself (OverlayEntry::can_size_overlay set to true). If not provided the overlay panics.

Implementations§

Source§

impl Overlay

Source

pub fn new() -> Overlay

Creates an overlay; Dart’s named arguments are the setters.

The initial entries will be inserted into the overlay when its associated OverlayState is initialized.

Source

pub fn key(self, key: KeyRef) -> Overlay

Dart Overlay(key:).

Source

pub fn initial_entries( self, entries: impl IntoIterator<Item = Ref<OverlayEntry>>, ) -> Overlay

Dart Overlay(initialEntries:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> Overlay

Dart Overlay(clipBehavior:).

Source

pub fn always_size_to_content(self, always_size_to_content: bool) -> Overlay

Dart Overlay(alwaysSizeToContent:).

Source

pub fn wrap<K>(child: impl IntoWidget<K>) -> WrappingOverlay

Wrap the provided child in an Overlay to allow other visual elements (packed in OverlayEntrys) to float on top of the child.

This is a convenience method over the regular Overlay constructor: it creates an Overlay and puts the provided child in an OverlayEntry at the bottom of that newly created Overlay.

Source

pub fn of( app: &mut App, context: BuildContext, root_overlay: bool, ) -> Handle<OverlayState>

The OverlayState from the closest instance of Overlay that encloses the given context, and panics if one is not found.

If root_overlay is set to true, the state from the furthest instance of this class is given instead. Useful for installing overlay entries above all subsequent instances of Overlay.

See also:

Source

pub fn maybe_of( app: &mut App, context: BuildContext, root_overlay: bool, ) -> Option<Handle<OverlayState>>

The OverlayState from the closest instance of Overlay that encloses the given context, if any.

If root_overlay is set to true, the state from the furthest instance of this class is given instead.

See also:

Trait Implementations§

Source§

impl Debug for Overlay

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Overlay

Source§

fn default() -> Overlay

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

impl StatefulWidget for Overlay

Source§

type State = OverlayState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> OverlayState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Overlay

§

impl !Send for Overlay

§

impl !Sync for Overlay

§

impl !UnwindSafe for Overlay

§

impl Forget for Overlay

§

impl Freeze for Overlay
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<Retained<Handle<OverlayEntry>>>: Freeze,

§

impl Move for Overlay

§

impl Unpin for Overlay
where Rc<dyn Key>: Unpin, *const u8 is !null: Unpin, NonZero<u32>: Unpin, Rc<Keep>: Unpin,

§

impl UnsafeUnpin for Overlay

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

Source§

fn downcast(&self) -> &T

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<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

Source§

fn upcast(&self) -> Option<&T>