Skip to main content

LayoutEngine

Struct LayoutEngine 

Source
pub struct LayoutEngine { /* private fields */ }

Implementations§

Source§

impl LayoutEngine

Source

pub fn new() -> Self

Source

pub fn direction(&self) -> Direction

The direction logical edges currently resolve against.

Source

pub fn set_direction(&mut self, direction: Direction) -> bool

Re-resolves every direction-dependent node against direction, returning whether anything changed. The caller still has to mark the tree dirty and recompute — this only rewrites styles.

This is what lets one build serve both directions: rather than rebuilding the widget tree, each node that was authored logically is resolved again from the intent recorded when it was created.

Source

pub fn new_leaf(&mut self, style: LayoutStyle) -> Result<NodeId, LayoutError>

Source

pub fn new_measured_leaf( &mut self, style: LayoutStyle, measure: MeasureFn, ) -> Result<NodeId, LayoutError>

Source

pub fn new_container( &mut self, style: LayoutStyle, children: &[NodeId], ) -> Result<NodeId, LayoutError>

Source

pub fn set_style( &mut self, node: NodeId, style: LayoutStyle, ) -> Result<(), LayoutError>

Source

pub fn set_children( &mut self, parent: NodeId, children: &[NodeId], ) -> Result<(), LayoutError>

Replaces parent’s children with children, in order. Used by reactive lists to insert, move, and drop item nodes as their source collection changes.

Source

pub fn add_child( &mut self, parent: NodeId, child: NodeId, ) -> Result<(), LayoutError>

Appends child to parent’s existing children (unlike [set_children], which replaces them). Used to attach an overlay’s out-of-flow content to the layout root without touching the root’s other children.

Source

pub fn remove_child( &mut self, parent: NodeId, child: NodeId, ) -> Result<(), LayoutError>

Detaches child from parent (does not free it — call [remove] afterwards to release the node).

Source

pub fn remove(&mut self, node: NodeId)

Frees a node (and its measure context) from the tree. The caller must have already detached it from its parent (via [set_children]); a removed node id must not be used again.

Source

pub fn mark_dirty(&mut self, node: NodeId) -> Result<(), LayoutError>

Source

pub fn is_size_auto(&self, node: NodeId) -> (bool, bool)

Whether the node’s width/height are auto (i.e. content-sized).

Source

pub fn set_width(&mut self, node: NodeId, width: Option<f32>)

Sets the node’s width to a definite length, or back to auto when None.

Source

pub fn set_height(&mut self, node: NodeId, height: Option<f32>)

Sets the node’s height to a definite length, or back to auto when None.

Source

pub fn set_min_height(&mut self, node: NodeId, height: Option<f32>)

Sets the node’s minimum height to a definite length, or clears it (auto) when None. Lets a content-measured leaf (e.g. a code editor’s text area) fill a viewport it would otherwise underflow.

Source

pub fn is_row(&self, node: NodeId) -> bool

Whether the node lays its children along the main (horizontal) axis — a flex row. A column, or any non-row node (missing / errored), is false. A transparent fragment reads its host’s axis to know which margin edge a per-item gap sits on.

Source

pub fn set_leading_margin(&mut self, node: NodeId, is_row: bool, px: f32)

Sets the node’s leading margin on the host’s main axis (top for a column; for a row, whichever horizontal edge the host lays out from) to px, leaving the other edges untouched. A transparent for … gap:N uses this to space its items by a gap without a container of its own: the item cell carries the gap as a margin instead.

Source

pub fn set_display(&mut self, node: NodeId, visible: bool)

Toggles a node in or out of layout flow. A hidden node (Display::None) takes no space and lays out none of its subtree; a visible node is Display::Flex. Used for responsive show/hide (e.g. collapsing a sidebar on narrow windows).

Source

pub fn compute_layout( &mut self, root: NodeId, available_width: AvailableSpace, available_height: AvailableSpace, ) -> Result<(), LayoutError>

Source

pub fn is_dirty(&self, node: NodeId) -> bool

Source

pub fn layout(&self, node: NodeId) -> Result<Rect, LayoutError>

Source

pub fn is_fixed_size(&self, node: NodeId) -> Option<(f32, f32)>

Source

pub fn collect_dirty_nodes(&self, root: NodeId, out: &mut Vec<NodeId>)

Source

pub fn walk<F>(&self, root: NodeId, f: &mut F) -> Result<(), LayoutError>
where F: FnMut(NodeId, Rect) -> bool,

Trait Implementations§

Source§

impl Default for LayoutEngine

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.