Revert "[NUI] Refactoring Theme and StyleManager (#1981)" (#2013)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / PopupStyle.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     /// PopupStyle is a class which saves Popup's ux data.
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class PopupStyle : ControlStyle
28     {
29         static PopupStyle() { }
30
31         /// <summary>
32         /// Creates a new instance of a PopupStyle.
33         /// </summary>
34         [EditorBrowsable(EditorBrowsableState.Never)]
35         public PopupStyle() : base()
36         {
37             InitSubStyle();
38         }
39
40         /// <summary>
41         /// Creates a new instance of a PopupStyle with style.
42         /// </summary>
43         /// <param name="style">Create PopupStyle by style customized by user.</param>
44         [EditorBrowsable(EditorBrowsableState.Never)]
45         public PopupStyle(PopupStyle style) : base(style)
46         {
47             Title = new TextLabelStyle();
48             Buttons = new ButtonStyle();
49             this.CopyFrom(style);
50         }
51
52         /// <summary>
53         /// Title Text's style.
54         /// </summary>
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public TextLabelStyle Title { get; set; }
57
58         /// <summary>
59         /// Popup button's style.
60         /// </summary>
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public ButtonStyle Buttons { get; set; }
63
64         /// <summary>
65         /// Style's clone function.
66         /// </summary>
67         /// <param name="bindableObject">The style that need to copy.</param>
68         [EditorBrowsable(EditorBrowsableState.Never)]
69         public override void CopyFrom(BindableObject bindableObject)
70         {
71             base.CopyFrom(bindableObject);
72
73             PopupStyle popupStyle = bindableObject as PopupStyle;
74             if (popupStyle != null)
75             {
76                 if (popupStyle.Title != null)
77                 {
78                     Title?.CopyFrom(popupStyle.Title);
79                 }
80
81                 if (popupStyle.Buttons != null)
82                 {
83                     Buttons?.CopyFrom(popupStyle.Buttons);
84                 }
85             }
86         }
87
88         private void InitSubStyle()
89         {
90             // TODO Apply proper shadow as a default for a Popup
91             BoxShadow = new Shadow()
92             {
93                 BlurRadius = 5,
94                 Offset = new Vector2(5, 5),
95             };
96
97             Title = new TextLabelStyle()
98             {
99                 PositionUsesPivotPoint = true,
100                 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
101                 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
102                 HorizontalAlignment = HorizontalAlignment.Begin,
103                 VerticalAlignment = VerticalAlignment.Bottom
104             };
105
106             Buttons = new ButtonStyle()
107             {
108                 Size = new Size(0, 0),
109                 PositionUsesPivotPoint = true,
110                 ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
111                 PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
112                 Overlay = new ImageViewStyle()
113                 {
114                     PositionUsesPivotPoint = true,
115                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
116                     PivotPoint = Tizen.NUI.PivotPoint.Center,
117                     WidthResizePolicy = ResizePolicyType.FillToParent,
118                     HeightResizePolicy = ResizePolicyType.FillToParent
119                 },
120
121                 Text = new TextLabelStyle()
122                 {
123                     PositionUsesPivotPoint = true,
124                     ParentOrigin = Tizen.NUI.ParentOrigin.Center,
125                     PivotPoint = Tizen.NUI.PivotPoint.Center,
126                     WidthResizePolicy = ResizePolicyType.FillToParent,
127                     HeightResizePolicy = ResizePolicyType.FillToParent,
128                     HorizontalAlignment = HorizontalAlignment.Center,
129                     VerticalAlignment = VerticalAlignment.Center
130                 }
131             };
132         }
133     }
134 }