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 /// Adds an object at the end of the pack list.
55 /// Packs "content" object into the Box, placing it last in the list of children objects.
56 /// The actual position the object will get on screen depends on the layout used.
57 /// If no custom layout is set, it will be at the bottom or right,
58 /// depending if the Box is vertical or horizontal, respectively.
60 /// <param name="content">The oject be packed</param>
61 public void PackEnd(EvasObject content)
63 Interop.Elementary.elm_box_pack_end(RealHandle, content);
68 /// Adds an "content" object to the beginning of the pack list.
71 /// Pack "content" object into the Box obj, placing it first in the list of children objects.
72 /// The actual position the object will get on screen depends on the layout used.
73 /// If no custom layout is set, it will be at the top or left,
74 /// depending if the Box is vertical or horizontal, respectively.
76 /// <param name="content">The object to be packed.</param>
77 public void PackStart(EvasObject content)
79 Interop.Elementary.elm_box_pack_start(RealHandle, content);
84 /// Adds an "content "object to the Box after the "after" object.
87 /// This will add the "content" to the Box indicated after the object indicated with "after".
88 /// If "after" is not already in the Box, results are undefined.
89 /// After means either to the right of the "after" object or below it depending on orientation.
91 /// <param name="content">The object will be added in Box</param>
92 /// <param name="after">The object has been added in Box</param>
93 public void PackAfter(EvasObject content, EvasObject after)
95 Interop.Elementary.elm_box_pack_after(RealHandle, content, after);
100 /// Remove the "content" oject from Box without deleting it.
102 /// <param name="content">The object to unpack</param>
103 public void UnPack(EvasObject content)
105 Interop.Elementary.elm_box_unpack(RealHandle, content);
106 RemoveChild(content);
110 /// Removes all objects from Box container.
112 public void UnPackAll()
114 Interop.Elementary.elm_box_unpack_all(RealHandle);
119 /// Whenever anything changes that requires the Box in obj to recalculate the size and position of its elements,
120 /// the function cb will be called to determine what the layout of the children will be.
122 /// <param name="action">The callback function used for layout </param>
123 public void SetLayoutCallback(Action action)
125 _layoutCallback = (obj, priv, data) =>
129 Interop.Elementary.elm_box_layout_set(RealHandle, _layoutCallback, IntPtr.Zero, null);
133 /// Sets the color of color class to Box's layout parent.
135 /// <param name="part">The name of color class. </param>
136 /// <param name="color">The color value.</param>
137 public override void SetPartColor(string part, Color color)
139 Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255,
140 color.G * color.A / 255,
141 color.B * color.A / 255,
146 /// Get the color of color class of Box's layout parent.
148 /// <param name="part">The name of color class.</param>
149 /// <returns></returns>
150 public override Color GetPartColor(string part)
153 Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a);
154 return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
157 protected override IntPtr CreateHandle(EvasObject parent)
159 IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
160 Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
162 RealHandle = Interop.Elementary.elm_box_add(handle);
163 Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);