Expand description
Cascada is a lightweight, high-performance layout engine for UI frameworks.
It is designed for developers building UI libraries, such as GUIs or TUI’s, who want a fast, predictable layout system without the complexity of implementing their own.
§Usage
The core of this library is the Layout trait, which is implemented for different
use cases. There are currently four types of layout nodes:
EmptyLayout: A layout node with no children.BlockLayout: A layout node with one child.HorizontalLayout: A layout node that arranges its children horizontally.VerticalLayout: A layout node that arranges its children vertically.
Create a root layout node and pass it into the solve_layout function with the total
available space.
use cascada::{HorizontalLayout, EmptyLayout, solve_layout, IntrinsicSize, Size, Layout};
// Add three equally sized nodes.
let child = EmptyLayout::new()
.intrinsic_size(IntrinsicSize::fill());
let mut layout = HorizontalLayout::new()
.intrinsic_size(IntrinsicSize::fill())
.add_children([
child.clone(),
child.clone(),
child,
]);
solve_layout(&mut layout,Size::unit(3000.0));
let size = &layout.children()[0].size();
assert_eq!(size.width,1000.0);To get the size and position of the layout nodes you can iterate over the tree.
use cascada::{HorizontalLayout, EmptyLayout, solve_layout, IntrinsicSize, Size, Layout};
let child = EmptyLayout::new()
.intrinsic_size(IntrinsicSize::fill());
let mut layout = HorizontalLayout::new()
.intrinsic_size(IntrinsicSize::fill())
.add_children([
child.clone(),
child.clone(),
child,
]);
solve_layout(&mut layout,Size::unit(3000.0));
for node in layout.iter(){
println!("Size: {:?}",node.size());
println!("Position: {:?}",node.position());
}Or you could use ids to get specific nodes from the tree.
use cascada::{HorizontalLayout, EmptyLayout, solve_layout, IntrinsicSize, Size, Layout, GlobalId};
let id = GlobalId::new();
let child = EmptyLayout::new()
.set_id(id)
.intrinsic_size(IntrinsicSize::fixed(20.0,50.0));
let mut layout = HorizontalLayout::new()
.intrinsic_size(IntrinsicSize::fill())
.add_children([
child.clone(),
child.clone(),
child,
]);
solve_layout(&mut layout,Size::unit(3000.0));
let child = layout.get(id).unwrap();
assert_eq!(child.size().width,20.0);See the layout module documentation for more details.
§Features flags
debug-tools: Enables thedebug_treemethod.
Re-exports§
pub use layout::*;
Modules§
- debug
- ffi
- Experimental ffi.
- layout
- The layout engine uses
IntrinsicSizeandBoxConstraintsto calculate the final size and position of the layout nodes. The core idea of the layout engine is that there are only three different sizes that aLayoutnode will want to be:
Structs§
- Bounds
- The bounds of any object that has a
SizeandPosition. - BoxConstraints
- Describes the maximum and minimum size of a layout node.
- Global
Id - A global unique identifier.
- Intrinsic
Size - This is the preferred size of a [
Layout] node. - Padding
- The space between the edges of a
Layoutnode and its content. - Position
- The x and y position of a layout node.
- Size
- The width and height of a layout node.
Enums§
- Axis
Alignment - Describes how a
Layoutshould align its children. - BoxSizing
- Describes the size a [
Layout] will try to be. - Layout
Error