/src/yoga/yoga/algorithm/SizingMode.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <yoga/debug/AssertFatal.h> |
11 | | #include <yoga/enums/MeasureMode.h> |
12 | | |
13 | | namespace facebook::yoga { |
14 | | |
15 | | /** |
16 | | * Corresponds to a CSS auto box sizes. Missing "min-content", as Yoga does not |
17 | | * current support automatic minimum sizes. |
18 | | * https://www.w3.org/TR/css-sizing-3/#auto-box-sizes |
19 | | * https://www.w3.org/TR/css-flexbox-1/#min-size-auto |
20 | | */ |
21 | | enum class SizingMode { |
22 | | /** |
23 | | * The size a box would take if its outer size filled the available space in |
24 | | * the given axis; in other words, the stretch fit into the available space, |
25 | | * if that is definite. Undefined if the available space is indefinite. |
26 | | */ |
27 | | StretchFit, |
28 | | |
29 | | /** |
30 | | * A box’s “ideal” size in a given axis when given infinite available space. |
31 | | * Usually this is the smallest size the box could take in that axis while |
32 | | * still fitting around its contents, i.e. minimizing unfilled space while |
33 | | * avoiding overflow. |
34 | | */ |
35 | | MaxContent, |
36 | | |
37 | | /** |
38 | | * If the available space in a given axis is definite, equal to |
39 | | * clamp(min-content size, stretch-fit size, max-content size) (i.e. |
40 | | * max(min-content size, min(max-content size, stretch-fit size))). When |
41 | | * sizing under a min-content constraint, equal to the min-content size. |
42 | | * Otherwise, equal to the max-content size in that axis. |
43 | | */ |
44 | | FitContent, |
45 | | }; |
46 | | |
47 | 0 | inline MeasureMode measureMode(SizingMode mode) { |
48 | 0 | switch (mode) { |
49 | 0 | case SizingMode::StretchFit: |
50 | 0 | return MeasureMode::Exactly; |
51 | 0 | case SizingMode::MaxContent: |
52 | 0 | return MeasureMode::Undefined; |
53 | 0 | case SizingMode::FitContent: |
54 | 0 | return MeasureMode::AtMost; |
55 | 0 | default: |
56 | 0 | fatalWithMessage("Invalid SizingMode"); |
57 | 0 | } |
58 | 0 | } |
59 | | |
60 | 0 | inline SizingMode sizingMode(MeasureMode mode) { |
61 | 0 | switch (mode) { |
62 | 0 | case MeasureMode::Exactly: |
63 | 0 | return SizingMode::StretchFit; |
64 | 0 | case MeasureMode::Undefined: |
65 | 0 | return SizingMode::MaxContent; |
66 | 0 | case MeasureMode::AtMost: |
67 | 0 | return SizingMode::FitContent; |
68 | 0 | default: |
69 | 0 | fatalWithMessage("Invalid MeasureMode"); |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | } // namespace facebook::yoga |