Merge "Add API comments for ElmSharp API" into tizen
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Box.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// The Box is a container used to arranges UI components in a linear order.
23     /// </summary>
24     public class Box : Container
25     {
26         private Interop.Elementary.BoxLayoutCallback _layoutCallback;
27
28         /// <summary>
29         /// Creates and initializes a new instance of the Box class.
30         /// </summary>
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)
33         {
34         }
35
36         /// <summary>
37         /// Sets or gets IsHorizontal value which describe pack direction, vertical is default.
38         /// </summary>
39         public bool IsHorizontal
40         {
41             get
42             {
43                 return Interop.Elementary.elm_box_horizontal_get(RealHandle);
44             }
45             set
46             {
47                 Interop.Elementary.elm_box_horizontal_set(RealHandle, value);
48             }
49         }
50
51         /// <summary>
52         /// Adds an object at the end of the pack list.
53         /// </summary>
54         /// <remarks>
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.
59         /// </remarks>
60         /// <param name="content">The oject be packed</param>
61         public void PackEnd(EvasObject content)
62         {
63             Interop.Elementary.elm_box_pack_end(RealHandle, content);
64             AddChild(content);
65         }
66
67         /// <summary>
68         /// Adds an "content" object to the beginning of the pack list.
69         /// </summary>
70         /// <remarks>
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.
75         /// </remarks>
76         /// <param name="content">The object to be packed.</param>
77         public void PackStart(EvasObject content)
78         {
79             Interop.Elementary.elm_box_pack_start(RealHandle, content);
80             AddChild(content);
81         }
82
83         /// <summary>
84         /// Adds an "content "object to the Box after the "after" object.
85         /// </summary>
86         /// <remarks>
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.
90         /// </remarks>
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)
94         {
95             Interop.Elementary.elm_box_pack_after(RealHandle, content, after);
96             AddChild(content);
97         }
98
99         /// <summary>
100         /// Remove the "content" oject from Box without deleting it.
101         /// </summary>
102         /// <param name="content">The object to unpack</param>
103         public void UnPack(EvasObject content)
104         {
105             Interop.Elementary.elm_box_unpack(RealHandle, content);
106             RemoveChild(content);
107         }
108
109         /// <summary>
110         /// Removes all objects from Box container.
111         /// </summary>
112         public void UnPackAll()
113         {
114             Interop.Elementary.elm_box_unpack_all(RealHandle);
115             ClearChildren();
116         }
117
118         /// <summary>
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.
121         /// </summary>
122         /// <param name="action">The callback function used for layout </param>
123         public void SetLayoutCallback(Action action)
124         {
125             _layoutCallback = (obj, priv, data) =>
126             {
127                 action();
128             };
129             Interop.Elementary.elm_box_layout_set(RealHandle, _layoutCallback, IntPtr.Zero, null);
130         }
131
132         /// <summary>
133         /// Sets the color of exact part to Box's layout parent.
134         /// </summary>
135         /// <param name="part">The name of part class, it could be 'bg', 'elm.swllow.content'.</param>
136         /// <param name="color">The color value.</param>
137         public override void SetPartColor(string part, Color color)
138         {
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,
142                                                                               color.A);
143         }
144
145         /// <summary>
146         /// Gets the color of exact part of Box's layout parent.
147         /// </summary>
148         /// <param name="part">The name of part class, it could be 'bg', 'elm.swllow.content'.</param>
149         /// <returns></returns>
150         public override Color GetPartColor(string part)
151         {
152             int r, g, b, a;
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);
155         }
156
157         protected override IntPtr CreateHandle(EvasObject parent)
158         {
159             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
160             Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
161
162             RealHandle = Interop.Elementary.elm_box_add(handle);
163             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
164
165             return handle;
166         }
167     }
168 }