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.
20 #include <dali-toolkit/public-api/dali-toolkit-common.h>
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali-toolkit/devel-api/layouting/layout-length.h>
23 #include <dali-toolkit/public-api/dali-toolkit-common.h>
33 * A MeasureSpec is used during the Measure pass by a LayoutGroup to inform it's children
34 * how to be measured. For instance, it may measure a child with an exact width and an unspecified
35 * height in order to determine height for width.
37 class DALI_TOOLKIT_API MeasureSpec
40 using IntType = LayoutLength::IntType;
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.mValue ),
57 MeasureSpec( IntType 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 Get the mode of the measure spec.
88 * @return The mode of the measure spec
90 MeasureSpec::Mode GetMode() const
96 * @brief Get the size of the measure spec
98 * @return the size of the measure spec
100 IntType GetSize() const
106 * @brief Adjust the measure size by the given delta.
108 * Used only for EXACT and AT_MOST modes.
109 * @param[in] measureSpec the measure spec to adjust
110 * @param[in] delta A positive or negative value to adjust the measure spec by.
112 * @note if the adjusted size is negative, it is zeroed.
113 * @return A new measure spec with the adjusted values.
115 static MeasureSpec Adjust( MeasureSpec measureSpec, int delta )
117 auto mode = measureSpec.GetMode();
118 auto size = measureSpec.GetSize();
120 if( mode == MeasureSpec::Mode::UNSPECIFIED )
122 return MeasureSpec( size, MeasureSpec::Mode::UNSPECIFIED );
125 if( delta < 0 && measureSpec.mSize < static_cast<IntType>(abs(delta)) )
133 return MeasureSpec( size, mode );
137 IntType mSize; ///< The specified size
138 Mode mMode; ///< The measure mode
141 inline std::ostream& operator<< (std::ostream& o, const MeasureSpec& measureSpec )
143 return o << ( (measureSpec.GetMode() == MeasureSpec::Mode::UNSPECIFIED ? "Unspecified"
144 : (measureSpec.GetMode() == MeasureSpec::Mode::EXACTLY ? "Exactly":"At most" ) ) )
145 << " " << measureSpec.GetSize();
148 } //namespace Toolkit
152 #endif // DALI_TOOLKIT_LAYOUTING_MEASURE_SPEC_H