Skip to main content

Layout

Struct Layout 

Source
pub(crate) struct Layout<W> {
    tree: TaffyTree<Size<f32>>,
    widgets: HashMap<NodeId, W>,
    surfaces: HashSet<NodeId>,
    scrolls: HashMap<NodeId, W>,
    overlays: HashSet<NodeId>,
}
Expand description

One tree for every window: each window’s content hangs off its own root node. A node’s context is its natural size, present only on widget leaves.

Fields§

§tree: TaffyTree<Size<f32>>§widgets: HashMap<NodeId, W>§surfaces: HashSet<NodeId>

Stacks whose widget is the surface drawn behind their children.

§scrolls: HashMap<NodeId, W>

Stacks that scroll, and the scroll area that shows each one’s children.

§overlays: HashSet<NodeId>

Widgets that cover their stack’s content, outside its layout.

Implementations§

Source§

impl<W> Layout<W>

Source

pub(crate) fn new() -> Self

Source

pub(crate) fn add_root(&mut self) -> NodeId

Source

pub(crate) fn add_widget(&mut self, widget: W, natural: Size) -> NodeId

Source

pub(crate) fn add_divider(&mut self, widget: W, natural: Size) -> NodeId

A divider stretches across its parent’s cross axis and stays one point thick.

Source

pub(crate) fn add_overlay(&mut self, widget: W, natural: Size) -> NodeId

A widget that covers its whole stack, padding included, and takes no part in how the stack lays out its other children: Taffy skips it, and place gives it the stack’s content frame.

Source

pub(crate) fn add_spacer(&mut self) -> NodeId

Empty space that takes whatever room its stack has left.

Source

pub(crate) fn add_stack( &mut self, style: &StackStyle, surface: Option<W>, ) -> NodeId

A stack, with the surface widget drawn behind its children if it has one. Stacks size from their children, so a surface needs no natural size.

Source

pub(crate) fn add_scroll( &mut self, style: &StackStyle, surface: Option<W>, scroll: W, bar_width: f32, ) -> NodeId

A stack shown in scroll, whose children scroll up and down when they are taller than it, with its scroll bar taking bar_width beside them. It takes the space its parent has left, and adds nothing to its parent’s size, so a parent sized by its content leaves it none.

Source

pub(crate) fn set_scroll_bar_width(&mut self, root: NodeId, width: f32)

Leaves width beside the content of every scroll area in the tree under root, for its scroll bar.

Source

pub(crate) fn scroll_around(&self, node: NodeId) -> Option<&W>

The scroll area whose content node is in, counting a scroll’s own children as in it, or None when it is straight in the window.

Source

fn add_leaf(&mut self, widget: W, natural: Size, style: Style) -> NodeId

Source

pub(crate) fn insert(&mut self, parent: NodeId, index: usize, child: NodeId)

Source

pub(crate) fn set_content( &mut self, root: NodeId, content: NodeId, ) -> Option<NodeId>

Makes content fill the window whose root is root, returning the content it replaces, which is now detached and still holds its widgets.

Source

pub(crate) fn remove(&mut self, node: NodeId) -> Vec<W>

Removes node and everything under it, handing back their widgets.

Source

fn remove_into(&mut self, node: NodeId, removed: &mut Vec<W>)

Source

pub(crate) fn widget(&self, node: NodeId) -> Option<&W>

Source

pub(crate) fn set_natural(&mut self, node: NodeId, natural: Size) -> bool

Records a widget’s new natural size; returns whether layout is now out of date.

Source

pub(crate) fn min_width(&mut self, root: NodeId, title_bar_inset: f32) -> f32

The narrowest the window rooted at root can be without clipping its content.

Source

pub(crate) fn layout_window( &mut self, root: NodeId, viewport: Size, title_bar_inset: f32, apply: impl FnMut(Placed<'_, W>), )

Lays out the window rooted at root and reports where each widget goes. Content starts below the title bar; a surface whose top touches it reaches up under the title bar, while its children stay below.

Source

fn place( &self, node: NodeId, parent_origin: Point, title_bar_inset: Option<f32>, apply: &mut impl FnMut(Placed<'_, W>), )

Native widgets are flat children of the window or of a scroll area’s content, so frames are made relative to those here. Inside a scroll area there is no title bar to reach under.

Auto Trait Implementations§

§

impl<W> !Send for Layout<W>

§

impl<W> !Sync for Layout<W>

§

impl<W> Freeze for Layout<W>

§

impl<W> RefUnwindSafe for Layout<W>
where W: RefUnwindSafe,

§

impl<W> Unpin for Layout<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for Layout<W>

§

impl<W> UnwindSafe for Layout<W>
where W: UnwindSafe,

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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.