/src/yoga/yoga/algorithm/Align.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/Yoga.h> |
11 | | |
12 | | #include <yoga/algorithm/FlexDirection.h> |
13 | | #include <yoga/node/Node.h> |
14 | | |
15 | | namespace facebook::yoga { |
16 | | |
17 | | inline Align resolveChildAlignment( |
18 | | const yoga::Node* node, |
19 | 33.0M | const yoga::Node* child) { |
20 | 33.0M | const Align align = child->style().alignSelf() == Align::Auto |
21 | 33.0M | ? node->style().alignItems() |
22 | 33.0M | : child->style().alignSelf(); |
23 | 33.0M | if (align == Align::Baseline && isColumn(node->style().flexDirection())) { |
24 | 0 | return Align::FlexStart; |
25 | 0 | } |
26 | 33.0M | return align; |
27 | 33.0M | } |
28 | | |
29 | | /** |
30 | | * Fallback alignment to use on overflow |
31 | | * https://www.w3.org/TR/css-align-3/#distribution-values |
32 | | */ |
33 | 0 | constexpr Align fallbackAlignment(Align align) { |
34 | 0 | switch (align) { |
35 | | // Fallback to flex-start |
36 | 0 | case Align::SpaceBetween: |
37 | 0 | case Align::Stretch: |
38 | 0 | return Align::FlexStart; |
39 | | |
40 | | // Fallback to safe center. TODO (T208209388): This should be aligned to |
41 | | // Start instead of FlexStart (for row-reverse containers) |
42 | 0 | case Align::SpaceAround: |
43 | 0 | case Align::SpaceEvenly: |
44 | 0 | return Align::FlexStart; |
45 | 0 | default: |
46 | 0 | return align; |
47 | 0 | } |
48 | 0 | } |
49 | | |
50 | | /** |
51 | | * Fallback alignment to use on overflow |
52 | | * https://www.w3.org/TR/css-align-3/#distribution-values |
53 | | */ |
54 | 359k | constexpr Justify fallbackAlignment(Justify align) { |
55 | 359k | switch (align) { |
56 | | // Fallback to flex-start |
57 | 0 | case Justify::SpaceBetween: |
58 | | // TODO: Support `justify-content: stretch` |
59 | | // case Justify::Stretch: |
60 | 0 | return Justify::FlexStart; |
61 | | |
62 | | // Fallback to safe center. TODO (T208209388): This should be aligned to |
63 | | // Start instead of FlexStart (for row-reverse containers) |
64 | 0 | case Justify::SpaceAround: |
65 | 0 | case Justify::SpaceEvenly: |
66 | 0 | return Justify::FlexStart; |
67 | 359k | default: |
68 | 359k | return align; |
69 | 359k | } |
70 | 359k | } |
71 | | |
72 | | } // namespace facebook::yoga |