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
|
# Saffron layout system
> Note: at this moment, these docs exist solely for me, the maintainer, to place down ideas and to help with the massive task of architecting a UI framework and layout engine. This message will be removed when these docs are ready.
## Size requests
A widget's width and height are not commands to the layout engine. They are simply requests. The layout engine will attempt to give each widget its required size, but if the window is too small, the sizes will be reduced. Widgets must be ready to handle rendering at any size.
### Size requests based on size modes
- `SAFFRON_SIZE_FIXED`: The widget will take only the required space on this axis, but will take less if needed.
- `SAFFRON_SIZE_STRETCH`: The widget has a minimum required size on this axis, and will take as much extra space as possible. Can take less if needed.
- `SAFFRON_SIZE_SCALE`: The widget will fill the available space while preserving its aspect ratio, even if it sacrifices the requested size.
## Layout pass
1. Calculate inner area
2. Position children sequentially (including child boxes), horizontally or vertically
3. Recurse into child boxes
Children are positioned before recursion. This ensures that child boxes have already been positioned and have set bounds before attempting to layout their children, keeping layouts responsive.
## pixel_perfect
If a widget has the attribute `pixel_perfect` set to `true`, it is excluded from layouting and must manage its own position and size. The layout engine will literally skip these widgets with a simple condition.
## Spacing
Spacing is added between children, not before the first or after the last.
## Overflow
Children never overflow outside the inner area (unless they have `pixel_perfect` set to `true`, because they are excluded from layouting). If total requested size exceeds available space, the layout engine will reduce children in size to make space. As mentioned above, widgets must be ready to handle any size, whether it is ridiculously small or ridiculously large.
TODO for future: add scroll containers, in that case only they can overflow for scrolling
|