Support BackgroundColor API for Table
authorKangho Hur <kangho.hur@samsung.com>
Tue, 6 Dec 2016 11:56:45 +0000 (20:56 +0900)
committerKangho Hur <kangho.hur@samsung.com>
Tue, 6 Dec 2016 11:56:45 +0000 (20:56 +0900)
- this change enable containers (box and table) to use Color.Default

Change-Id: I6b9d1c65e08e2c3692fb881b4217b7397b2a488c

src/ElmSharp/ElmSharp/Container.cs
src/ElmSharp/ElmSharp/Table.cs
test/ElmSharp.Test/ElmSharp.Test.csproj
test/ElmSharp.Test/TC/TableTest1.cs [new file with mode: 0644]

index 0cd27c0..75a1f5c 100644 (file)
@@ -27,6 +27,22 @@ namespace ElmSharp
         {
         }
 
+       public override Color BackgroundColor
+        {
+            set
+            {
+                if(value.IsDefault)
+                {
+                    SetPartColor("bg", Color.Transparent);
+                }
+                else
+                {
+                    SetPartColor("bg", value);
+                }
+                _backgroundColor = value;
+            }
+        }
+
         protected virtual IntPtr GetRealHandle(IntPtr handle)
         {
             return Interop.Elementary.elm_object_part_content_get(handle, "elm.swallow.content");
index 742cfaf..252e6d0 100644 (file)
@@ -31,11 +31,11 @@ namespace ElmSharp
         {
             get
             {
-                return Interop.Elementary.elm_table_homogeneous_get(Handle);
+                return Interop.Elementary.elm_table_homogeneous_get(GetRealHandle(Handle));
             }
             set
             {
-                Interop.Elementary.elm_table_homogeneous_set(Handle, value);
+                Interop.Elementary.elm_table_homogeneous_set(GetRealHandle(Handle), value);
             }
         }
 
@@ -48,7 +48,7 @@ namespace ElmSharp
             set
             {
                 _paddingX = value;
-                Interop.Elementary.elm_table_padding_set(Handle, _paddingX, _paddingY);
+                Interop.Elementary.elm_table_padding_set(GetRealHandle(Handle), _paddingX, _paddingY);
             }
         }
 
@@ -61,7 +61,7 @@ namespace ElmSharp
             set
             {
                 _paddingY = value;
-                Interop.Elementary.elm_table_padding_set(Handle, _paddingX, _paddingY);
+                Interop.Elementary.elm_table_padding_set(GetRealHandle(Handle), _paddingX, _paddingY);
             }
         }
 
@@ -69,7 +69,7 @@ namespace ElmSharp
         {
             if (obj == null)
                 throw new ArgumentNullException("obj");
-            Interop.Elementary.elm_table_pack(Handle, obj, col, row, colspan, rowspan);
+            Interop.Elementary.elm_table_pack(GetRealHandle(Handle), obj, col, row, colspan, rowspan);
             AddChild(obj);
         }
 
@@ -77,19 +77,25 @@ namespace ElmSharp
         {
             if (obj == null)
                 throw new ArgumentNullException("obj");
-            Interop.Elementary.elm_table_unpack(Handle, obj);
+            Interop.Elementary.elm_table_unpack(GetRealHandle(Handle), obj);
             RemoveChild(obj);
         }
 
         public void Clear()
         {
-            Interop.Elementary.elm_table_clear(Handle, false);
+            Interop.Elementary.elm_table_clear(GetRealHandle(Handle), false);
             ClearChildren();
         }
 
         protected override IntPtr CreateHandle(EvasObject parent)
         {
-            return Interop.Elementary.elm_table_add(parent);
+            IntPtr handle = Interop.Elementary.elm_layout_add(parent);
+            Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
+
+            IntPtr realHandle = Interop.Elementary.elm_table_add(handle);
+            Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", realHandle);
+
+            return handle;
         }
     }
 }
index 832a052..b019daa 100644 (file)
@@ -63,6 +63,7 @@
     <Compile Include="TC\GenListTest3.cs" />
     <Compile Include="TC\GenListTest4.cs" />
     <Compile Include="TC\GenListTest6.cs" />
+    <Compile Include="TC\TableTest1.cs" />
     <Compile Include="TC\PerformanceTest.cs" />
     <Compile Include="TC\GenListTest5.cs" />
     <Compile Include="TC\IconTest1.cs" />
diff --git a/test/ElmSharp.Test/TC/TableTest1.cs b/test/ElmSharp.Test/TC/TableTest1.cs
new file mode 100644 (file)
index 0000000..24ca0d6
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using ElmSharp;
+
+namespace ElmSharp.Test
+{
+    public class TableTest1 : TestCaseBase
+    {
+        public override string TestName => "TableTest1";
+        public override string TestDescription => "To test basic operation of Table";
+
+        public override void Run(Window window)
+        {
+            Conformant conformant = new Conformant(window);
+            conformant.Show();
+            Table table = new Table(window) {
+                PaddingX = 10,
+                PaddingY = 10
+            };
+           // table.BackgroundColor = Color.Orange;
+            conformant.SetContent(table);
+            table.Show();
+
+            Button button1 = new Button(window) {
+                Text = "Button (set Color.Oranage)",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1
+            };
+            button1.Clicked += (e,o) =>
+            {
+                table.BackgroundColor = Color.Orange;
+                Console.WriteLine("{0} Clicked! - Button's BG Color : {1}, Table's BG Color : {2}", ((Button)e).Text, ((Button)e).BackgroundColor, table.BackgroundColor);
+            };
+
+            Button button2 = new Button(window) {
+                Text = "Button 2 (set Color.Defalut)",
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1,
+                BackgroundColor = new Color(50, 100, 200, 75)
+            };
+            button2.Clicked += (e, o) =>
+            {
+                table.BackgroundColor = Color.Default;
+                Console.WriteLine("{0} Clicked! - Button's BG Color : {1}, Table's BG Color : {2}", ((Button)e).Text, ((Button)e).BackgroundColor, table.BackgroundColor);
+            };
+
+            table.Pack(button1,0,0,3,3);
+            table.Pack(button2,3,1,1,1);
+
+            button1.Show();
+            button2.Show();
+        }
+    }
+}