X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Flayouting%2Flayout-length.h;h=6004b77e3a8600f71ae3f2b1820597ba29aad319;hb=b8c53c32af48487b8d5178425ecf8f801e44ad4d;hp=94f7ae09edb525b6f74563f2d5bde54e561c527b;hpb=16634ab902b66b0ba2f3f39af8ff6ed25b5f7115;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/devel-api/layouting/layout-length.h b/dali-toolkit/devel-api/layouting/layout-length.h index 94f7ae0..6004b77 100644 --- a/dali-toolkit/devel-api/layouting/layout-length.h +++ b/dali-toolkit/devel-api/layouting/layout-length.h @@ -16,163 +16,295 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +// EXTERNAL INCLUDES #include +#include #include namespace Dali { + namespace Toolkit { /** * @brief A type that represents a layout length. * - * Currently, this implies pixels, but could be extended to handle device dependant sizes, etc. + * Currently, this implies pixels, but could be extended to handle device dependent sizes, etc. */ class LayoutLength { public: - using IntType = int; - - LayoutLength( IntType value ) - : mValue( value ) - { - } - - LayoutLength( const LayoutLength& layoutLength ) - : mValue( layoutLength.mValue ) - { - } - - LayoutLength& operator=(const LayoutLength& rhs) - { - mValue = rhs.mValue; - return *this; - } - bool operator==( const LayoutLength& rhs ) + /** + * @brief default constructor, initialises to 0 + */ + LayoutLength() + : mValue( 0 ) { - return mValue == rhs.mValue; } - bool operator==( LayoutLength::IntType rhs ) - { - return mValue == rhs; - } - - bool operator!=( const LayoutLength& rhs ) - { - return !operator==(rhs); - } - - bool operator<( const LayoutLength& rhs ) + /** + * @brief constructor + * + * @param value the value to initialise with + */ + LayoutLength( int value ) + : mValue( value ) { - return mValue < rhs.mValue; } - bool operator<( const LayoutLength rhs ) const + /** + * @brief constructor from float + * + * @param value the value to initialise with + */ + LayoutLength( float value ) + : mValue( value ) { - return mValue < rhs.mValue; } - bool operator<=( const LayoutLength& rhs ) - { - return mValue <= rhs.mValue; - } - bool operator<=( LayoutLength rhs ) - { - return mValue <= rhs.mValue; - } - bool operator>( const LayoutLength& rhs ) - { - return mValue > rhs.mValue; - } - bool operator>( LayoutLength rhs ) - { - return mValue > rhs.mValue; - } - bool operator>=( const LayoutLength& rhs ) - { - return mValue >= rhs.mValue; - } - bool operator>=( LayoutLength rhs ) + /** + * @brief constructor + * + * @param layoutLength the value to initialise with + */ + LayoutLength( const LayoutLength& layoutLength ) + : mValue( layoutLength.mValue ) { - return mValue >= rhs.mValue; } - LayoutLength operator+( const LayoutLength& rhs ) + /** + * @brief assignment operator + * + * @param rhs LayoutLength to assign + * @return reference to itself + */ + LayoutLength& operator=( const LayoutLength& rhs ) { - return mValue + rhs.mValue; + if( this != &rhs ) + { + mValue = rhs.mValue; + } + return *this; } - LayoutLength operator+( LayoutLength::IntType rhs ) + /** + * @brief assignment operator from int + * + * @param value the value to assign + * @return reference to itself + */ + LayoutLength& operator=( int value ) { - return mValue + rhs; + mValue = value; + return *this; } - LayoutLength operator-( const LayoutLength& rhs ) - { - return mValue - rhs.mValue; - } - LayoutLength operator-( LayoutLength::IntType rhs ) + /** + * @brief assignment operator from float + * + * @param value the value to assign + * @return reference to itself + */ + LayoutLength& operator=( float value ) { - return mValue - rhs; + mValue = value; + return *this; } - LayoutLength& operator+=( const LayoutLength& rhs ) + /** + * @brief plus equals operator + * + * @param rhs to add to this + * @return reference to itself + */ + LayoutLength& operator+=( LayoutLength rhs ) { mValue += rhs.mValue; return *this; } - LayoutLength& operator+=( LayoutLength::IntType rhs ) - { - mValue += rhs; - return *this; - } - LayoutLength& operator-=( const LayoutLength& rhs ) + /** + * @brief minus equals operator + * + * @param rhs to subtract from this + * @return reference to itself + */ + LayoutLength& operator-=( LayoutLength rhs ) { mValue -= rhs.mValue; return *this; } - LayoutLength& operator-=( LayoutLength::IntType rhs ) + /** + * @brief return value as decimal value (full raw value) + * + * @return the LayoutLength as full decimal value + */ + float AsDecimal() const { - mValue -= rhs; - return *this; + return mValue; } - LayoutLength operator/( const LayoutLength& rhs ) - { - return mValue / rhs.mValue; - } - LayoutLength operator/( LayoutLength::IntType rhs ) + /** + * @brief return value as rounded integer value (whole number) + * + * @return the LayoutLength rounded to next integer value + */ + float AsInteger() const { - return mValue / rhs; + return round( mValue ); } - LayoutLength operator*( const LayoutLength& rhs ) - { - return mValue * rhs.mValue; - } - LayoutLength operator*( LayoutLength::IntType rhs ) - { - return mValue * rhs; - } - LayoutLength operator*( float rhs ) + /** + * @brief return value as truncated integral value (whole number) + * + * @return the LayoutLength rounded to next integral value + */ + float AsTruncated() const { - return LayoutLength(LayoutLength::IntType(float(mValue) * rhs)); + return trunc( mValue ); } - operator float() - { - return float( mValue ); - } +private: + + float mValue; - IntType mValue; }; /** + * @brief equal to operator + * + * @param lhs value to compare + * @param rhs value to compare against + * @note Using value instead of reference to allow conversions from int and float + * @return true if identical, false otherwise + */ +inline bool operator==( LayoutLength lhs, LayoutLength rhs ) +{ + return lhs.AsDecimal() == rhs.AsDecimal(); +} + +/** + * @brief not equal to operator + * + * @param lhs value to compare + * @param rhs value to compare against + * @note Using value instead of reference to allow conversions from int and float + * @return true if value is not identical, false otherwise + */ +inline bool operator!=( LayoutLength lhs, LayoutLength rhs ) +{ + return !operator==( lhs, rhs ); +} + +/** + * @brief less than operator + * + * @param lhs value to compare + * @param rhs value to compare against + * @note Using value instead of reference to allow conversions from int and float + * @return true if lhs value is less, false otherwise + */ +inline bool operator<( LayoutLength lhs, LayoutLength rhs ) +{ + return lhs.AsDecimal() < rhs.AsDecimal(); +} + +/** + * @brief greater than operator + * + * @param lhs value to compare + * @param rhs value to compare against + * @note Using value instead of reference to allow conversions from int and float + * @return true if lhs value is greater, false otherwise + */ +inline bool operator>( LayoutLength lhs, LayoutLength rhs ) +{ + return rhs < lhs; +} + +/** + * @brief less than or equal to operator + * + * @param lhs value to compare + * @param rhs value to compare against + * @note Using value instead of reference to allow conversions from int and float + * @return true if lhs value is less than or equal to, false otherwise + */ +inline bool operator<=( LayoutLength lhs, LayoutLength rhs ) +{ + return !(lhs > rhs); +} + +/** + * @brief greater than or equal to operator + * + * @param lhs value to compare + * @param rhs value to compare against + * @note Using value instead of reference to allow conversions from int and float + * @return true if lhs value is greater than or equal to, false otherwise + */ +inline bool operator>=( LayoutLength lhs, LayoutLength rhs ) +{ + return !(lhs < rhs); +} + +/** + * @brief add two LayoutLengths + * + * @param lhs The LayoutLength to add + * @param rhs The LayoutLength to add + * @note Using value instead of reference to allow conversions from int and float + * @return the resulting LayoutLength + */ +inline LayoutLength operator+( LayoutLength lhs, LayoutLength rhs ) +{ + return lhs.AsDecimal() + rhs.AsDecimal(); +} + +/** + * @brief subtract two LayoutLengths + * + * @param lhs The LayoutLength to subtract from + * @param rhs The LayoutLength to subtract + * @note Using value instead of reference to allow conversions from int and float + * @return the resulting LayoutLength + */ +inline LayoutLength operator-( LayoutLength lhs, LayoutLength rhs ) +{ + return lhs.AsDecimal() - rhs.AsDecimal(); +} + +/** + * @brief multiply two LayoutLengths + * + * @param lhs The LayoutLength to multiply + * @param rhs The LayoutLength to multiply + * @note Using value instead of reference to allow conversions from int and float + * @return the resulting LayoutLength + */ +inline LayoutLength operator*( LayoutLength lhs, LayoutLength rhs ) +{ + return lhs.AsDecimal() * rhs.AsDecimal(); +} + +/** + * @brief divide LayoutLength by a LayoutLength + * + * @param lhs The LayoutLength to divide + * @param rhs The LayoutLength to divide by + * @note Using value instead of reference to allow conversions from int and float + * @return the resulting value as float + */ +inline LayoutLength operator/( LayoutLength lhs, LayoutLength rhs ) +{ + return lhs.AsDecimal() / rhs.AsDecimal(); +} + +/** * @brief Prints a LayoutLength * * @param[in] o The output stream operator @@ -181,7 +313,7 @@ public: */ inline std::ostream& operator<<( std::ostream& o, const LayoutLength& layoutLength ) { - return o<