diff --git a/csharp/Facebook.Yoga/YogaNodeType.cs b/csharp/Facebook.Yoga/YogaNodeType.cs new file mode 100644 index 00000000..f4840018 --- /dev/null +++ b/csharp/Facebook.Yoga/YogaNodeType.cs @@ -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, + } +} diff --git a/enums.py b/enums.py index 0e8a4f37..3d539aeb 100644 --- a/enums.py +++ b/enums.py @@ -84,6 +84,10 @@ ENUMS = { 'Vertical', 'All', ], + 'NodeType': [ + 'Default', + 'Text', + ], 'LogLevel': [ 'Error', 'Warn', diff --git a/java/com/facebook/yoga/YogaNodeType.java b/java/com/facebook/yoga/YogaNodeType.java new file mode 100644 index 00000000..53f56a7f --- /dev/null +++ b/java/com/facebook/yoga/YogaNodeType.java @@ -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); + } + } +} diff --git a/javascript/sources/YGEnums.js b/javascript/sources/YGEnums.js index bb30b61b..373909da 100644 --- a/javascript/sources/YGEnums.js +++ b/javascript/sources/YGEnums.js @@ -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, diff --git a/yoga/YGEnums.c b/yoga/YGEnums.c index 2af4869e..f554c367 100644 --- a/yoga/YGEnums.c +++ b/yoga/YGEnums.c @@ -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"; } + diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index 8ec5829e..e12b9667 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -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, diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 44245b10..3a4faf85 100644 --- a/yoga/Yoga.c +++ b/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++) { diff --git a/yoga/Yoga.h b/yoga/Yoga.h index b18f3dbc..162415db 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -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);