2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 /// The Box is a container that is used to arrange UI components in a linear order.
24 /// <since_tizen> preview </since_tizen>
25 public class Box : Container
27 private Interop.Elementary.BoxLayoutCallback _layoutCallback;
30 /// Creates and initializes a new instance of the Box class.
32 /// <param name="parent">The EvasObject to which the new Box will be attached as a child.</param>
33 /// <since_tizen> preview </since_tizen>
34 public Box(EvasObject parent) : base(parent)
39 /// Sets or gets the IsHorizontal value, which describe the pack direction. Vertical is default.
41 /// <since_tizen> preview </since_tizen>
42 public bool IsHorizontal
46 return Interop.Elementary.elm_box_horizontal_get(RealHandle);
50 Interop.Elementary.elm_box_horizontal_set(RealHandle, value);
55 /// Sets or gets whether the box has to arrange its children homogeneously.
57 /// <since_tizen> preview </since_tizen>
58 public bool IsHomogeneous
62 return Interop.Elementary.elm_box_homogeneous_get(RealHandle);
66 Interop.Elementary.elm_box_homogeneous_set(RealHandle, value);
71 /// Adds an object at the end of the pack list.
74 /// Packs the "content" object into the Box, placing it last in the list of children objects.
75 /// The actual position of the object will get on the screen depending on the layout used.
76 /// If no custom layout is set, it will be at the bottom or right,
77 /// depending if the Box is vertical or horizontal, respectively.
79 /// <param name="content">The oject to be packed.</param>
80 /// <since_tizen> preview </since_tizen>
81 public void PackEnd(EvasObject content)
83 Interop.Elementary.elm_box_pack_end(RealHandle, content);
88 /// Adds a "content" object to the beginning of the pack list.
91 /// Packs the "content" object into the box object, placing it first in the list of children objects.
92 /// The actual position of the object will get on the screen depending on the layout used.
93 /// If no custom layout is set, it will be at the top or left,
94 /// depending if the Box is vertical or horizontal, respectively.
96 /// <param name="content">The object to be packed.</param>
97 /// <since_tizen> preview </since_tizen>
98 public void PackStart(EvasObject content)
100 Interop.Elementary.elm_box_pack_start(RealHandle, content);
105 /// Adds a "content" object to the box after the "after" object.
108 /// This will add the "content" to the box indicated after the object indicated with "after".
109 /// If "after" is not already in the box, the results are undefined.
110 /// After means either to the right of the "after" object or below it, depending on orientation.
112 /// <param name="content">The object will be added in the box.</param>
113 /// <param name="after">The object has been added in the box.</param>
114 /// <since_tizen> preview </since_tizen>
115 public void PackAfter(EvasObject content, EvasObject after)
117 Interop.Elementary.elm_box_pack_after(RealHandle, content, after);
122 /// Adds a "content" object to the box before the "before" object.
125 /// This will add the "content" to the box indicated before the object indicated with "before".
126 /// If "before" is not already in the box, the results are undefined.
127 /// Before means either to the left of the "before" object or below it, depending on orientation.
129 /// <param name="content">The object will be added in the box.</param>
130 /// <param name="before">The object has been added in the box.</param>
131 /// <since_tizen> preview </since_tizen>
132 public void PackBefore(EvasObject content, EvasObject before)
134 Interop.Elementary.elm_box_pack_before(RealHandle, content, before);
139 /// Removes the "content" object from the box without deleting it.
141 /// <param name="content">The object to unpack.</param>
142 /// <since_tizen> preview </since_tizen>
143 public void UnPack(EvasObject content)
145 Interop.Elementary.elm_box_unpack(RealHandle, content);
146 RemoveChild(content);
150 /// Removes all the objects from the Box container.
152 /// <since_tizen> preview </since_tizen>
153 public void UnPackAll()
155 Interop.Elementary.elm_box_unpack_all(RealHandle);
160 /// Whenever any changes that requires the box in object to recalculate the size and position of its elements,
161 /// the function cb will be called to determine what the layout of the children will be.
163 /// <param name="action">The callback function used for layout.</param>
164 /// <since_tizen> preview </since_tizen>
165 public void SetLayoutCallback(Action action)
167 _layoutCallback = (obj, priv, data) =>
171 Interop.Elementary.elm_box_layout_set(RealHandle, _layoutCallback, IntPtr.Zero, null);
175 /// Sets the color of the exact part to the box's layout parent.
177 /// <param name="part">The name of part class, it could be 'bg', 'elm.swllow.content'.</param>
178 /// <param name="color">The color value.</param>
179 /// <since_tizen> preview </since_tizen>
180 public override void SetPartColor(string part, Color color)
182 Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255,
183 color.G * color.A / 255,
184 color.B * color.A / 255,
189 /// Gets the color of the exact part of the box's layout parent.
191 /// <param name="part">The name of part class, it could be 'bg', 'elm.swllow.content'.</param>
192 /// <returns></returns>
193 /// <since_tizen> preview </since_tizen>
194 public override Color GetPartColor(string part)
197 Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a);
198 return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
202 /// Forces the box to recalculate its children packing.
203 /// If any children were added or removed, the box will not calculate the values immediately, rather leaving it to the next main loop iteration.
204 /// While this is great as it would save lots of recalculation, whenever you need to get the position of a just added item, you must force recalculate before doing so.
206 /// <since_tizen> preview </since_tizen>
207 public void Recalculate()
209 Interop.Elementary.elm_box_recalculate(RealHandle);
213 /// Clears the box's of all the children.
214 /// Remove all the elements contained by the box, deleting the respective objects.
216 /// <since_tizen> preview </since_tizen>
219 Interop.Elementary.elm_box_clear(RealHandle);
224 /// Sets or gets the alignment of the whole bounding box of contents.
226 /// <param name="horizontal">Horizontal alignment.</param>
227 /// <param name="vertical">Vertical alignment.</param>
228 /// <since_tizen> preview </since_tizen>
229 public void SetBoxAlignment(double horizontal, double vertical)
231 Interop.Elementary.elm_box_align_set(RealHandle, horizontal, vertical);
235 /// Sets or gets the space (padding) between the box's elements.
237 /// <param name="horizontal">Horizontal padding.</param>
238 /// <param name="vertical">Vertical padding.</param>
239 /// <since_tizen> preview </since_tizen>
240 public void SetPadding(int horizontal, int vertical)
242 Interop.Elementary.elm_box_padding_set(RealHandle, horizontal, vertical);
246 /// Creates a widget handle.
248 /// <param name="parent">Parent EvasObject.</param>
249 /// <returns>Handle IntPtr.</returns>
250 /// <since_tizen> preview </since_tizen>
251 protected override IntPtr CreateHandle(EvasObject parent)
253 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
254 Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
256 RealHandle = Interop.Elementary.elm_box_add(handle);
257 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);