[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Table.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 Table is a container widget to arrange other widgets in a table where items can span multiple columns or rows.
23     /// Inherits <see cref="Container"/>.
24     /// </summary>
25     /// <since_tizen> preview </since_tizen>
26     public class Table : Container
27     {
28         int _paddingX = 0;
29         int _paddingY = 0;
30
31         /// <summary>
32         /// Creates and initializes a new instance of the Table class.
33         /// </summary>
34         /// <param name="parent">
35         /// A <see cref="EvasObject"/> to which the new Table instance will be attached.
36         /// </param>
37         /// <since_tizen> preview </since_tizen>
38         public Table(EvasObject parent) : base(parent)
39         {
40         }
41
42         /// <summary>
43         /// Sets or gets whether the layout of this table is homogeneous.
44         /// </summary>
45         /// <remarks>True for homogeneous, False for no homogeneous.</remarks>
46         /// <since_tizen> preview </since_tizen>
47         public bool Homogeneous
48         {
49             get
50             {
51                 return Interop.Elementary.elm_table_homogeneous_get(RealHandle);
52             }
53             set
54             {
55                 Interop.Elementary.elm_table_homogeneous_set(RealHandle, value);
56             }
57         }
58
59         /// <summary>
60         /// Sets or gets the horizontal padding between the cells.
61         /// </summary>
62         /// <since_tizen> preview </since_tizen>
63         public int PaddingX
64         {
65             get
66             {
67                 return _paddingX;
68             }
69             set
70             {
71                 _paddingX = value;
72                 Interop.Elementary.elm_table_padding_set(RealHandle, _paddingX, _paddingY);
73             }
74         }
75
76         /// <summary>
77         /// Sets or gets the vertical padding between the cells.
78         /// </summary>
79         /// <since_tizen> preview </since_tizen>
80         public int PaddingY
81         {
82             get
83             {
84                 return _paddingY;
85             }
86             set
87             {
88                 _paddingY = value;
89                 Interop.Elementary.elm_table_padding_set(RealHandle, _paddingX, _paddingY);
90             }
91         }
92         /// <summary>
93         /// Adds a subobject on the table with the coordinates passed.
94         /// </summary>
95         /// <param name="obj">The subobject to be added to the table.</param>
96         /// <param name="col">The column number.</param>
97         /// <param name="row">The row number.</param>
98         /// <param name="colspan">The column span.</param>
99         /// <param name="rowspan">The row span.</param>
100         /// <since_tizen> preview </since_tizen>
101         public void Pack(EvasObject obj, int col, int row, int colspan, int rowspan)
102         {
103             if (obj == null)
104                 throw new ArgumentNullException("obj");
105             Interop.Elementary.elm_table_pack(RealHandle, obj, col, row, colspan, rowspan);
106             AddChild(obj);
107         }
108
109         /// <summary>
110         /// Removes the child from the table.
111         /// </summary>
112         /// <param name="obj">The subobject.</param>
113         /// <since_tizen> preview </since_tizen>
114         public void Unpack(EvasObject obj)
115         {
116             if (obj == null)
117                 throw new ArgumentNullException("obj");
118             Interop.Elementary.elm_table_unpack(RealHandle, obj);
119             RemoveChild(obj);
120         }
121
122         /// <summary>
123         /// Removes all the child objects from a table object.
124         /// </summary>
125         /// <since_tizen> preview </since_tizen>
126         public void Clear()
127         {
128             Interop.Elementary.elm_table_clear(RealHandle, false);
129             ClearChildren();
130         }
131
132         /// <summary>
133         /// Sets the color for a particular part of the table.
134         /// </summary>
135         /// <param name="part">The name of part class.</param>
136         /// <param name="color">The color.</param>
137         /// <since_tizen> preview </since_tizen>
138         public override void SetPartColor(string part, Color color)
139         {
140             Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255,
141                                                                               color.G * color.A / 255,
142                                                                               color.B * color.A / 255,
143                                                                               color.A);
144         }
145
146         /// <summary>
147         /// Gets the color of a particular part of the table.
148         /// </summary>
149         /// <param name="part">The name of part class, it could be 'bg', 'elm.swllow.content'.</param>
150         /// <returns>The color of a particular part.</returns>
151         /// <since_tizen> preview </since_tizen>
152         public override Color GetPartColor(string part)
153         {
154             int r, g, b, a;
155             Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a);
156             return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
157         }
158
159         /// <summary>
160         /// Creates a widget handle.
161         /// </summary>
162         /// <param name="parent">Parent EvasObject.</param>
163         /// <returns>Handle IntPtr.</returns>
164         /// <since_tizen> preview </since_tizen>
165         protected override IntPtr CreateHandle(EvasObject parent)
166         {
167             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
168             Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
169
170             RealHandle = Interop.Elementary.elm_table_add(handle);
171             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
172
173             return handle;
174         }
175     }
176 }