2016-12-19 23:01:31 +01: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.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace Facebook.Yoga
|
|
|
|
{
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
public struct YogaValue
|
|
|
|
{
|
|
|
|
private float Value;
|
|
|
|
private YogaUnit Unit;
|
2016-12-20 07:32:47 +01:00
|
|
|
private byte isDefined; /* use byte to keep struct blitable */
|
2016-12-19 23:01:31 +01:00
|
|
|
|
|
|
|
public bool IsDefined => isDefined != 0;
|
|
|
|
|
|
|
|
public static YogaValue Pixel(float value)
|
|
|
|
{
|
|
|
|
return new YogaValue
|
|
|
|
{
|
|
|
|
Value = value,
|
2016-12-20 07:32:47 +01:00
|
|
|
isDefined = YogaConstants.IsUndefined(value) ? (byte)0 : (byte)1,
|
2016-12-19 23:01:31 +01:00
|
|
|
Unit = YogaUnit.Pixel
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Equals(YogaValue other)
|
|
|
|
{
|
|
|
|
return Value.Equals(other.Value) && Unit == other.Unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-20 07:32:47 +01:00
|
|
|
public static YogaValue Undefined()
|
|
|
|
{
|
|
|
|
return new YogaValue
|
|
|
|
{
|
|
|
|
Value = YogaConstants.Undefined,
|
|
|
|
isDefined = 0,
|
|
|
|
Unit = YogaUnit.Pixel
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
public static YogaValue Percent(float value)
|
|
|
|
{
|
|
|
|
return new YogaValue
|
|
|
|
{
|
|
|
|
Value = value,
|
2016-12-20 07:32:47 +01:00
|
|
|
isDefined = YogaConstants.IsUndefined(value) ? (byte)0 : (byte)1,,
|
2016-12-19 23:01:31 +01:00
|
|
|
Unit = YogaUnit.Percent
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static implicit operator YogaValue(float pixelValue)
|
|
|
|
{
|
|
|
|
return Pixel(pixelValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|