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 used to arranges UI components in a linear order.
24 public class Box : Container
26 private Interop.Elementary.BoxLayoutCallback _layoutCallback;
29 /// Creates and initializes a new instance of the Box class.
31 /// <param name="parent">The EvasObject to which the new Box will be attached as a child.</param>
32 public Box(EvasObject parent) : base(parent)
37 /// Sets or gets IsHorizontal value which describe pack direction, vertical is default.
39 public bool IsHorizontal
43 return Interop.Elementary.elm_box_horizontal_get(RealHandle);
47 Interop.Elementary.elm_box_horizontal_set(RealHandle, value);
52 /// Sets or gets whether the box to arrange its children homogeneously.
54 public bool IsHomogeneous
58 return Interop.Elementary.elm_box_homogeneous_get(RealHandle);
62 Interop.Elementary.elm_box_homogeneous_set(RealHandle, value);
67 /// Adds an object at the end of the pack list.
70 /// Packs "content" object into the Box, placing it last in the list of children objects.
71 /// The actual position the object will get on screen depends on the layout used.
72 /// If no custom layout is set, it will be at the bottom or right,
73 /// depending if the Box is vertical or horizontal, respectively.
75 /// <param name="content">The oject be packed</param>
76 public void PackEnd(EvasObject content)
78 Interop.Elementary.elm_box_pack_end(RealHandle, content);
83 /// Adds an "content" object to the beginning of the pack list.
86 /// Pack "content" object into the Box obj, placing it first in the list of children objects.
87 /// The actual position the object will get on screen depends on the layout used.
88 /// If no custom layout is set, it will be at the top or left,
89 /// depending if the Box is vertical or horizontal, respectively.
91 /// <param name="content">The object to be packed.</param>
92 public void PackStart(EvasObject content)
94 Interop.Elementary.elm_box_pack_start(RealHandle, content);
99 /// Adds an "content "object to the Box after the "after" object.
102 /// This will add the "content" to the Box indicated after the object indicated with "after".
103 /// If "after" is not already in the Box, results are undefined.
104 /// After means either to the right of the "after" object or below it depending on orientation.
106 /// <param name="content">The object will be added in Box</param>
107 /// <param name="after">The object has been added in Box</param>
108 public void PackAfter(EvasObject content, EvasObject after)
110 Interop.Elementary.elm_box_pack_after(RealHandle, content, after);
115 /// Adds an "content "object to the Box before the "before" object.
118 /// This will add the "content" to the Box indicated before the object indicated with "before".
119 /// If "before" is not already in the Box, results are undefined.
120 /// before means either to the left of the "before" object or below it depending on orientation.
122 /// <param name="content">The object will be added in Box</param>
123 /// <param name="before">The object has been added in Box</param>
124 public void PackBefore(EvasObject content, EvasObject before)
126 Interop.Elementary.elm_box_pack_before(RealHandle, content, before);
131 /// Remove the "content" oject from Box without deleting it.
133 /// <param name="content">The object to unpack</param>
134 public void UnPack(EvasObject content)
136 Interop.Elementary.elm_box_unpack(RealHandle, content);
137 RemoveChild(content);
141 /// Removes all objects from Box container.
143 public void UnPackAll()
145 Interop.Elementary.elm_box_unpack_all(RealHandle);
150 /// Whenever anything changes that requires the Box in obj to recalculate the size and position of its elements,
151 /// the function cb will be called to determine what the layout of the children will be.
153 /// <param name="action">The callback function used for layout </param>
154 public void SetLayoutCallback(Action action)
156 _layoutCallback = (obj, priv, data) =>
160 Interop.Elementary.elm_box_layout_set(RealHandle, _layoutCallback, IntPtr.Zero, null);
164 /// Sets the color of exact part to Box's layout parent.
166 /// <param name="part">The name of part class, it could be 'bg', 'elm.swllow.content'.</param>
167 /// <param name="color">The color value.</param>
168 public override void SetPartColor(string part, Color color)
170 Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255,
171 color.G * color.A / 255,
172 color.B * color.A / 255,
177 /// Gets the color of exact part of Box's layout parent.
179 /// <param name="part">The name of part class, it could be 'bg', 'elm.swllow.content'.</param>
180 /// <returns></returns>
181 public override Color GetPartColor(string part)
184 Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a);
185 return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
189 /// Force the box to recalculate its children packing.
190 /// If any children was added or removed, box will not calculate the values immediately rather leaving it to the next main loop iteration.
191 /// 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.
193 public void Recalculate()
195 Interop.Elementary.elm_box_recalculate(RealHandle);
199 /// Clear the box of all children.
200 /// Remove all the elements contained by the box, deleting the respective objects.
204 Interop.Elementary.elm_box_clear(RealHandle);
209 /// Sets or gets the alignment of the whole bounding box of contents.
211 /// <param name="horizontal">Horizontal alignment</param>
212 /// <param name="vertical">Vertical alignment</param>
213 public void SetBoxAlignment(double horizontal, double vertical)
215 Interop.Elementary.elm_box_align_set(RealHandle, horizontal, vertical);
219 /// Sets or gets the space(padding) between the box's elements.
221 /// <param name="horizontal">Horizontal padding</param>
222 /// <param name="vertical">vertical padding</param>
223 public void SetPadding(int horizontal, int vertical)
225 Interop.Elementary.elm_box_padding_set(RealHandle, horizontal, vertical);
229 /// Creates a widget handle.
231 /// <param name="parent">Parent EvasObject</param>
232 /// <returns>Handle IntPtr</returns>
233 protected override IntPtr CreateHandle(EvasObject parent)
235 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
236 Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
238 RealHandle = Interop.Elementary.elm_box_add(handle);
239 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);