/*
* Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.ComponentModel;
using Tizen.NUI.BaseComponents;
namespace Tizen.NUI
{
///
/// [Draft] A type that represents a layout length. Currently, this implies pixels, but could be extended to handle device dependant sizes, etc.
///
internal struct LayoutLength
{
private float _value;
///
/// [Draft] Constructor from an int
///
/// Int to initialize with.
public LayoutLength(int value)
{
_value = value;
}
///
/// [Draft] Constructor from a float
///
/// Float to initialize with.
public LayoutLength(float value)
{
_value = value;
}
///
/// [Draft] Constructor from a LayoutLength
///
/// LayoutLength object to initialize with.
public LayoutLength(LayoutLength layoutLength)
{
_value = layoutLength._value;
}
///
/// [Draft] Return value as rounded value (whole number), best used as final output
///
/// The layout length value as a rounded whole number.
public float AsRoundedValue()
{
return (float)Math.Round((decimal)_value, MidpointRounding.AwayFromZero);
}
///
/// [Draft] Return value as the raw decimal value, best used for calculations
///
/// The layout length value as the raw decimal value.
public float AsDecimal()
{
return _value;
}
///
/// [Draft] The == operator.
///
/// The first value.
/// The second value
/// true if LayoutLengths are equal
public static bool operator ==(LayoutLength arg1, LayoutLength arg2)
{
return arg1.Equals(arg2);
}
///
/// [Draft] The != operator.
///
/// The first value.
/// The second value
/// true if LayoutLengths are not equal
public static bool operator !=(LayoutLength arg1, LayoutLength arg2)
{
return !arg1.Equals(arg2);
}
///
/// Determines whether the specified object is equal to the current object.
///
/// The object to compare with the current object.
/// true if equal LayoutLength, else false.
public override bool Equals(object obj)
{
if (obj is LayoutLength)
{
return this.Equals((LayoutLength)obj);
}
return false;
}
///
/// Determines whether the specified object is equal to the current object.
///
/// The LayoutLength to compare with the current LayoutLength.
/// true if equal LayoutLengths, else false.
public bool Equals(LayoutLength layoutLength)
{
return (Math.Abs(_value - layoutLength._value ) <= float.Epsilon);
}
///
/// A hash code for the current object.
///
public override int GetHashCode()
{
return (int)Math.Ceiling(_value);
}
///
/// The addition operator.
///
/// The first value.
/// The second value.
/// The LayoutLength containing the result of the addition.
public static LayoutLength operator +(LayoutLength arg1, LayoutLength arg2)
{
return new LayoutLength( arg1._value + arg2._value );
}
///
/// The addition operator.
///
/// The first value.
/// The second value.
/// The LayoutLength containing the result of the addition.
public static LayoutLength operator +(LayoutLength arg1, int arg2)
{
return new LayoutLength(arg1._value + (float)arg2);
}
///
/// The subtraction operator.
///
/// The first value.
/// The second value.
/// The LayoutLength containing the result of the subtraction.
public static LayoutLength operator -(LayoutLength arg1, LayoutLength arg2)
{
return new LayoutLength(arg1._value - arg2._value);
}
///
/// The subtraction operator.
///
/// The first value.
/// The second value.
/// The LayoutLength containing the result of the subtraction.
public static LayoutLength operator -(LayoutLength arg1, int arg2)
{
return new LayoutLength(arg1._value - (float)arg2);
}
///
/// The multiplication operator.
///
/// The first value.
/// The second value.
/// The LayoutLength containing the result of the multiplication.
public static LayoutLength operator *(LayoutLength arg1, LayoutLength arg2)
{
return new LayoutLength(arg1._value * arg2._value);
}
///
/// Th multiplication operator.
///
/// The first value.
/// The int value to scale the LayoutLength.
/// The LayoutLength containing the result of the scaling.
public static LayoutLength operator *(LayoutLength arg1, int arg2)
{
return new LayoutLength(arg1._value * arg2);
}
///
/// The division operator.
///
/// The first value.
/// The second value.
/// The LayoutLength containing the result of the division.
public static LayoutLength operator /(LayoutLength arg1, LayoutLength arg2)
{
return new LayoutLength(arg1._value / arg2._value);
}
///
/// Th division operator.
///
/// The first value.
/// The int value to scale the vector by.
/// The LayoutLength containing the result of the scaling.
public static LayoutLength operator /(LayoutLength arg1, int arg2)
{
return new LayoutLength(arg1._value / (float)arg2);
}
}
}