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>
impl<W> Layout<W>
pub(crate) fn new() -> Self
pub(crate) fn add_root(&mut self) -> NodeId
pub(crate) fn add_widget(&mut self, widget: W, natural: Size) -> NodeId
Sourcepub(crate) fn add_divider(&mut self, widget: W, natural: Size) -> NodeId
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.
Sourcepub(crate) fn add_overlay(&mut self, widget: W, natural: Size) -> NodeId
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.
Sourcepub(crate) fn add_spacer(&mut self) -> NodeId
pub(crate) fn add_spacer(&mut self) -> NodeId
Empty space that takes whatever room its stack has left.
Sourcepub(crate) fn add_stack(
&mut self,
style: &StackStyle,
surface: Option<W>,
) -> NodeId
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.
Sourcepub(crate) fn add_scroll(
&mut self,
style: &StackStyle,
surface: Option<W>,
scroll: W,
bar_width: f32,
) -> NodeId
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.
Sourcepub(crate) fn set_scroll_bar_width(&mut self, root: NodeId, width: f32)
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.
Sourcepub(crate) fn scroll_around(&self, node: NodeId) -> Option<&W>
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.
fn add_leaf(&mut self, widget: W, natural: Size, style: Style) -> NodeId
pub(crate) fn insert(&mut self, parent: NodeId, index: usize, child: NodeId)
Sourcepub(crate) fn set_content(
&mut self,
root: NodeId,
content: NodeId,
) -> Option<NodeId>
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.
Sourcepub(crate) fn remove(&mut self, node: NodeId) -> Vec<W>
pub(crate) fn remove(&mut self, node: NodeId) -> Vec<W>
Removes node and everything under it, handing back their widgets.
fn remove_into(&mut self, node: NodeId, removed: &mut Vec<W>)
pub(crate) fn widget(&self, node: NodeId) -> Option<&W>
Sourcepub(crate) fn set_natural(&mut self, node: NodeId, natural: Size) -> bool
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.
Sourcepub(crate) fn min_width(&mut self, root: NodeId, title_bar_inset: f32) -> f32
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.
Sourcepub(crate) fn layout_window(
&mut self,
root: NodeId,
viewport: Size,
title_bar_inset: f32,
apply: impl FnMut(Placed<'_, W>),
)
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.
Sourcefn place(
&self,
node: NodeId,
parent_origin: Point,
title_bar_inset: Option<f32>,
apply: &mut impl FnMut(Placed<'_, W>),
)
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.