1 #ifndef DALI_TOOLKIT_LAYOUTING_MEASURE_SPEC_H
2 #define DALI_TOOLKIT_LAYOUTING_MEASURE_SPEC_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/dali-common.h>
25 #include <dali-toolkit/devel-api/layouting/layout-length.h>
26 #include <dali-toolkit/public-api/dali-toolkit-common.h>
34 * A MeasureSpec is used during the Measure pass by a LayoutGroup to inform it's children
35 * how to be measured. For instance, it may measure a child with an exact width and an unspecified
36 * height in order to determine height for width.
38 class DALI_TOOLKIT_API MeasureSpec
44 UNSPECIFIED, ///< This is used by a parent to determine the desired dimension of a child layout.
45 EXACTLY, /** This is used by a parent to impose an exact size on the child. The child must use
46 this size, and guarantee that all of its descendants will fit within this size */
47 AT_MOST /** This is used by the parent to impose a maximum size on the child. The child must guarantee
48 * that it and all of it's descendants will fit within this size. */
51 MeasureSpec( LayoutLength measureSpec, MeasureSpec::Mode mode )
52 : mSize( measureSpec ),
57 MeasureSpec( LayoutLength measureSpec )
58 : mSize( measureSpec ),
59 mMode( Mode::UNSPECIFIED )
63 ~MeasureSpec() = default;
65 MeasureSpec& operator=( const MeasureSpec& rhs )
69 this->mSize = rhs.mSize;
70 this->mMode = rhs.mMode;
75 bool operator==( MeasureSpec value )
77 return mSize == value.mSize;
80 bool operator!=( MeasureSpec value )
82 return mSize != value.mSize;
86 * @brief Set the mode of the measure spec.
88 * @param mode The mode to set
90 void SetMode( MeasureSpec::Mode mode )
96 * @brief Get the mode of the measure spec.
98 * @return The mode of the measure spec
100 MeasureSpec::Mode GetMode() const
106 * @brief Set the size of the measure spec
108 * @param size the size to set
110 void SetSize( LayoutLength size )
116 * @brief Get the size of the measure spec
118 * @return the size of the measure spec
120 LayoutLength GetSize() const
126 * @brief Adjust the measure size by the given delta.
128 * Used only for EXACT and AT_MOST modes.
129 * @param[in] measureSpec the measure spec to adjust
130 * @param[in] delta A positive or negative value to adjust the measure spec by.
132 * @note if the adjusted size is negative, it is zeroed.
133 * @return A new measure spec with the adjusted values.
135 static MeasureSpec Adjust( MeasureSpec measureSpec, int delta )
137 auto mode = measureSpec.GetMode();
138 auto size = measureSpec.GetSize();
140 if( mode == MeasureSpec::Mode::UNSPECIFIED )
142 return MeasureSpec( size, MeasureSpec::Mode::UNSPECIFIED );
145 if( delta < 0 && measureSpec.mSize < abs(delta) )
153 return MeasureSpec( size, mode );
158 LayoutLength mSize; ///< The specified size
159 Mode mMode; ///< The measure mode
163 inline std::ostream& operator<< (std::ostream& o, const MeasureSpec& measureSpec )
165 return o << ( (measureSpec.GetMode() == MeasureSpec::Mode::UNSPECIFIED ? "Unspecified"
166 : (measureSpec.GetMode() == MeasureSpec::Mode::EXACTLY ? "Exactly":"At most" ) ) )
167 << " " << measureSpec.GetSize();
170 } //namespace Toolkit
174 #endif // DALI_TOOLKIT_LAYOUTING_MEASURE_SPEC_H