5e1416203f95a184c71ca77b2a0bbbf80d7f37ec
[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     public class Table : Container
22     {
23         int _paddingX = 0;
24         int _paddingY = 0;
25
26         public Table(EvasObject parent) : base(parent)
27         {
28         }
29
30         public bool Homogeneous
31         {
32             get
33             {
34                 return Interop.Elementary.elm_table_homogeneous_get(RealHandle);
35             }
36             set
37             {
38                 Interop.Elementary.elm_table_homogeneous_set(RealHandle, value);
39             }
40         }
41
42         public int PaddingX
43         {
44             get
45             {
46                 return _paddingX;
47             }
48             set
49             {
50                 _paddingX = value;
51                 Interop.Elementary.elm_table_padding_set(RealHandle, _paddingX, _paddingY);
52             }
53         }
54
55         public int PaddingY
56         {
57             get
58             {
59                 return _paddingY;
60             }
61             set
62             {
63                 _paddingY = value;
64                 Interop.Elementary.elm_table_padding_set(RealHandle, _paddingX, _paddingY);
65             }
66         }
67
68         public void Pack(EvasObject obj, int col, int row, int colspan, int rowspan)
69         {
70             if (obj == null)
71                 throw new ArgumentNullException("obj");
72             Interop.Elementary.elm_table_pack(RealHandle, obj, col, row, colspan, rowspan);
73             AddChild(obj);
74         }
75
76         public void Unpack(EvasObject obj)
77         {
78             if (obj == null)
79                 throw new ArgumentNullException("obj");
80             Interop.Elementary.elm_table_unpack(RealHandle, obj);
81             RemoveChild(obj);
82         }
83
84         public void Clear()
85         {
86             Interop.Elementary.elm_table_clear(RealHandle, false);
87             ClearChildren();
88         }
89
90         public override void SetPartColor(string part, Color color)
91         {
92             Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255,
93                                                                               color.G * color.A / 255,
94                                                                               color.B * color.A / 255,
95                                                                               color.A);
96         }
97
98         public override Color GetPartColor(string part)
99         {
100             int r, g, b, a;
101             Interop.Elementary.elm_object_color_class_color_get(Handle, part, out r, out g, out b, out a);
102             return new Color((int)(r / (a / 255.0)), (int)(g / (a / 255.0)), (int)(b / (a / 255.0)), a);
103         }
104
105         protected override IntPtr CreateHandle(EvasObject parent)
106         {
107             IntPtr handle = Interop.Elementary.elm_layout_add(parent);
108             Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
109
110             RealHandle = Interop.Elementary.elm_table_add(handle);
111             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
112
113             return handle;
114         }
115     }
116 }