ltk/layout/mod.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>
//! Layouts — composable arrangers for [`Element`](crate::Element) trees.
//!
//! Layouts decide *where* their children sit; they don't paint anything of
//! their own. Each layout exposes a free constructor (`column()`, `row()`,
//! `stack()`, `grid(N)`, `spacer()`) and a builder-style API for spacing,
//! padding, alignment and sizing. Layouts and [widgets](crate::widget)
//! share the same [`Element<Msg>`](crate::Element) tree — anything that
//! converts into an `Element` can be pushed into any layout.
//!
//! ## What's available
//!
//! * **Flow** — [`column::Column`] (top-to-bottom),
//! [`row::Row`] (left-to-right). Both honour `padding`, `spacing`,
//! `max_width`, `align_center_*` and inline `Spacer` distribution.
//! * **Overlay** — [`stack::Stack`] for FrameLayout-style layering with
//! per-child [`HAlign`](stack::HAlign) / [`VAlign`](stack::VAlign) and
//! margin / pixel-translation overrides. Useful for foreground HUD on
//! top of a background image, or a floating action button anchored to
//! the bottom-right.
//! * **Grid** — [`wrap_grid::WrapGrid`] for fixed-column-count grids that
//! wrap their children into rows (icon launchers, photo galleries).
//! * **Filler** — [`spacer::Spacer`], an invisible child that absorbs
//! leftover space along the parent's main axis. Pair with
//! [`flex::Flex`](crate::Flex) when the filler is non-trivial (a card
//! that should stretch a row).
//!
//! Most layouts default to "fill the parent's available rect" and only
//! shrink to their content with `fit_content()`.
//!
//! ## Sizing model
//!
//! Layouts implement `preferred_size( max_width, &Canvas ) -> ( w, h )`
//! the same way widgets do. The convention is: the layout claims the
//! parent-supplied `max_width` (or the explicit `max_width(...)` setting)
//! and reports the height needed for its children. Spacers and
//! `Scroll`/`Flex` declare zero intrinsic main-axis size and absorb the
//! leftover space the parent has after fixed-size siblings have been laid
//! out.
pub mod column;
pub mod row;
pub mod spacer;
pub mod stack;
pub mod wrap_grid;