Adding node type and moving rounding dependency to rely on that type
Reviewed By: emilsjolander Differential Revision: D5025107 fbshipit-source-id: a8d66e2f9c5d02ab080784cc474be583a09b92e2
This commit is contained in:
parent
c15a6b6202
commit
70b7488f97
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
#include "YGEnums.h"
|
||||
|
||||
const char *YGAlignToString(const YGAlign value) {
|
||||
switch (value) {
|
||||
const char *YGAlignToString(const YGAlign value){
|
||||
switch(value){
|
||||
case YGAlignAuto:
|
||||
return "auto";
|
||||
case YGAlignFlexStart:
|
||||
|
@ -31,8 +31,8 @@ const char *YGAlignToString(const YGAlign value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGDimensionToString(const YGDimension value) {
|
||||
switch (value) {
|
||||
const char *YGDimensionToString(const YGDimension value){
|
||||
switch(value){
|
||||
case YGDimensionWidth:
|
||||
return "width";
|
||||
case YGDimensionHeight:
|
||||
|
@ -41,8 +41,8 @@ const char *YGDimensionToString(const YGDimension value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGDirectionToString(const YGDirection value) {
|
||||
switch (value) {
|
||||
const char *YGDirectionToString(const YGDirection value){
|
||||
switch(value){
|
||||
case YGDirectionInherit:
|
||||
return "inherit";
|
||||
case YGDirectionLTR:
|
||||
|
@ -53,8 +53,8 @@ const char *YGDirectionToString(const YGDirection value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGDisplayToString(const YGDisplay value) {
|
||||
switch (value) {
|
||||
const char *YGDisplayToString(const YGDisplay value){
|
||||
switch(value){
|
||||
case YGDisplayFlex:
|
||||
return "flex";
|
||||
case YGDisplayNone:
|
||||
|
@ -63,8 +63,8 @@ const char *YGDisplayToString(const YGDisplay value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGEdgeToString(const YGEdge value) {
|
||||
switch (value) {
|
||||
const char *YGEdgeToString(const YGEdge value){
|
||||
switch(value){
|
||||
case YGEdgeLeft:
|
||||
return "left";
|
||||
case YGEdgeTop:
|
||||
|
@ -87,16 +87,16 @@ const char *YGEdgeToString(const YGEdge value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGExperimentalFeatureToString(const YGExperimentalFeature value) {
|
||||
switch (value) {
|
||||
const char *YGExperimentalFeatureToString(const YGExperimentalFeature value){
|
||||
switch(value){
|
||||
case YGExperimentalFeatureWebFlexBasis:
|
||||
return "web-flex-basis";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGFlexDirectionToString(const YGFlexDirection value) {
|
||||
switch (value) {
|
||||
const char *YGFlexDirectionToString(const YGFlexDirection value){
|
||||
switch(value){
|
||||
case YGFlexDirectionColumn:
|
||||
return "column";
|
||||
case YGFlexDirectionColumnReverse:
|
||||
|
@ -109,8 +109,8 @@ const char *YGFlexDirectionToString(const YGFlexDirection value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGJustifyToString(const YGJustify value) {
|
||||
switch (value) {
|
||||
const char *YGJustifyToString(const YGJustify value){
|
||||
switch(value){
|
||||
case YGJustifyFlexStart:
|
||||
return "flex-start";
|
||||
case YGJustifyCenter:
|
||||
|
@ -125,8 +125,8 @@ const char *YGJustifyToString(const YGJustify value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGLogLevelToString(const YGLogLevel value) {
|
||||
switch (value) {
|
||||
const char *YGLogLevelToString(const YGLogLevel value){
|
||||
switch(value){
|
||||
case YGLogLevelError:
|
||||
return "error";
|
||||
case YGLogLevelWarn:
|
||||
|
@ -143,8 +143,8 @@ const char *YGLogLevelToString(const YGLogLevel value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGMeasureModeToString(const YGMeasureMode value) {
|
||||
switch (value) {
|
||||
const char *YGMeasureModeToString(const YGMeasureMode value){
|
||||
switch(value){
|
||||
case YGMeasureModeUndefined:
|
||||
return "undefined";
|
||||
case YGMeasureModeExactly:
|
||||
|
@ -155,8 +155,18 @@ const char *YGMeasureModeToString(const YGMeasureMode value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGOverflowToString(const YGOverflow value) {
|
||||
switch (value) {
|
||||
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:
|
||||
return "visible";
|
||||
case YGOverflowHidden:
|
||||
|
@ -167,8 +177,8 @@ const char *YGOverflowToString(const YGOverflow value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGPositionTypeToString(const YGPositionType value) {
|
||||
switch (value) {
|
||||
const char *YGPositionTypeToString(const YGPositionType value){
|
||||
switch(value){
|
||||
case YGPositionTypeRelative:
|
||||
return "relative";
|
||||
case YGPositionTypeAbsolute:
|
||||
|
@ -177,8 +187,8 @@ const char *YGPositionTypeToString(const YGPositionType value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGPrintOptionsToString(const YGPrintOptions value) {
|
||||
switch (value) {
|
||||
const char *YGPrintOptionsToString(const YGPrintOptions value){
|
||||
switch(value){
|
||||
case YGPrintOptionsLayout:
|
||||
return "layout";
|
||||
case YGPrintOptionsStyle:
|
||||
|
@ -189,8 +199,8 @@ const char *YGPrintOptionsToString(const YGPrintOptions value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGUnitToString(const YGUnit value) {
|
||||
switch (value) {
|
||||
const char *YGUnitToString(const YGUnit value){
|
||||
switch(value){
|
||||
case YGUnitUndefined:
|
||||
return "undefined";
|
||||
case YGUnitPoint:
|
||||
|
@ -203,8 +213,8 @@ const char *YGUnitToString(const YGUnit value) {
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
const char *YGWrapToString(const YGWrap value) {
|
||||
switch (value) {
|
||||
const char *YGWrapToString(const YGWrap value){
|
||||
switch(value){
|
||||
case YGWrapNoWrap:
|
||||
return "no-wrap";
|
||||
case YGWrapWrap:
|
||||
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue