2016-11-17 07:03:30 -08:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
namespace Facebook.Yoga
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public partial class YogaNode
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
[Obsolete("use Object Initializer")]
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public static YogaNode Create(
|
2016-12-02 05:47:43 -08:00
|
|
|
|
YogaDirection? styleDirection = null,
|
|
|
|
|
YogaFlexDirection? flexDirection = null,
|
|
|
|
|
YogaJustify? justifyContent = null,
|
|
|
|
|
YogaAlign? alignContent = null,
|
|
|
|
|
YogaAlign? alignItems = null,
|
|
|
|
|
YogaAlign? alignSelf = null,
|
|
|
|
|
YogaPositionType? positionType = null,
|
|
|
|
|
YogaWrap? wrap = null,
|
|
|
|
|
YogaOverflow? overflow = null,
|
2016-11-17 07:03:30 -08:00
|
|
|
|
float? flex = null,
|
|
|
|
|
float? flexGrow = null,
|
|
|
|
|
float? flexShrink = null,
|
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
2017-01-02 05:20:37 -08:00
|
|
|
|
YogaValue? flexBasis = null,
|
2016-11-17 07:03:30 -08:00
|
|
|
|
Spacing position = null,
|
|
|
|
|
Spacing margin = null,
|
|
|
|
|
Spacing padding = null,
|
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
2017-01-02 05:20:37 -08:00
|
|
|
|
Border border = null,
|
|
|
|
|
YogaValue? width = null,
|
|
|
|
|
YogaValue? height = null,
|
|
|
|
|
YogaValue? maxWidth = null,
|
|
|
|
|
YogaValue? maxHeight = null,
|
|
|
|
|
YogaValue? minWidth = null,
|
|
|
|
|
YogaValue? minHeight = null)
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2016-12-02 11:18:16 -08:00
|
|
|
|
YogaNode node = new YogaNode();
|
2016-11-17 07:03:30 -08:00
|
|
|
|
|
|
|
|
|
if (styleDirection.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.StyleDirection = styleDirection.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flexDirection.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.FlexDirection = flexDirection.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (justifyContent.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.JustifyContent = justifyContent.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (alignContent.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.AlignContent = alignContent.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (alignItems.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.AlignItems = alignItems.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (alignSelf.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.AlignSelf = alignSelf.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (positionType.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.PositionType = positionType.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wrap.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.Wrap = wrap.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (overflow.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.Overflow = overflow.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flex.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.Flex = flex.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flexGrow.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.FlexGrow = flexGrow.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flexShrink.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.FlexShrink = flexShrink.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flexBasis.HasValue)
|
|
|
|
|
{
|
|
|
|
|
node.FlexBasis = flexBasis.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position != null)
|
|
|
|
|
{
|
|
|
|
|
if (position.Top.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.Top = position.Top.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.Bottom.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.Bottom = position.Bottom.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.Left.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.Left = position.Left.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.Right.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.Right = position.Right.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (margin != null)
|
|
|
|
|
{
|
|
|
|
|
if (margin.Top.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.MarginTop = margin.Top.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (margin.Bottom.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.MarginBottom = margin.Bottom.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (margin.Left.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.MarginLeft = margin.Left.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (margin.Right.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.MarginRight = margin.Right.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (padding != null)
|
|
|
|
|
{
|
|
|
|
|
if (padding.Top.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.PaddingTop = padding.Top.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (padding.Bottom.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.PaddingBottom = padding.Bottom.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (padding.Left.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.PaddingLeft = padding.Left.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (padding.Right.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.PaddingRight = padding.Right.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (border != null)
|
|
|
|
|
{
|
|
|
|
|
if (border.Top.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.BorderTopWidth = border.Top.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (border.Bottom.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.BorderBottomWidth = border.Bottom.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (border.Left.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.BorderLeftWidth = border.Left.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (border.Right.HasValue)
|
|
|
|
|
{
|
2017-01-08 07:58:31 -08:00
|
|
|
|
node.BorderRightWidth = border.Right.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 06:59:34 -08:00
|
|
|
|
if (width.HasValue)
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2016-12-15 06:59:34 -08:00
|
|
|
|
node.Width = width.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 06:59:34 -08:00
|
|
|
|
if (height.HasValue)
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2016-12-15 06:59:34 -08:00
|
|
|
|
node.Height = height.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 06:59:34 -08:00
|
|
|
|
if (minWidth.HasValue)
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2016-12-15 06:59:34 -08:00
|
|
|
|
node.MinWidth = minWidth.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 06:59:34 -08:00
|
|
|
|
if (minHeight.HasValue)
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2016-12-15 06:59:34 -08:00
|
|
|
|
node.MinHeight = minHeight.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 06:59:34 -08:00
|
|
|
|
if (maxWidth.HasValue)
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2016-12-15 06:59:34 -08:00
|
|
|
|
node.MaxWidth = maxWidth.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 06:59:34 -08:00
|
|
|
|
if (maxHeight.HasValue)
|
2016-11-17 07:03:30 -08:00
|
|
|
|
{
|
2016-12-15 06:59:34 -08:00
|
|
|
|
node.MaxHeight = maxHeight.Value;
|
2016-11-17 07:03:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|