Add feature to use percentage as value unit
Summary: Adds the feature to use percentage as a value unit. You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience. I did some benchmarks: ``` Without Percentage Feature - Release x86: Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms Nested flex: median: 0.000000 ms, stddev: 0.490101 ms Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms Nested flex: median: 0.000000 ms, stddev: 0.477791 ms Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms With Percentage Feature - Release x86: Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms Nested flex: median: 0.000000 ms, stddev: 0.489570 ms Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms Closes https://github.com/facebook/yoga/pull/258 Reviewed By: dshahidehpour Differential Revision: D4361945 Pulled By: emilsjolander fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
This commit is contained in:
committed by
Facebook Github Bot
parent
6f462a72bf
commit
a85bd4ad2a
41
yoga/Yoga.h
41
yoga/Yoga.h
@@ -38,6 +38,11 @@ typedef struct YGSize {
|
||||
float height;
|
||||
} YGSize;
|
||||
|
||||
typedef struct YGValue {
|
||||
float value;
|
||||
YGUnit unit;
|
||||
} YGValue;
|
||||
|
||||
typedef struct YGNode *YGNodeRef;
|
||||
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
|
||||
float width,
|
||||
@@ -83,7 +88,7 @@ WIN_EXPORT bool YGNodeIsDirty(const YGNodeRef node);
|
||||
|
||||
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
|
||||
|
||||
WIN_EXPORT bool YGValueIsUndefined(const float value);
|
||||
WIN_EXPORT bool YGFloatIsUndefined(const float value);
|
||||
|
||||
WIN_EXPORT bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,
|
||||
const float width,
|
||||
@@ -108,12 +113,26 @@ WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode
|
||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, const type paramName); \
|
||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node);
|
||||
|
||||
#define YG_NODE_STYLE_PROPERTY_UNIT(type, name, paramName) \
|
||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, const float paramName); \
|
||||
WIN_EXPORT void YGNodeStyleSet##name##Percent(const YGNodeRef node, const float paramName); \
|
||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node);
|
||||
|
||||
#define YG_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, \
|
||||
const YGEdge edge, \
|
||||
const type paramName); \
|
||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge);
|
||||
|
||||
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT(type, name, paramName) \
|
||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, \
|
||||
const YGEdge edge, \
|
||||
const float paramName); \
|
||||
WIN_EXPORT void YGNodeStyleSet##name##Percent(const YGNodeRef node, \
|
||||
const YGEdge edge, \
|
||||
const float paramName); \
|
||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge);
|
||||
|
||||
#define YG_NODE_LAYOUT_PROPERTY(type, name) \
|
||||
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node);
|
||||
|
||||
@@ -135,19 +154,19 @@ YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
|
||||
WIN_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex);
|
||||
YG_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
||||
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
||||
YG_NODE_STYLE_PROPERTY(float, FlexBasis, flexBasis);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, FlexBasis, flexBasis);
|
||||
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Position, position);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Margin, margin);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Padding, padding);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Position, position);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Margin, margin);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Padding, padding);
|
||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
|
||||
|
||||
YG_NODE_STYLE_PROPERTY(float, Width, width);
|
||||
YG_NODE_STYLE_PROPERTY(float, Height, height);
|
||||
YG_NODE_STYLE_PROPERTY(float, MinWidth, minWidth);
|
||||
YG_NODE_STYLE_PROPERTY(float, MinHeight, minHeight);
|
||||
YG_NODE_STYLE_PROPERTY(float, MaxWidth, maxWidth);
|
||||
YG_NODE_STYLE_PROPERTY(float, MaxHeight, maxHeight);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, Width, width);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, Height, height);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MinWidth, minWidth);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MinHeight, minHeight);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MaxWidth, maxWidth);
|
||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MaxHeight, maxHeight);
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
// Aspect ratio control the size of the undefined dimension of a node.
|
||||
|
Reference in New Issue
Block a user