Adding node type and moving rounding dependency to rely on that type
Summary: This diff adds node type definition to Yoga and moves rounding to rely on the node type. If the node has measure function we consider that node to be text node, otherwise we have default behavior. Reviewed By: emilsjolander Differential Revision: D5025107 fbshipit-source-id: a8d66e2f9c5d02ab080784cc474be583a09b92e2
This commit is contained in:
committed by
Facebook Github Bot
parent
626a05fb6f
commit
3fefe9fc49
17
csharp/Facebook.Yoga/YogaNodeType.cs
Normal file
17
csharp/Facebook.Yoga/YogaNodeType.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
public enum YogaNodeType
|
||||
{
|
||||
Default,
|
||||
Text,
|
||||
}
|
||||
}
|
4
enums.py
4
enums.py
@@ -84,6 +84,10 @@ ENUMS = {
|
||||
'Vertical',
|
||||
'All',
|
||||
],
|
||||
'NodeType': [
|
||||
'Default',
|
||||
'Text',
|
||||
],
|
||||
'LogLevel': [
|
||||
'Error',
|
||||
'Warn',
|
||||
|
36
java/com/facebook/yoga/YogaNodeType.java
Normal file
36
java/com/facebook/yoga/YogaNodeType.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
@DoNotStrip
|
||||
public enum YogaNodeType {
|
||||
DEFAULT(0),
|
||||
TEXT(1);
|
||||
|
||||
private int mIntValue;
|
||||
|
||||
YogaNodeType(int intValue) {
|
||||
mIntValue = intValue;
|
||||
}
|
||||
|
||||
public int intValue() {
|
||||
return mIntValue;
|
||||
}
|
||||
|
||||
public static YogaNodeType fromInt(int value) {
|
||||
switch (value) {
|
||||
case 0: return DEFAULT;
|
||||
case 1: return TEXT;
|
||||
default: throw new IllegalArgumentException("Unknown enum value: " + value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -72,6 +72,10 @@ module.exports = {
|
||||
MEASURE_MODE_EXACTLY: 1,
|
||||
MEASURE_MODE_AT_MOST: 2,
|
||||
|
||||
NODE_TYPE_COUNT: 2,
|
||||
NODE_TYPE_DEFAULT: 0,
|
||||
NODE_TYPE_TEXT: 1,
|
||||
|
||||
OVERFLOW_COUNT: 3,
|
||||
OVERFLOW_VISIBLE: 0,
|
||||
OVERFLOW_HIDDEN: 1,
|
||||
|
@@ -155,6 +155,16 @@ const char *YGMeasureModeToString(const YGMeasureMode value) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGNodeTypeToString(const YGNodeType value){
|
||||
switch(value){
|
||||
case YGNodeTypeDefault:
|
||||
return "default";
|
||||
case YGNodeTypeText:
|
||||
return "text";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGOverflowToString(const YGOverflow value){
|
||||
switch(value){
|
||||
case YGOverflowVisible:
|
||||
@@ -214,3 +224,4 @@ const char *YGWrapToString(const YGWrap value) {
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
|
@@ -106,6 +106,13 @@ typedef YG_ENUM_BEGIN(YGMeasureMode) {
|
||||
} YG_ENUM_END(YGMeasureMode);
|
||||
WIN_EXPORT const char *YGMeasureModeToString(const YGMeasureMode value);
|
||||
|
||||
#define YGNodeTypeCount 2
|
||||
typedef YG_ENUM_BEGIN(YGNodeType) {
|
||||
YGNodeTypeDefault,
|
||||
YGNodeTypeText,
|
||||
} YG_ENUM_END(YGNodeType);
|
||||
WIN_EXPORT const char *YGNodeTypeToString(const YGNodeType value);
|
||||
|
||||
#define YGOverflowCount 3
|
||||
typedef YG_ENUM_BEGIN(YGOverflow) {
|
||||
YGOverflowVisible,
|
||||
|
21
yoga/Yoga.c
21
yoga/Yoga.c
@@ -121,6 +121,7 @@ typedef struct YGNode {
|
||||
|
||||
bool isDirty;
|
||||
bool hasNewLayout;
|
||||
YGNodeType nodeType;
|
||||
|
||||
YGValue const *resolvedDimensions[2];
|
||||
} YGNode;
|
||||
@@ -158,6 +159,7 @@ static YGNode gYGNodeDefaults = {
|
||||
.children = NULL,
|
||||
.hasNewLayout = true,
|
||||
.isDirty = false,
|
||||
.nodeType = YGNodeTypeDefault,
|
||||
.resolvedDimensions = {[YGDimensionWidth] = &YGValueUndefined,
|
||||
[YGDimensionHeight] = &YGValueUndefined},
|
||||
|
||||
@@ -444,11 +446,15 @@ static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
|
||||
void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) {
|
||||
if (measureFunc == NULL) {
|
||||
node->measure = NULL;
|
||||
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate places in Litho
|
||||
node->nodeType = YGNodeTypeDefault;
|
||||
} else {
|
||||
YGAssertWithNode(node,
|
||||
YGNodeGetChildCount(node) == 0,
|
||||
"Cannot set measure function: Nodes with measure functions cannot have children.");
|
||||
node->measure = measureFunc;
|
||||
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate places in Litho
|
||||
node->nodeType = YGNodeTypeText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,6 +728,7 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
|
||||
YG_NODE_PROPERTY_IMPL(void *, Context, context, context);
|
||||
YG_NODE_PROPERTY_IMPL(YGPrintFunc, PrintFunc, printFunc, print);
|
||||
YG_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout);
|
||||
YG_NODE_PROPERTY_IMPL(YGNodeType, NodeType, nodeType, nodeType);
|
||||
|
||||
YG_NODE_STYLE_PROPERTY_IMPL(YGDirection, Direction, direction, direction);
|
||||
YG_NODE_STYLE_PROPERTY_IMPL(YGFlexDirection, FlexDirection, flexDirection, flexDirection);
|
||||
@@ -3402,19 +3409,19 @@ static void YGRoundToPixelGrid(const YGNodeRef node,
|
||||
|
||||
// If a node has a custom measure function we never want to round down its size as this could
|
||||
// lead to unwanted text truncation.
|
||||
const bool hasMeasure = node->measure != NULL;
|
||||
const bool textRounding = node->nodeType == YGNodeTypeText;
|
||||
|
||||
node->layout.position[YGEdgeLeft] =
|
||||
YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor, false, hasMeasure);
|
||||
YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding);
|
||||
node->layout.position[YGEdgeTop] =
|
||||
YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, hasMeasure);
|
||||
YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding);
|
||||
|
||||
node->layout.dimensions[YGDimensionWidth] =
|
||||
YGRoundValueToPixelGrid(absoluteNodeRight, pointScaleFactor, hasMeasure, false) -
|
||||
YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, hasMeasure);
|
||||
YGRoundValueToPixelGrid(absoluteNodeRight, pointScaleFactor, textRounding, false) -
|
||||
YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, textRounding);
|
||||
node->layout.dimensions[YGDimensionHeight] =
|
||||
YGRoundValueToPixelGrid(absoluteNodeBottom, pointScaleFactor, hasMeasure, false) -
|
||||
YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, hasMeasure);
|
||||
YGRoundValueToPixelGrid(absoluteNodeBottom, pointScaleFactor, textRounding, false) -
|
||||
YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, textRounding);
|
||||
|
||||
const uint32_t childCount = YGNodeListCount(node->children);
|
||||
for (uint32_t i = 0; i < childCount; i++) {
|
||||
|
@@ -161,6 +161,7 @@ YG_NODE_PROPERTY(YGMeasureFunc, MeasureFunc, measureFunc);
|
||||
YG_NODE_PROPERTY(YGBaselineFunc, BaselineFunc, baselineFunc)
|
||||
YG_NODE_PROPERTY(YGPrintFunc, PrintFunc, printFunc);
|
||||
YG_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
||||
YG_NODE_PROPERTY(YGNodeType, NodeType, nodeType);
|
||||
|
||||
YG_NODE_STYLE_PROPERTY(YGDirection, Direction, direction);
|
||||
YG_NODE_STYLE_PROPERTY(YGFlexDirection, FlexDirection, flexDirection);
|
||||
|
Reference in New Issue
Block a user