[NUI] Public Style apis (#1434)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / ToastStyle.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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.ComponentModel;
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI.Components
22 {
23     /// <summary>
24     /// ToastStyle is a class which saves Toast's ux data.
25     /// </summary>
26     /// <since_tizen> 8 </since_tizen>
27     public class ToastStyle : ControlStyle
28     {
29         static ToastStyle() { }
30
31         /// <summary>
32         /// Creates a new instance of a ToastStyle.
33         /// </summary>
34         /// <since_tizen> 8 </since_tizen>
35         public ToastStyle() : base()
36         {
37             InitSubStyle();
38         }
39
40         /// <summary>
41         /// Creates a new instance of a ToastStyle with Style.
42         /// </summary>
43         /// <param name="style">Create ToastStyle by Style customized by user.</param>
44         /// <since_tizen> 8 </since_tizen>
45         public ToastStyle(ToastStyle style) : base(style)
46         {
47             InitSubStyle();
48             this.CopyFrom(style);
49         }
50
51         /// <summary>
52         /// Gets or sets toast show duration time.
53         /// </summary>
54         /// <since_tizen> 8 </since_tizen>
55         public uint? Duration { get; set; }
56
57         /// <summary>
58         /// Text's Style.
59         /// </summary>
60         /// <since_tizen> 8 </since_tizen>
61         public TextLabelStyle Text { get; set; }
62
63         /// <summary>
64         /// Style's clone function.
65         /// </summary>
66         /// <param name="bindableObject">The style that need to copy.</param>
67         /// <since_tizen> 8 </since_tizen>
68         public override void CopyFrom(BindableObject bindableObject)
69         {
70             base.CopyFrom(bindableObject);
71             ToastStyle toastStyle = bindableObject as ToastStyle;
72             if (toastStyle != null)
73             {
74                 if (null != toastStyle.Text)
75                 {
76                     Text?.CopyFrom(toastStyle.Text);
77                 }
78                 Duration = toastStyle.Duration;
79             }
80         }
81
82         private void InitSubStyle()
83         {
84             Text = new TextLabelStyle()
85             {
86                 PositionUsesPivotPoint = true,
87                 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
88                 PivotPoint = Tizen.NUI.PivotPoint.Center,
89                 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
90                 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
91                 HorizontalAlignment = HorizontalAlignment.Center,
92                 VerticalAlignment = VerticalAlignment.Center,
93                 TextColor = Color.White
94             };
95         }
96     }
97 }