Support new features of Tizen.CircularUI (#188)
[platform/core/csapi/xsf.git] / src / XSF / Tizen.Wearable.CircularUI.Forms.Renderer / ContentButtonRenderer.cs
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 using Tizen.Wearable.CircularUI.Forms;
19 using Tizen.Wearable.CircularUI.Forms.Renderer;
20 using Xamarin.Forms;
21 using Xamarin.Forms.Platform.Tizen;
22 using Xamarin.Forms.Platform.Tizen.Native;
23 using XForms = Xamarin.Forms.Forms;
24 using XFLayout = Xamarin.Forms.Layout;
25 using EButton = ElmSharp.Button;
26 using EColor = ElmSharp.Color;
27 using System.ComponentModel;
28
29 [assembly: ExportRenderer(typeof(ContentButton), typeof(ContentButtonRenderer))]
30
31 namespace Tizen.Wearable.CircularUI.Forms.Renderer
32 {
33     public class ContentButtonRenderer : LayoutRenderer
34     {
35         EButton _button;
36
37         ContentButton Button => Element as ContentButton;
38
39         protected override void OnElementChanged(ElementChangedEventArgs<XFLayout> e)
40         {
41             base.OnElementChanged(e);
42             Initialize();
43         }
44
45         void Initialize()
46         {
47             if (_button == null)
48             {
49                 _button = new EButton(XForms.NativeParent);
50                 _button.BackgroundColor = EColor.Transparent;
51                 _button.SetPartColor("effect", EColor.Transparent);
52                 _button.SetPartColor("effect_pressed", EColor.Transparent);
53                 _button.Show();
54
55                 _button.Pressed += OnPressed;
56                 _button.Released += OnReleased;
57                 _button.Clicked += OnClicked;
58
59                 Control.PackEnd(_button);
60             }
61         }
62
63         protected override void UpdateLayout()
64         {
65             base.UpdateLayout();
66
67             _button.Geometry = Control.Geometry;
68             _button.RaiseTop();
69         }
70
71         void OnPressed(object sender, EventArgs args)
72         {
73             Button?.SendPressed();
74         }
75
76         void OnReleased(object sender, EventArgs args)
77         {
78             Button?.SendReleased();
79         }
80
81         void OnClicked(object sender, EventArgs args)
82         {
83             Button?.SendClicked();
84         }
85     }
86 }