vizia_core/layout/mod.rs
1//! Vizia uses [morphorm](https://github.com/vizia/morphorm) for layout.
2//!
3//! # Stacks
4//! By default, vizia will position the children of a view one after another into a vertical column called a stack.
5//! The [`layout_type()`](crate::modifiers::LayoutModifiers::layout_type) modifier (or `layout-type` css property) is used to determine how a container positions its children,
6//! and can be used to select between a vertical `Column`, horizontal `Row`, or `Grid`.
7//!
8//! The [`position()`](crate::modifiers::LayoutModifiers::position) modifier (or `position-type` css property) is used to determine whether a child view respects the
9//! stack position determined by the parent (`parent-directed`), or whether to position itself relative to the top-left of its parent
10//! and ignore its siblings (`self-directed`).
11//!
12//! # Space
13//! The position of views is modified by adding space to the sides of a view. Space can be added to the `left`, `right`, `top`, and `bottom`
14//! of a view, or to all sides simultaneously with the `space` modifier/ css property.
15//!
16//! Spacing is specified in [`Units`], which has four variants:
17//! - [`Pixels`](Units::Pixels) - Specifies the space as a fixed number of logical pixels. This value is scaled with the scale factor of the window.
18//! - `Percentage` - Specifies the space as a percentage of the parent size in the same axis, so parent width for `left` and `right` space
19//! and parent height for `top` and `bottom` space.
20//! - `Stretch` - Specifies the space as a ratio of the remaining free space of the parent. This is best understood with an example.
21//! Let's say the parent is 400px wide and the child is 200px wide. The `left` and `right` space of the child are both set to `Stretch(1.0)`.
22//! This means that the ratio for each is 1/2, because each has stretch 1.0 and the total stretch factor in that axis is 2.0 (1.0 + 1.0).
23//! The remaining free space is the parent width minus any fixed space and size of the child, in this case the child width, so 400.0 - 200.0 = 200.0.
24//! Now the computed space for the `left` and `right` sides is 1/2 of the remaining free space, so 200.0 / 2.0 = 100.0.
25//! If the `left` space had been `Stretch(3.0)`, the ratio would have been 3/4 for `left` and 1/4 for `right` and the computed space would have
26//! been `150.0` for `left` and `50.0` for right.
27//! - `Auto` - The spacing is determined by the corresponding `child_space` of the parent. So `left` would be determined by the parent `padding_left` etc.
28//!
29//! # Child Space
30pub(crate) mod cache;
31pub(crate) mod node;
32
33pub use morphorm::{LayoutType, PositionType, Units};
34
35/// Represents an axis-aligned bounding box.
36pub mod bounds;
37
38pub use bounds::*;
39
40pub use cache::GeoChanged;