waterui_layout/lib.rs
1#![no_std]
2#![cfg_attr(
3 test,
4 allow(
5 clippy::float_cmp,
6 reason = "tests assert exact layout geometry values"
7 )
8)]
9//! Layout building blocks for `WaterUI`.
10//!
11//! This crate bridges the declarative [`View`](waterui_core::View) system with
12//! the imperative, backend-driven layout pass. It contains:
13//!
14//! - the low-level [`Layout`] trait and its geometry helpers,
15//! - reusable containers such as [`spacer()`], [`padding::Padding`], and stacks,
16//! - thin wrappers (for example [`scroll()`]) that signal backend-specific
17//! behaviour.
18//!
19//! # Logical Pixels (Points)
20//!
21//! All layout values use **logical pixels** (points/dp) - the same unit as design
22//! tools like Figma, Sketch, and Adobe XD. Native backends handle conversion to
23//! physical pixels based on screen density:
24//!
25//! - iOS/macOS: Uses points natively
26//! - Android: Converts dp → pixels via `displayMetrics.density`
27//!
28//! This ensures `spacing(8.0)` or `width(100.0)` renders at the same physical
29//! size across all platforms, matching your design specifications exactly.
30//!
31//! # Example
32//!
33//! ```rust
34//! use waterui::prelude::*;
35//!
36//! pub fn toolbar() -> impl View {
37//! hstack((
38//! text("WaterUI"),
39//! spacer(),
40//! vstack((text("Docs"), text("Blog"))),
41//! ))
42//! .spacing(8.0) // 8pt spacing - same as Figma/Sketch
43//! }
44//! ```
45//!
46//! For a broader tour see the crate README.
47
48extern crate alloc;
49
50pub use waterui_core::layout::*;
51
52mod collections;
53mod containers;
54mod modifiers;
55
56pub use collections::{grid, scroll};
57pub use containers::{
58 absolute, aspect_ratio, collection_transition, container, divider, frame, spacer,
59};
60pub use modifiers::{alignment_guide, background, overlay, padding, safe_area};
61
62pub use divider::Divider;
63pub use spacer::{Spacer, spacer, spacer_min};
64pub mod stack;
65
66pub use grid::{Grid, GridRow, grid, row};
67pub use scroll::{ScrollController, ScrollView, scroll, scroll_both, scroll_horizontal};
68
69pub use alignment_guide::{HorizontalAlignmentGuide, VerticalAlignmentGuide};
70pub use aspect_ratio::{AspectRatio, AspectRatioLayout, ContentMode, aspect_ratio};
71pub use collection_transition::{CollectionTransition, collection_transition};
72pub use container::LazyContainer;
73
74pub use background::{BackgroundLayout, BackgroundView, background};
75pub use overlay::{Overlay, OverlayLayout, overlay};
76pub use safe_area::{EdgeSet, IgnoreSafeArea, SafeAreaInsets};
77
78pub use absolute::{
79 Absolute, AbsoluteLayout, PinConstraints, PositionExt, PositionTarget, PositionedChild,
80 PositionedLayout, absolute,
81};
82
83#[cfg(test)]
84mod tests;