Expand description
Layout building blocks for WaterUI.
This crate bridges the declarative View system with
the imperative, backend-driven layout pass. It contains:
- the low-level
Layouttrait and its geometry helpers, - reusable containers such as
spacer(),padding::Padding, and stacks, - thin wrappers (for example
scroll()) that signal backend-specific behaviour.
§Logical Pixels (Points)
All layout values use logical pixels (points/dp) - the same unit as design tools like Figma, Sketch, and Adobe XD. Native backends handle conversion to physical pixels based on screen density:
- iOS/macOS: Uses points natively
- Android: Converts dp → pixels via
displayMetrics.density
This ensures spacing(8.0) or width(100.0) renders at the same physical
size across all platforms, matching your design specifications exactly.
§Example
use waterui::prelude::*;
pub fn toolbar() -> impl View {
hstack((
text("WaterUI"),
spacer(),
vstack((text("Docs"), text("Blog"))),
))
.spacing(8.0) // 8pt spacing - same as Figma/Sketch
}For a broader tour see the crate README.
Modules§
- absolute
- Absolute positioning layout for
WaterUI. - alignment_
guide - Alignment-guide wrapper views.
- aspect_
ratio - Constrains a view to a width-to-height ratio.
- background
- Background layout for rendering content behind a view.
- collection_
transition - Opt-in animation for reactive-collection membership changes.
- container
- View wrapper that lets arbitrary
Layoutimplementations participate in theWaterUIview tree. - divider
- Divider layout primitive shared across
WaterUIsurfaces. - frame
- Reactive frame constraints for overriding a child’s incoming proposal.
- grid
- A two-dimensional layout that arranges views in columns and rows.
- overlay
- Overlay helpers for layering content on top of a base view.
- padding
- Padding layouts that inset a child by fixed edge distances.
- safe_
area - Safe area handling for layout containers.
- scroll
- Scroll containers that defer behaviour to the active renderer backend.
- spacer
- Flexible layout gaps used by stacks and other containers.
- stack
- Stack-based layout primitives.
Structs§
- Absolute
- Container for absolutely positioned children.
- Absolute
Layout - Layout that fills parent and gives each child full bounds.
- Affine2
- 2D affine transform stored as a row-major 2x3 matrix.
- Alignment
- Combined two-dimensional alignment used by layout containers.
- Alignment
KeyId - Stable identifier for a built-in alignment guide in the layout runtime.
- Aspect
Ratio - A view constrained to a width-to-height ratio.
- Aspect
Ratio Layout - Layout that sizes its single child to a fixed width-to-height ratio.
- Background
Layout - Layout used by
BackgroundViewto render a background behind content. - Background
View - A view that renders a
backgroundbehind thecontent. - Collection
Transition - Environment request to animate reactive-collection membership changes.
- Divider
- A thin line that separates content.
- EdgeSet
- Specifies which edges should ignore safe area insets.
- Grid
- A view that arranges content in rows and columns.
- GridRow
- A data-carrying struct that represents a single row in a
Grid. It does not implementViewitself; it is consumed by theGrid. - Horizontal
Alignment - Horizontal alignment guide handle.
- Horizontal
Alignment Guide - A wrapper view that overrides one horizontal alignment guide.
- Ignore
Safe Area - Marker metadata indicating this view should ignore safe area insets.
- Layout
Priority - How strongly a view holds on to space when its container runs short.
- Lazy
Container - A view wrapper that executes an arbitrary
Layoutimplementation with reconstructable views, which can support lazy layouting. - Memoized
SubView - A
SubViewthat remembers what each proposal measured. - Overlay
- A view that layers
overlaycontent on top of abaseview without allowing the overlay to influence layout sizing. - Overlay
Layout - Layout used by
Overlayto keep the base child’s size authoritative while still allowing aligned overlay content. - PinConstraints
- Edge-based constraints for absolute positioning.
- Placed
Subview - A child view together with its placed frame inside a container.
- Point
- Absolute coordinate relative to a parent layout’s origin.
- Positioned
Child - A view with positioning information, for use in
Absolutecontainer. - Positioned
Layout - Layout that positions a single child within received bounds.
- Proposal
Size - A size proposal from parent to child during layout negotiation.
- Rect
- Axis-aligned rectangle relative to its parent.
- Safe
Area Insets - The window’s safe area, published by the platform backend.
- Scroll
Controller - Explicit programmatic control for a scrollable view.
- Scroll
View - A scrollable view that displays content larger than its frame.
- Size
- Two-dimensional size expressed in points.
- Spacer
- A flexible space that expands to push views apart.
- Unit
Point - Normalized coordinates (0.0–1.0) for positioning and gradient endpoints.
- Vec2
- Two-dimensional displacement vector (e.g. velocity, gravity, wind, offset).
- Vertical
Alignment - Vertical alignment guide handle.
- Vertical
Alignment Guide - A wrapper view that overrides one vertical alignment guide.
- View
Dimensions - Measured dimensions together with explicit alignment guides.
Enums§
- Content
Mode - How a view fills a ratio-constrained box.
- Layout
Direction - The logical horizontal direction used by layout containers.
- Position
Target - Target position for absolute positioning.
- Stretch
Axis - Specifies which axis (or axes) a view wants to stretch to fill available space.
Constants§
- MEMOIZED_
PROPOSALS - How many distinct proposals one child’s memo retains.
Traits§
- Layout
- A layout algorithm for arranging child views.
- Position
Ext - Extension trait for absolute positioning of views.
- SubView
- A proxy for querying child view sizes during layout.
Functions§
- absolute
- Creates an
Absolutecontainer for positioning children. - aspect_
ratio - Constrains
contenttoratio, shrinking to fit inside what is offered. - background
- Convenience constructor for creating a
BackgroundView. - collection_
transition - Wraps
contentso every reactive collection within it animates membership changes withanimation(seeCollectionTransition). - grid
- Creates a new grid with the specified number of columns and rows.
- layout_
direction - Resolves the reactive layout direction installed in an environment.
- measure_
layout - Measures a layout and resolves its explicit guides for the given children.
- overlay
- Convenience constructor for creating an
Overlaywith the default alignment. - row
- Creates a new grid row containing the specified views.
- scroll
- Creates a vertical
ScrollViewwith the given content. - scroll_
both - Creates a
ScrollViewthat can scroll in both directions. - scroll_
horizontal - Creates a horizontal
ScrollViewwith the given content. - spacer
- Creates a flexible spacer with zero minimum length.
- spacer_
min - Creates a spacer with a specific minimum length.
- with_
memoized_ children - Runs
passwith every child wrapped in aMemoizedSubView, so repeated probes within that one layout pass measure each child at most once per distinct proposal.