C++ Cleanup 6/N: YGFloatOptional (#1356)
Summary: X-link: https://github.com/facebook/react-native/pull/39224 Pull Request resolved: https://github.com/facebook/yoga/pull/1356 X-link: https://github.com/facebook/react-native/pull/39196 ## This diff This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] bypass-github-export-checks Reviewed By: shwanton Differential Revision: D48847256 fbshipit-source-id: ab9729a4a02ab90d974183425935f4d274db5732
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c029041707
commit
989f352e03
@@ -110,7 +110,7 @@ CompactValue Node::computeColumnGap(
|
||||
}
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getLeadingPosition(
|
||||
FloatOptional Node::getLeadingPosition(
|
||||
const YGFlexDirection axis,
|
||||
const float axisSize) const {
|
||||
auto leadingPosition = isRow(axis)
|
||||
@@ -124,7 +124,7 @@ YGFloatOptional Node::getLeadingPosition(
|
||||
return yoga::resolveValue(leadingPosition, axisSize);
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getTrailingPosition(
|
||||
FloatOptional Node::getTrailingPosition(
|
||||
const YGFlexDirection axis,
|
||||
const float axisSize) const {
|
||||
auto trailingPosition = isRow(axis)
|
||||
@@ -162,7 +162,7 @@ bool Node::isTrailingPosDefined(const YGFlexDirection axis) const {
|
||||
return !trailingPosition.isUndefined();
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getLeadingMargin(
|
||||
FloatOptional Node::getLeadingMargin(
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) const {
|
||||
auto leadingMargin = isRow(axis)
|
||||
@@ -170,11 +170,11 @@ YGFloatOptional Node::getLeadingMargin(
|
||||
style_.margin(), YGEdgeStart, leading[axis], CompactValue::ofZero())
|
||||
: computeEdgeValueForColumn(
|
||||
style_.margin(), leading[axis], CompactValue::ofZero());
|
||||
return leadingMargin.isAuto() ? YGFloatOptional{0}
|
||||
return leadingMargin.isAuto() ? FloatOptional{0}
|
||||
: yoga::resolveValue(leadingMargin, widthSize);
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getTrailingMargin(
|
||||
FloatOptional Node::getTrailingMargin(
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) const {
|
||||
auto trailingMargin = isRow(axis)
|
||||
@@ -183,17 +183,17 @@ YGFloatOptional Node::getTrailingMargin(
|
||||
: computeEdgeValueForColumn(
|
||||
style_.margin(), trailing[axis], CompactValue::ofZero());
|
||||
return trailingMargin.isAuto()
|
||||
? YGFloatOptional{0}
|
||||
? FloatOptional{0}
|
||||
: yoga::resolveValue(trailingMargin, widthSize);
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getMarginForAxis(
|
||||
FloatOptional Node::getMarginForAxis(
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) const {
|
||||
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getGapForAxis(
|
||||
FloatOptional Node::getGapForAxis(
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) const {
|
||||
auto gap = isRow(axis)
|
||||
@@ -325,7 +325,7 @@ void Node::setLayoutLastOwnerDirection(YGDirection direction) {
|
||||
layout_.lastOwnerDirection = direction;
|
||||
}
|
||||
|
||||
void Node::setLayoutComputedFlexBasis(const YGFloatOptional computedFlexBasis) {
|
||||
void Node::setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis) {
|
||||
layout_.computedFlexBasis = computedFlexBasis;
|
||||
}
|
||||
|
||||
@@ -352,16 +352,16 @@ void Node::setLayoutDimension(float dimension, int index) {
|
||||
|
||||
// If both left and right are defined, then use left. Otherwise return +left or
|
||||
// -right depending on which is defined.
|
||||
YGFloatOptional Node::relativePosition(
|
||||
FloatOptional Node::relativePosition(
|
||||
const YGFlexDirection axis,
|
||||
const float axisSize) const {
|
||||
if (isLeadingPositionDefined(axis)) {
|
||||
return getLeadingPosition(axis, axisSize);
|
||||
}
|
||||
|
||||
YGFloatOptional trailingPosition = getTrailingPosition(axis, axisSize);
|
||||
FloatOptional trailingPosition = getTrailingPosition(axis, axisSize);
|
||||
if (!trailingPosition.isUndefined()) {
|
||||
trailingPosition = YGFloatOptional{-1 * trailingPosition.unwrap()};
|
||||
trailingPosition = FloatOptional{-1 * trailingPosition.unwrap()};
|
||||
}
|
||||
return trailingPosition;
|
||||
}
|
||||
@@ -383,9 +383,9 @@ void Node::setPosition(
|
||||
// Here we should check for `YGPositionTypeStatic` and in this case zero inset
|
||||
// properties (left, right, top, bottom, begin, end).
|
||||
// https://www.w3.org/TR/css-position-3/#valdef-position-static
|
||||
const YGFloatOptional relativePositionMain =
|
||||
const FloatOptional relativePositionMain =
|
||||
relativePosition(mainAxis, mainSize);
|
||||
const YGFloatOptional relativePositionCross =
|
||||
const FloatOptional relativePositionCross =
|
||||
relativePosition(crossAxis, crossSize);
|
||||
|
||||
setLayoutPosition(
|
||||
@@ -468,7 +468,7 @@ void Node::cloneChildrenIfNeeded(void* cloneContext) {
|
||||
void Node::markDirtyAndPropagate() {
|
||||
if (!flags_.isDirty) {
|
||||
setDirty(true);
|
||||
setLayoutComputedFlexBasis(YGFloatOptional());
|
||||
setLayoutComputedFlexBasis(FloatOptional());
|
||||
if (owner_) {
|
||||
owner_->markDirtyAndPropagate();
|
||||
}
|
||||
@@ -534,7 +534,7 @@ float Node::getTrailingBorder(const YGFlexDirection axis) const {
|
||||
return fmaxf(trailingBorder.value, 0.0f);
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getLeadingPadding(
|
||||
FloatOptional Node::getLeadingPadding(
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) const {
|
||||
auto leadingPadding = isRow(axis)
|
||||
@@ -546,10 +546,10 @@ YGFloatOptional Node::getLeadingPadding(
|
||||
: computeEdgeValueForColumn(
|
||||
style_.padding(), leading[axis], CompactValue::ofZero());
|
||||
return yoga::maxOrDefined(
|
||||
yoga::resolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f));
|
||||
yoga::resolveValue(leadingPadding, widthSize), FloatOptional(0.0f));
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getTrailingPadding(
|
||||
FloatOptional Node::getTrailingPadding(
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) const {
|
||||
auto trailingPadding = isRow(axis)
|
||||
@@ -558,21 +558,21 @@ YGFloatOptional Node::getTrailingPadding(
|
||||
: computeEdgeValueForColumn(
|
||||
style_.padding(), trailing[axis], CompactValue::ofZero());
|
||||
return yoga::maxOrDefined(
|
||||
yoga::resolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f));
|
||||
yoga::resolveValue(trailingPadding, widthSize), FloatOptional(0.0f));
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getLeadingPaddingAndBorder(
|
||||
FloatOptional Node::getLeadingPaddingAndBorder(
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) const {
|
||||
return getLeadingPadding(axis, widthSize) +
|
||||
YGFloatOptional(getLeadingBorder(axis));
|
||||
FloatOptional(getLeadingBorder(axis));
|
||||
}
|
||||
|
||||
YGFloatOptional Node::getTrailingPaddingAndBorder(
|
||||
FloatOptional Node::getTrailingPaddingAndBorder(
|
||||
const YGFlexDirection axis,
|
||||
const float widthSize) const {
|
||||
return getTrailingPadding(axis, widthSize) +
|
||||
YGFloatOptional(getTrailingBorder(axis));
|
||||
FloatOptional(getTrailingBorder(axis));
|
||||
}
|
||||
|
||||
void Node::reset() {
|
||||
|
Reference in New Issue
Block a user