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