From 7a171bc04279c2820cdf782eefe63e68769cf423 Mon Sep 17 00:00:00 2001 From: Kangho Hur Date: Tue, 6 Dec 2016 20:56:45 +0900 Subject: [PATCH] Support BackgroundColor API for Table - this change enable containers (box and table) to use Color.Default Change-Id: I6b9d1c65e08e2c3692fb881b4217b7397b2a488c --- ElmSharp.Test/ElmSharp.Test.csproj | 1 + ElmSharp.Test/TC/TableTest1.cs | 73 ++++++++++++++++++++++++++++++++++++++ ElmSharp/ElmSharp/Container.cs | 16 +++++++++ ElmSharp/ElmSharp/Table.cs | 22 +++++++----- 4 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 ElmSharp.Test/TC/TableTest1.cs diff --git a/ElmSharp.Test/ElmSharp.Test.csproj b/ElmSharp.Test/ElmSharp.Test.csproj index 832a052..b019daa 100644 --- a/ElmSharp.Test/ElmSharp.Test.csproj +++ b/ElmSharp.Test/ElmSharp.Test.csproj @@ -63,6 +63,7 @@ + diff --git a/ElmSharp.Test/TC/TableTest1.cs b/ElmSharp.Test/TC/TableTest1.cs new file mode 100644 index 0000000..24ca0d6 --- /dev/null +++ b/ElmSharp.Test/TC/TableTest1.cs @@ -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(); + } + } +} diff --git a/ElmSharp/ElmSharp/Container.cs b/ElmSharp/ElmSharp/Container.cs index 0cd27c0..75a1f5c 100644 --- a/ElmSharp/ElmSharp/Container.cs +++ b/ElmSharp/ElmSharp/Container.cs @@ -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"); diff --git a/ElmSharp/ElmSharp/Table.cs b/ElmSharp/ElmSharp/Table.cs index 742cfaf..252e6d0 100644 --- a/ElmSharp/ElmSharp/Table.cs +++ b/ElmSharp/ElmSharp/Table.cs @@ -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; } } } -- 2.7.4