Change the type of flex to YGFloatOptional
Summary: Change the type of flex to YGFloatOptional internally, but keeping the public facing API the same as before Reviewed By: emilsjolander Differential Revision: D7211327 fbshipit-source-id: 0d979b6ba00317317b98bbc6e63979c7f1feb2da
This commit is contained in:
committed by
Facebook Github Bot
parent
b3f8851bc2
commit
2232d7603a
@@ -57,3 +57,9 @@ float YGFloatSanitize(const float& val) {
|
|||||||
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
|
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
|
||||||
return op.isUndefined ? YGUndefined : op.value;
|
return op.isUndefined ? YGUndefined : op.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool YGFloatOptionalFloatEquals(
|
||||||
|
const YGFloatOptional& optional,
|
||||||
|
const float& val) {
|
||||||
|
return YGUnwrapFloatOptional(optional) == val;
|
||||||
|
}
|
||||||
|
@@ -94,6 +94,12 @@ float YGFloatSanitize(const float& val);
|
|||||||
// TODO: Get rid off this function
|
// TODO: Get rid off this function
|
||||||
float YGUnwrapFloatOptional(const YGFloatOptional& op);
|
float YGUnwrapFloatOptional(const YGFloatOptional& op);
|
||||||
|
|
||||||
|
// This function returns true if val and optional both are undefined or if val
|
||||||
|
// and optional.val is true, otherwise its false.
|
||||||
|
bool YGFloatOptionalFloatEquals(
|
||||||
|
const YGFloatOptional& optional,
|
||||||
|
const float& val);
|
||||||
|
|
||||||
YGFlexDirection YGFlexDirectionCross(
|
YGFlexDirection YGFlexDirectionCross(
|
||||||
const YGFlexDirection flexDirection,
|
const YGFlexDirection flexDirection,
|
||||||
const YGDirection direction);
|
const YGDirection direction);
|
||||||
|
@@ -500,7 +500,7 @@ YGValue YGNode::resolveFlexBasisPtr() const {
|
|||||||
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
|
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
|
||||||
return flexBasis;
|
return flexBasis;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(style_.flex) && style_.flex > 0.0f) {
|
if (!style_.flex.isUndefined && style_.flex.value > 0.0f) {
|
||||||
return config_->useWebDefaults ? YGValueAuto : YGValueZero;
|
return config_->useWebDefaults ? YGValueAuto : YGValueZero;
|
||||||
}
|
}
|
||||||
return YGValueAuto;
|
return YGValueAuto;
|
||||||
@@ -595,8 +595,8 @@ float YGNode::resolveFlexGrow() {
|
|||||||
if (!YGFloatIsUndefined(style_.flexGrow)) {
|
if (!YGFloatIsUndefined(style_.flexGrow)) {
|
||||||
return style_.flexGrow;
|
return style_.flexGrow;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(style_.flex) && style_.flex > 0.0f) {
|
if (!style_.flex.isUndefined && style_.flex.value > 0.0f) {
|
||||||
return style_.flex;
|
return style_.flex.value;
|
||||||
}
|
}
|
||||||
return kDefaultFlexGrow;
|
return kDefaultFlexGrow;
|
||||||
}
|
}
|
||||||
@@ -608,9 +608,9 @@ float YGNode::resolveFlexShrink() {
|
|||||||
if (!YGFloatIsUndefined(style_.flexShrink)) {
|
if (!YGFloatIsUndefined(style_.flexShrink)) {
|
||||||
return style_.flexShrink;
|
return style_.flexShrink;
|
||||||
}
|
}
|
||||||
if (!config_->useWebDefaults && !YGFloatIsUndefined(style_.flex) &&
|
if (!config_->useWebDefaults && !style_.flex.isUndefined &&
|
||||||
style_.flex < 0.0f) {
|
style_.flex.value < 0.0f) {
|
||||||
return -style_.flex;
|
return -style_.flex.value;
|
||||||
}
|
}
|
||||||
return config_->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink;
|
return config_->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink;
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,15 @@ static void appendFormatedString(string* str, const char* fmt, ...) {
|
|||||||
str->append(result);
|
str->append(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void appendFloatOptionalIfDefined(
|
||||||
|
string* base,
|
||||||
|
const string key,
|
||||||
|
const YGFloatOptional num) {
|
||||||
|
if (!num.isUndefined) {
|
||||||
|
appendFormatedString(base, "%s: %g; ", key.c_str(), num.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
appendFloatIfNotUndefined(string* base, const string key, const float num) {
|
appendFloatIfNotUndefined(string* base, const string key, const float num) {
|
||||||
if (!YGFloatIsUndefined(num)) {
|
if (!YGFloatIsUndefined(num)) {
|
||||||
@@ -155,7 +164,7 @@ void YGNodeToString(
|
|||||||
appendFloatIfNotUndefined(str, "flex-grow", node->getStyle().flexGrow);
|
appendFloatIfNotUndefined(str, "flex-grow", node->getStyle().flexGrow);
|
||||||
appendFloatIfNotUndefined(str, "flex-shrink", node->getStyle().flexShrink);
|
appendFloatIfNotUndefined(str, "flex-shrink", node->getStyle().flexShrink);
|
||||||
appendNumberIfNotAuto(str, "flex-basis", node->getStyle().flexBasis);
|
appendNumberIfNotAuto(str, "flex-basis", node->getStyle().flexBasis);
|
||||||
appendFloatIfNotUndefined(str, "flex", node->getStyle().flex);
|
appendFloatOptionalIfDefined(str, "flex", node->getStyle().flex);
|
||||||
|
|
||||||
if (node->getStyle().flexWrap != YGNode().getStyle().flexWrap) {
|
if (node->getStyle().flexWrap != YGNode().getStyle().flexWrap) {
|
||||||
appendFormatedString(
|
appendFormatedString(
|
||||||
|
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include "YGStyle.h"
|
#include "YGStyle.h"
|
||||||
|
|
||||||
|
#define YGFloatOptionalUndefined \
|
||||||
|
{ true, 0 }
|
||||||
|
|
||||||
const YGValue kYGValueUndefined = {0, YGUnitUndefined};
|
const YGValue kYGValueUndefined = {0, YGUnitUndefined};
|
||||||
|
|
||||||
const YGValue kYGValueAuto = {YGUndefined, YGUnitAuto};
|
const YGValue kYGValueAuto = {YGUndefined, YGUnitAuto};
|
||||||
@@ -39,7 +42,7 @@ YGStyle::YGStyle()
|
|||||||
flexWrap(YGWrapNoWrap),
|
flexWrap(YGWrapNoWrap),
|
||||||
overflow(YGOverflowVisible),
|
overflow(YGOverflowVisible),
|
||||||
display(YGDisplayFlex),
|
display(YGDisplayFlex),
|
||||||
flex(YGUndefined),
|
flex(YGFloatOptionalUndefined),
|
||||||
flexGrow(YGUndefined),
|
flexGrow(YGUndefined),
|
||||||
flexShrink(YGUndefined),
|
flexShrink(YGUndefined),
|
||||||
flexBasis(kYGValueAuto),
|
flexBasis(kYGValueAuto),
|
||||||
@@ -69,8 +72,11 @@ bool YGStyle::operator==(const YGStyle& style) {
|
|||||||
YGValueArrayEqual(minDimensions, style.minDimensions) &&
|
YGValueArrayEqual(minDimensions, style.minDimensions) &&
|
||||||
YGValueArrayEqual(maxDimensions, style.maxDimensions);
|
YGValueArrayEqual(maxDimensions, style.maxDimensions);
|
||||||
|
|
||||||
if (!(YGFloatIsUndefined(flex) && YGFloatIsUndefined(style.flex))) {
|
areNonFloatValuesEqual =
|
||||||
areNonFloatValuesEqual = areNonFloatValuesEqual && flex == style.flex;
|
areNonFloatValuesEqual && flex.isUndefined == style.flex.isUndefined;
|
||||||
|
if (areNonFloatValuesEqual && !flex.isUndefined && !style.flex.isUndefined) {
|
||||||
|
areNonFloatValuesEqual =
|
||||||
|
areNonFloatValuesEqual && flex.value == style.flex.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(YGFloatIsUndefined(flexGrow) && YGFloatIsUndefined(style.flexGrow))) {
|
if (!(YGFloatIsUndefined(flexGrow) && YGFloatIsUndefined(style.flexGrow))) {
|
||||||
|
@@ -20,7 +20,7 @@ struct YGStyle {
|
|||||||
YGWrap flexWrap;
|
YGWrap flexWrap;
|
||||||
YGOverflow overflow;
|
YGOverflow overflow;
|
||||||
YGDisplay display;
|
YGDisplay display;
|
||||||
float flex;
|
YGFloatOptional flex;
|
||||||
float flexGrow;
|
float flexGrow;
|
||||||
float flexShrink;
|
float flexShrink;
|
||||||
YGValue flexBasis;
|
YGValue flexBasis;
|
||||||
|
@@ -752,7 +752,26 @@ YG_NODE_STYLE_PROPERTY_IMPL(YGWrap, FlexWrap, flexWrap, flexWrap);
|
|||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGOverflow, Overflow, overflow, overflow);
|
YG_NODE_STYLE_PROPERTY_IMPL(YGOverflow, Overflow, overflow, overflow);
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display);
|
YG_NODE_STYLE_PROPERTY_IMPL(YGDisplay, Display, display, display);
|
||||||
|
|
||||||
YG_NODE_STYLE_PROPERTY_IMPL(float, Flex, flex, flex);
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
|
void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
||||||
|
if (!YGFloatOptionalFloatEquals(node->getStyle().flex, flex)) {
|
||||||
|
YGStyle style = node->getStyle();
|
||||||
|
if (YGFloatIsUndefined(flex)) {
|
||||||
|
style.flex = {true, 0};
|
||||||
|
} else {
|
||||||
|
style.flex = {false, flex};
|
||||||
|
}
|
||||||
|
node->setStyle(style);
|
||||||
|
node->markDirtyAndPropogate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
|
float YGNodeStyleGetFlex(const YGNodeRef node) {
|
||||||
|
return node->getStyle().flex.isUndefined ? YGUndefined
|
||||||
|
: node->getStyle().flex.value;
|
||||||
|
}
|
||||||
|
|
||||||
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow);
|
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow);
|
||||||
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink);
|
YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink);
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis);
|
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis);
|
||||||
@@ -762,7 +781,7 @@ YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin);
|
|||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Padding, padding, padding);
|
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Padding, padding, padding);
|
||||||
|
|
||||||
// TODO: Change the API to accept YGFloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
void YGNodeStyleSetBorder(
|
void YGNodeStyleSetBorder(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGEdge edge,
|
const YGEdge edge,
|
||||||
@@ -783,8 +802,8 @@ void YGNodeStyleSetBorder(
|
|||||||
|
|
||||||
float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge) {
|
float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge) {
|
||||||
if (node->getStyle().border[edge].unit == YGUnitUndefined) {
|
if (node->getStyle().border[edge].unit == YGUnitUndefined) {
|
||||||
// TODO: Rather than returning YGUndefined, change the api to return
|
// TODO(T26792433): Rather than returning YGUndefined, change the api to
|
||||||
// YGFloatOptional.
|
// return YGFloatOptional.
|
||||||
return YGUndefined;
|
return YGUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -195,7 +195,6 @@ YG_NODE_STYLE_PROPERTY(YGPositionType, PositionType, positionType);
|
|||||||
YG_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap);
|
YG_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap);
|
||||||
YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
|
YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
|
||||||
YG_NODE_STYLE_PROPERTY(YGDisplay, Display, display);
|
YG_NODE_STYLE_PROPERTY(YGDisplay, Display, display);
|
||||||
|
|
||||||
YG_NODE_STYLE_PROPERTY(float, Flex, flex);
|
YG_NODE_STYLE_PROPERTY(float, Flex, flex);
|
||||||
YG_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
YG_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
||||||
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
||||||
|
Reference in New Issue
Block a user