pub struct LayoutFn(pub Arc<dyn Fn(LayoutCtx<'_>) -> Vec<Rect> + Send + Sync>);Expand description
Second escape hatch: author-supplied layout function.
When set on a node via El::layout, the layout pass calls this
function instead of running the column/row/overlay distribution for
that node’s direct children. The function returns one Rect per
child (in source order), positioned anywhere inside the container.
The library still recurses into each child (so descendants lay out
normally) and still drives hit-test, focus, animation, scroll —
those all read from UiState’s computed-rect side map, which receives the
rects this function produces.
Authors typically write a free fn(LayoutCtx) -> Vec<Rect> and
pass it directly: column(children).layout(my_layout).
§What you get
LayoutCtx::container— the rect available for placement (parent rect minus this node’s padding).LayoutCtx::children— read-only slice of the node’s children; index here matches the index in your returnedVec<Rect>.LayoutCtx::measure— call to get a child’s intrinsic(width, height)if you need it for sizing decisions.
§Scope limits (will panic)
- The custom-layout node itself must size with
Size::FixedorSize::Fillon both axes.Size::Hugwould require a separate intrinsic callback and is not yet supported. - The returned
Vec<Rect>length must equalchildren.len().
Tuple Fields§
§0: Arc<dyn Fn(LayoutCtx<'_>) -> Vec<Rect> + Send + Sync>Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LayoutFn
impl !RefUnwindSafe for LayoutFn
impl Send for LayoutFn
impl Sync for LayoutFn
impl Unpin for LayoutFn
impl UnsafeUnpin for LayoutFn
impl !UnwindSafe for LayoutFn
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.