MCPcopy Create free account
hub / github.com/Snapchat/Valdi / calculateBaseline

Function calculateBaseline

third-party/yoga/src/yoga/algorithm/Baseline.cpp:17–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15namespace facebook::yoga {
16
17float calculateBaseline(const yoga::Node* node) {
18 if (node->hasBaselineFunc()) {
19 Event::publish<Event::NodeBaselineStart>(node);
20
21 const float baseline = node->baseline(
22 node->getLayout().measuredDimension(Dimension::Width),
23 node->getLayout().measuredDimension(Dimension::Height));
24
25 Event::publish<Event::NodeBaselineEnd>(node);
26
27 yoga::assertFatalWithNode(
28 node,
29 !std::isnan(baseline),
30 "Expect custom baseline function to not return NaN");
31 return baseline;
32 }
33
34 yoga::Node* baselineChild = nullptr;
35 for (auto child : node->getLayoutChildren()) {
36 if (child->getLineIndex() > 0) {
37 break;
38 }
39 if (child->style().positionType() == PositionType::Absolute) {
40 continue;
41 }
42 if (resolveChildAlignment(node, child) == Align::Baseline ||
43 child->isReferenceBaseline()) {
44 baselineChild = child;
45 break;
46 }
47
48 if (baselineChild == nullptr) {
49 baselineChild = child;
50 }
51 }
52
53 if (baselineChild == nullptr) {
54 return node->getLayout().measuredDimension(Dimension::Height);
55 }
56
57 const float baseline = calculateBaseline(baselineChild);
58 return baseline + baselineChild->getLayout().position(PhysicalEdge::Top);
59}
60
61bool isBaselineLayout(const yoga::Node* node) {
62 if (isColumn(node->style().flexDirection())) {

Callers 2

justifyMainAxisFunction · 0.85
calculateLayoutImplFunction · 0.85

Calls 5

assertFatalWithNodeFunction · 0.85
resolveChildAlignmentFunction · 0.85
measuredDimensionMethod · 0.80
baselineMethod · 0.65
positionMethod · 0.45

Tested by

no test coverage detected