blob: 3bbfdac3e90638319a7ae7b8f01ca02b8525bc4d (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# Layout Specifications
## overview
This document is the specification of layout system.
The layout system imitates WPF and Android layout system.
## rules
### about `width` and `height` in `LayoutParams`
There is three mode in measure: `Content`, `Exactly`, `Stretch`.
- `Exactly` means the control should be of an exact size.
- `Content` means the control has the size that contains the children.
- `Stretch` means the control stretch to the max size that it can fill. If parent is `Content`, it occupies all available room parent provides, which means its parent will stretch as well.
### about `max_size`, `min_size`
`max_size` specifies the max size and `min_size` specifies the min size. They are of higher priority of `width` and `height`. Calculated size should be adjusted according to the four properties.
## structure
### enum `MeasureMode`
``` c++
enum class MeasureMode
{
Content,
Stretch,
Exactly
};
```
### struct `MeasureLength`
``` c++
struct MeaureLength
{
float length;
MeasureMode mode;
};
```
### struct `MeaureSize`
``` c++
struct MeasureSize
{
MeasureLength width;
MeasureLength height;
};
```
### struct `OptionalSize`
``` c++
struct OptionalSize
{
optional<float> width;
optional<float> height;
}
```
### struct `BasicLayoutParams`
``` c++
struct BasicLayoutParams
{
MeasureSize size;
OptionalSize max_size;
OptionalSize min_size;
}
```
### interface `ILayoutable`
``` c++
struct ILayoutable : virtual Interface
{
virtual void Measure(const Size&) = 0;
virtual void Layout(const Rect&) = 0;
virtual BasicLayoutParams* GetLayoutParams() = 0;
virtual void SetLayoutParams(BasicLayoutParams* params) = 0;
virtual Size GetDesiredSize() = 0;
virtual void SetDesiredSize(const Size& size) = 0;
/*
protected:
virtual Size OnMeasure(const Size& size);
virtual void OnLayout(const Rect& rect);
*/
};
```
## process
|