|
11 | 11 |
|
12 | 12 |
|
13 | 13 | class StreamLayout(Layout): |
| 14 | + """A cut down version of the vertical layout. |
| 15 | +
|
| 16 | + Faster, but with fewer supported "features". |
| 17 | +
|
| 18 | + """ |
| 19 | + |
14 | 20 | name = "stream" |
15 | 21 |
|
16 | 22 | def arrange( |
17 | 23 | self, parent: Widget, children: list[Widget], size: Size, greedy: bool = True |
18 | 24 | ) -> ArrangeResult: |
19 | 25 | parent.pre_layout(self) |
| 26 | + if not children: |
| 27 | + return [] |
20 | 28 | viewport = parent.app.size |
21 | 29 |
|
| 30 | + _Region = Region |
| 31 | + _WidgetPlacement = WidgetPlacement |
| 32 | + |
22 | 33 | placements: list[WidgetPlacement] = [] |
23 | | - if not children: |
24 | | - return [] |
25 | 34 | width = size.width |
26 | 35 | first_child_styles = children[0].styles |
27 | 36 | y = first_child_styles.margin.top |
28 | 37 | previous_margin = 0 |
29 | 38 | null_offset = NULL_OFFSET |
30 | 39 |
|
31 | 40 | for widget in children: |
32 | | - styles = widget.styles |
33 | | - overlay = styles.overlay == "screen" |
34 | | - absolute = styles.has_rule("position") and styles.position == "absolute" |
| 41 | + styles = widget.styles.base |
35 | 42 | margin = styles.margin |
| 43 | + gutter_width, gutter_height = styles.gutter.totals |
36 | 44 | top, right, bottom, left = margin |
37 | | - margin_width = left + right |
38 | 45 | y += max(top, previous_margin) |
39 | 46 | previous_margin = bottom |
40 | | - height = widget.get_content_height(size, viewport, width - margin_width) |
41 | | - height += styles.gutter.height |
| 47 | + height = ( |
| 48 | + widget.get_content_height(size, viewport, width - gutter_width) |
| 49 | + + gutter_height |
| 50 | + ) |
42 | 51 | if (max_height := styles.max_height) is not None and max_height.is_cells: |
43 | 52 | height = min(height, int(max_height.value)) |
44 | 53 | placements.append( |
45 | | - WidgetPlacement( |
46 | | - Region(left, y, width - margin_width, height), |
| 54 | + _WidgetPlacement( |
| 55 | + _Region(left, y, width - (left + right), height), |
47 | 56 | null_offset, |
48 | 57 | margin, |
49 | 58 | widget, |
50 | 59 | 0, |
51 | 60 | False, |
52 | | - overlay, |
53 | | - absolute, |
| 61 | + False, |
| 62 | + False, |
54 | 63 | ) |
55 | 64 | ) |
56 | 65 | y += height |
|
0 commit comments