1 /* Copyright (c) 2021 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
20 /// [Draft] This class implements a absolute layout, allowing explicit positioning of children.
21 /// Positions are from the top left of the layout and can be set using the View.Position and alike.
23 public class AbsoluteLayout : LayoutGroup
26 /// [Draft] Constructor
28 /// <since_tizen> 6 </since_tizen>
29 public AbsoluteLayout()
34 /// Measure the layout and its content to determine the measured width and the measured height.<br />
36 /// <param name="widthMeasureSpec">horizontal space requirements as imposed by the parent.</param>
37 /// <param name="heightMeasureSpec">vertical space requirements as imposed by the parent.</param>
38 /// <since_tizen> 6 </since_tizen>
39 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
41 // Ensure layout respects it's given minimum size
42 float maxWidth = SuggestedMinimumWidth.AsDecimal();
43 float maxHeight = SuggestedMinimumHeight.AsDecimal();
45 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
46 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
48 foreach (LayoutItem childLayout in IterateLayoutChildren())
50 // Get size of child with no padding, no margin. we won't support margin, padding for AbsolutLayout.
51 MeasureChildWithoutPadding(childLayout, widthMeasureSpec, heightMeasureSpec);
53 // Determine the width and height needed by the children using their given position and size.
54 // Children could overlap so find the right most child.
55 float childRight = childLayout.MeasuredWidth.Size.AsDecimal() + childLayout.Owner.PositionX;
56 float childBottom = childLayout.MeasuredHeight.Size.AsDecimal() + childLayout.Owner.PositionY;
58 if (maxWidth < childRight)
59 maxWidth = childRight;
61 if (maxHeight < childBottom)
62 maxHeight = childBottom;
64 if (childLayout.MeasuredWidth.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
66 childWidthState = MeasuredSize.StateType.MeasuredSizeTooSmall;
68 if (childLayout.MeasuredHeight.State == MeasuredSize.StateType.MeasuredSizeTooSmall)
70 childHeightState = MeasuredSize.StateType.MeasuredSizeTooSmall;
74 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(maxWidth), widthMeasureSpec, childWidthState),
75 ResolveSizeAndState(new LayoutLength(maxHeight), heightMeasureSpec, childHeightState));
79 /// Assign a size and position to each of its children.<br />
81 /// <param name="changed">This is a new size or position for this layout.</param>
82 /// <param name="left">Left position, relative to parent.</param>
83 /// <param name="top"> Top position, relative to parent.</param>
84 /// <param name="right">Right position, relative to parent.</param>
85 /// <param name="bottom">Bottom position, relative to parent.</param>
86 /// <since_tizen> 6 </since_tizen>
87 protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
89 // Absolute layout positions it's children at their Actor positions.
90 // Children could overlap or spill outside the parent, as is the nature of absolute positions.
91 foreach (LayoutItem childLayout in IterateLayoutChildren())
93 LayoutLength childWidth = childLayout.MeasuredWidth.Size;
94 LayoutLength childHeight = childLayout.MeasuredHeight.Size;
96 LayoutLength childLeft = new LayoutLength(childLayout.Owner.PositionX);
97 LayoutLength childTop = new LayoutLength(childLayout.Owner.PositionY);
99 childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight, true);