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
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::;
use ;
/// A self-layouting block-level component.
///
/// `BlockLayouter` allows custom types to be embedded in a layout
/// tree as block-level children via
/// [`LayoutChild::Custom`](crate::LayoutChild::Custom).
///
/// # Block layout
///
/// In a block formatting context, the engine positions the component
/// as a block child (stacked vertically). The component returns its
/// border-box [`Rect`] via [`layout`](Self::layout).
///
/// # Flex layout
///
/// In a flex formatting context, the engine uses the [`Rect`] returned
/// by [`layout`](Self::layout) to determine the component's main-axis
/// and cross-axis size.
///
/// # Examples
///
/// ```rust
/// use ui_layout::*;
///
/// #[derive(Debug)]
/// struct MyPanel {
/// width: f32,
/// height: f32,
/// }
///
/// impl BlockLayouter for MyPanel {
/// fn layout(&mut self, _ctx: &LayoutContext) -> Rect {
/// Rect { x: 0.0, y: 0.0, width: self.width, height: self.height }
/// }
/// }
///
/// let panel: Box<dyn BlockLayouter> = Box::new(MyPanel { width: 200.0, height: 100.0 });
/// let root = LayoutNode::with_children(
/// Style::default(),
/// [LayoutChild::Custom(panel)],
/// );
/// ```