Summary: YogaValue.cs(20,30): error CS1644: Feature `expression bodied members' cannot be used because it is not part of the C# 4.0 language specification YogaValue.cs(21,28): error CS1644: Feature `expression bodied members' cannot be used because it is not part of the C# 4.0 language specification Closes https://github.com/facebook/yoga/pull/316 Reviewed By: emilsjolander Differential Revision: D4381190 Pulled By: splhack fbshipit-source-id: fea157ac03944260d87b9f137bf966605c01a10e
88 lines
2.1 KiB
C#
88 lines
2.1 KiB
C#
/**
|
|
* 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.Runtime.InteropServices;
|
|
|
|
namespace Facebook.Yoga
|
|
{
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct YogaValue
|
|
{
|
|
private float value;
|
|
private YogaUnit unit;
|
|
|
|
public YogaUnit Unit
|
|
{
|
|
get
|
|
{
|
|
return unit;
|
|
}
|
|
}
|
|
|
|
public float Value
|
|
{
|
|
get
|
|
{
|
|
return value;
|
|
}
|
|
}
|
|
|
|
public static YogaValue Pixel(float value)
|
|
{
|
|
return new YogaValue
|
|
{
|
|
value = value,
|
|
unit = YogaConstants.IsUndefined(value) ? YogaUnit.Undefined : YogaUnit.Pixel
|
|
};
|
|
}
|
|
|
|
public bool Equals(YogaValue other)
|
|
{
|
|
return Unit == other.Unit && (Value.Equals(other.Value) || Unit == YogaUnit.Undefined);
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (ReferenceEquals(null, obj)) return false;
|
|
return obj is YogaValue && Equals((YogaValue) obj);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
unchecked
|
|
{
|
|
return (Value.GetHashCode() * 397) ^ (int) Unit;
|
|
}
|
|
}
|
|
|
|
public static YogaValue Undefined()
|
|
{
|
|
return new YogaValue
|
|
{
|
|
value = YogaConstants.Undefined,
|
|
unit = YogaUnit.Undefined
|
|
};
|
|
}
|
|
|
|
public static YogaValue Percent(float value)
|
|
{
|
|
return new YogaValue
|
|
{
|
|
value = value,
|
|
unit = YogaConstants.IsUndefined(value) ? YogaUnit.Undefined : YogaUnit.Percent
|
|
};
|
|
}
|
|
|
|
public static implicit operator YogaValue(float pixelValue)
|
|
{
|
|
return Pixel(pixelValue);
|
|
}
|
|
}
|
|
}
|