Skip to main content

Stack

Struct Stack 

Source
pub struct Stack {
    pub key: Option<KeyRef>,
    pub alignment: AlignmentGeometry,
    pub text_direction: Option<TextDirection>,
    pub fit: StackFit,
    pub clip_behavior: Clip,
    pub children: Vec<WidgetRef>,
}
Expand description

A widget that positions its children relative to the edges of its box.

This class is useful if you want to overlap several children in a simple way, for example having some text and an image, overlaid with a gradient and a button attached to the bottom.

Each child of a Stack widget is either positioned or non-positioned. Positioned children are those wrapped in a Positioned widget that has at least one non-None property. The stack sizes itself to contain all the non-positioned children, which are positioned according to alignment (which defaults to the top-left corner in left-to-right environments and the top-right corner in right-to-left environments). The positioned children are then placed relative to the stack according to their top, right, bottom, and left properties.

The stack paints its children in order with the first child being at the bottom. If you want to change the order in which the children paint, you can rebuild the stack with the children in the new order. If you reorder the children in this way, consider giving the children non-None keys. These keys will cause the framework to move the underlying objects for the children to their new locations rather than recreate them at their new location.

For more details about the stack layout algorithm, see RenderStack.

See also:

Fields§

§key: Option<KeyRef>§alignment: AlignmentGeometry

How to align the non-positioned and partially-positioned children in the stack.

The non-positioned children are placed relative to each other such that the points determined by alignment are co-located. For example, if the alignment is AlignmentGeometry::TOP_LEFT, then the top left corner of each non-positioned child will be located at the same global coordinate.

Partially-positioned children, those that do not specify an alignment in a particular axis (e.g. that have neither top nor bottom set), use the alignment to determine how they should be positioned in that under-specified axis.

Defaults to AlignmentGeometry::TOP_START.

§text_direction: Option<TextDirection>

The text direction with which to resolve alignment.

Defaults to the ambient Directionality.

§fit: StackFit

How to size the non-positioned children in the stack.

The constraints passed into the Stack from its parent are either loosened (StackFit::Loose) or tightened to their biggest size (StackFit::Expand).

§clip_behavior: Clip

Stacks only clip children whose geometry overflows the stack. A child that paints outside its bounds (e.g. a box with a shadow) will not be clipped, regardless of the value of this property. Similarly, a child that itself has a descendant that overflows the stack will not be clipped, as only the geometry of the stack’s direct children are considered.

Even when this is set to Clip::None, the stack itself does not extend its hit-test region: pointer events that fall outside the stack’s own bounds will not reach a child even if that child is painted in that area.

Defaults to Clip::HardEdge.

§children: Vec<WidgetRef>

Implementations§

Source§

impl Stack

Source

pub fn new() -> Stack

Creates a Stack; Dart’s named arguments are the setters.

By default, the non-positioned children of the stack are aligned by their top left corners.

Source

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

Dart Stack(key:).

Source

pub fn alignment(self, alignment: AlignmentGeometry) -> Stack

Dart Stack(alignment:).

Source

pub fn text_direction(self, text_direction: TextDirection) -> Stack

Dart Stack(textDirection:).

Source

pub fn fit(self, fit: StackFit) -> Stack

Dart Stack(fit:).

Source

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

Dart Stack(clipBehavior:).

Source

pub fn children(self, children: impl IntoIterator<Item = WidgetRef>) -> Stack

Dart Stack(children:).

Trait Implementations§

Source§

impl Debug for Stack

Source§

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

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

impl Default for Stack

Source§

fn default() -> Stack

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

impl MultiChildRenderObjectWidget for Stack

Source§

fn children(&self) -> &[WidgetRef]

The widgets below this widget in the tree. Read more
Source§

fn create_element(&self, app: &mut App, this: WidgetRef) -> AnyElement
where Self: Sized,

Creates the element that manages this widget’s children. Read more
Source§

impl RenderObjectWidget for Stack

Source§

type RenderObject = RenderStack

The render object this widget creates; Dart’s covariant RenderObject parameter type.
Source§

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

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 create_render_object( &self, app: &mut App, context: BuildContext, ) -> AnyRenderObject

Creates an instance of the RenderObject class that this widget represents, using the configuration described by this widget. Read more
Source§

fn update_render_object( &self, app: &mut App, context: BuildContext, render_object: RenderHandle<RenderStack>, )

Copies the configuration described by this widget to the given render object, which will be of the same type as returned by this object’s create_render_object. Read more
Source§

fn to_string_short(&self) -> String

Dart’s toStringShort, for a widget that names itself apart from its type, as SizedBox.expand does; see Widget::to_string_short.
Source§

fn debug_check_constructor(&self)

Source§

fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )

Dart’s debugVisitOnstageChildren of the element this widget makes, for a widget whose Dart element subclass overrides it only to hide children (_OffstageElement, _IndexedStackElement): calls visitor for each of children, in order, that is onstage. Waft’s generic single- and multi-child elements stand in for those subclasses and ask their widget here; an element of a widget’s own overrides Element::debug_visit_onstage_children instead.
Source§

fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )

A render object previously associated with this widget has been removed from the tree. The given RenderObject will be of the same type as returned by this object’s create_render_object.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Stack

§

impl !Send for Stack

§

impl !Sync for Stack

§

impl !UnwindSafe for Stack

§

impl Forget for Stack

§

impl Freeze for Stack
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn Widget>>: Freeze,

§

impl Move for Stack

§

impl Unpin for Stack
where Rc<dyn Key>: Unpin, *const u8 is !null: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for Stack
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Rc<dyn Widget>>: UnsafeUnpin,

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<MultiChildRenderObjectKind> for W

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>