[NUI] Rebase DevelNUI (#2507)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Theme / DefaultTheme.cs
1 /*
2  * Copyright(c) 2020 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 #if !PROFILE_WEARABLE
18
19 using System.Collections.Generic;
20 using System.Diagnostics.CodeAnalysis;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.Binding;
23
24 namespace Tizen.NUI.Components
25 {
26     // It is a C# version of res/Tizen.NUI.Components_Tizen.NUI.Theme.Common.xaml
27     internal class DefaultThemeCreator : IThemeCreator
28     {
29         public ResourceDictionary CreateThemeResource() => new ResourceDictionary()
30         {
31             ["ButtonBackgroundColorNormal"] = new Color(0.88f, 0.88f, 0.88f, 1),
32             ["ButtonBackgroundColorPressed"] = new Color(0.77f, 0.77f, 0.77f, 1),
33             ["ButtonBackgroundColorDisabled"] = new Color(0.88f, 0.88f, 0.88f, 1),
34             ["ButtonTextColorNormal"] = new Color(0.22f, 0.22f, 0.22f, 1),
35             ["ButtonTextColorPressed"] = new Color(0.11f, 0.11f, 0.11f, 1),
36             ["ButtonTextColorDisabled"] = new Color(0.66f, 0.66f, 0.66f, 1),
37             ["CheckBoxIconBackgroundImagePressed"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_p.png",
38             ["CheckBoxIconBackgroundImageSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_p.png",
39             ["CheckBoxIconBackgroundImageOther"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_n.png",
40             ["CheckBoxIconImageResourceUrlPressed"] = "",
41             ["CheckBoxIconImageResourceUrlSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_s.png",
42             ["CheckBoxIconImageResourceUrlOther"] = "",
43             ["CheckBoxTextColorNormal"] = new Color(0.22f, 0.22f, 0.22f, 1),
44             ["CheckBoxTextColorPressed"] = new Color(0.11f, 0.11f, 0.11f, 1),
45             ["CheckBoxTextColorDisabled"] = new Color(0.66f, 0.66f, 0.66f, 1),
46             ["DropDownBackgroundImagePressed"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_p.png",
47             ["DropDownBackgroundImageOther"] = FrameworkInformation.ResourcePath + "nui_component_default_checkbox_bg_n.png",
48             ["DropDownIconImageResourceUrl"] = FrameworkInformation.ResourcePath + "nui_component_default_dropdown_button_icon.png",
49             ["DropDownListBackgroundImageResourceUrl"] = FrameworkInformation.ResourcePath + "nui_component_default_dropdown_list_bg.png",
50             ["DropDownDataItemBackgroundColorPressed"] = new Color(0.05f, 0.63f, 0.9f, 1),
51             ["DropDownDataItemBackgroundColorSelected"] = new Color(0.8f, 0.8f, 0.8f, 1),
52             ["DropDownDataItemBackgroundColorNormal"] = new Color(1, 1, 1, 1),
53             ["PopupBackgroundColor"] = new Color(0.9f, 0.9f, 0.9f, 1),
54             ["PopupImageShadowUrl"] = FrameworkInformation.ResourcePath + "nui_component_default_popup_shadow.png",
55             ["PopupButtonBackgroundColorNormal"] = new Color(1, 1, 1, 1),
56             ["PopupButtonBackgroundColorPressed"] = new Color(1, 1, 1, 0.5f),
57             ["PopupButtonOverlayBackgroundColorNormal"] = new Color(1, 1, 1, 1),
58             ["PopupButtonOverlayBackgroundColorPressed"] = new Color(0, 0, 0, 0.1f),
59             ["PopupButtonOverlayBackgroundColorSelected"] = new Color(1, 1, 1, 1),
60             ["PopupButtonTextColor"] = new Color(0.05f, 0.63f, 0.9f, 1),
61             ["ProgressTrackBackgroundColor"] = new Color(0, 0, 0, 0.1f),
62             ["ProgressBufferBackgroundColor"] = new Color(0.05f, 0.63f, 0.9f, 0.3f),
63             ["ProgressProgressBackgroundColor"] = new Color(0.05f, 0.63f, 0.9f, 1),
64             ["RadioButtonIconBackgroundImagePressed"] = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_p.png",
65             ["RadioButtonIconBackgroundImageSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_s.png",
66             ["RadioButtonIconBackgroundImageOther"] = FrameworkInformation.ResourcePath + "nui_component_default_radiobutton_n.png",
67             ["RadioButtonTextColorNormal"] = new Color(0.22f, 0.22f, 0.22f, 1),
68             ["RadioButtonTextColorPressed"] = new Color(0.11f, 0.11f, 0.11f, 1),
69             ["RadioButtonTextColorDisabled"] = new Color(0.66f, 0.66f, 0.66f, 1),
70             ["SliderTrackColor"] = new Color(0, 0, 0, 0.1f),
71             ["SliderProgressColor"] = new Color(0.5f, 0.63f, 0.9f, 1),
72             ["SliderThumbImageResourceUrl"] = FrameworkInformation.ResourcePath + "nui_component_default_slider_thumb_n.png",
73             ["SliderThumbBackgroundImageNormal"] = FrameworkInformation.ResourcePath + "nui_component_default_slider_thumb_bg_p.png",
74             ["SliderThumbBackgroundImagePressed"] = FrameworkInformation.ResourcePath + "nui_component_default_slider_thumb_bg_p.png",
75             ["SwitchTrackImageResourceUrlNormal"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_n.png",
76             ["SwitchTrackImageResourceUrlSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_s.png",
77             ["SwitchTrackImageResourceUrlDisabled"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_d.png",
78             ["SwitchTrackImageResourceUrlDisabledSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_track_ds.png",
79             ["SwitchThumbImageResourceUrlNormal"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_n.png",
80             ["SwitchThumbImageResourceUrlDisabled"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_d.png",
81             ["SwitchThumbImageResourceUrlSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_switch_thumb_n.png",
82             ["SwitchTextColorNormal"] = new Color(0.22f, 0.22f, 0.22f, 1),
83             ["SwitchTextColorPressed"] = new Color(0.11f, 0.11f, 0.11f, 1),
84             ["SwitchTextColorDisabled"] = new Color(0.66f, 0.66f, 0.66f, 1),
85             ["TabBackgroundColor"] = Color.Yellow,
86             ["TabUnderLineBackgroundColor"] = new Color(0.05f, 0.63f, 0.9f, 1.0f),
87             ["TabTextColorNormal"] = Color.Black,
88             ["TabTextColorSelected"] = new Color(0.05f, 0.63f, 0.9f, 1),
89             ["ToastBackgroundColor"] = new Color(0, 0, 0, 0.8f),
90             ["PaginationIndicatorImageUrlNormal"] = FrameworkInformation.ResourcePath + "nui_component_default_pagination_normal_dot.png",
91             ["PaginationIndicatorImageUrlSelected"] = FrameworkInformation.ResourcePath + "nui_component_default_pagination_focus_dot.png",
92             ["ScrollbarTrackColor"] = new Color(1, 1, 1, 0.15f),
93             ["ScrollbarThumbColor"] = new Color(0.6f, 0.6f, 0.6f, 1.0f),
94         };
95
96         public Theme Create() => Create(null);
97
98         [SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope", Justification = "The responsibility to dispose the object is transferred to the theme object.")]
99         public Theme Create(IEnumerable<KeyValuePair<string, string>> changedResources)
100         {
101             var theme = new Theme() { Id = "Tizen.NUI.Theme.Common" };
102
103             theme.SetChangedResources(changedResources);
104             theme.Resources = CreateThemeResource();
105             theme.OnThemeResourcesChanged();
106
107             theme.AddStyleWithoutClone("Tizen.NUI.Components.Button", new ButtonStyle()
108             {
109                 Size = new Size(100, 45),
110                 BackgroundColor = new Selector<Color>()
111                 {
112                     Normal = (Color)theme.Resources["ButtonBackgroundColorNormal"],
113                     Pressed = (Color)theme.Resources["ButtonBackgroundColorPressed"],
114                     Disabled = (Color)theme.Resources["ButtonBackgroundColorDisabled"],
115                 },
116                 Text = new TextLabelStyle()
117                 {
118                     PointSize = 12,
119                     TextColor = new Selector<Color>()
120                     {
121                         Normal = (Color)theme.Resources["ButtonTextColorNormal"],
122                         Pressed = (Color)theme.Resources["ButtonTextColorPressed"],
123                         Disabled = (Color)theme.Resources["ButtonTextColorDisabled"],
124                     }
125                 }
126             });
127
128             theme.AddStyleWithoutClone("Tizen.NUI.Components.CheckBox", new ButtonStyle()
129             {
130                 Size = new Size(30, 30),
131                 Icon = new ImageViewStyle()
132                 {
133                     Opacity = new Selector<float?>()
134                     {
135                         Normal = 1.0f,
136                         Disabled = 0.4f,
137                         Selected = 1.0f,
138                     },
139                     BackgroundImage = new Selector<string>()
140                     {
141                         Pressed = (string)theme.Resources["CheckBoxIconBackgroundImagePressed"],
142                         Selected = (string)theme.Resources["CheckBoxIconBackgroundImageSelected"],
143                         Other = (string)theme.Resources["CheckBoxIconBackgroundImageOther"],
144                     },
145                     ResourceUrl = new Selector<string>()
146                     {
147                         Pressed = (string)theme.Resources["CheckBoxIconImageResourceUrlPressed"],
148                         Selected = (string)theme.Resources["CheckBoxIconImageResourceUrlSelected"],
149                         Other = (string)theme.Resources["CheckBoxIconImageResourceUrlOther"],
150                     },
151                 },
152                 Text = new TextLabelStyle()
153                 {
154                     PointSize = 12,
155                     TextColor = new Selector<Color>()
156                     {
157                         Normal = (Color)theme.Resources["CheckBoxTextColorNormal"],
158                         Pressed = (Color)theme.Resources["CheckBoxTextColorPressed"],
159                         Disabled = (Color)theme.Resources["CheckBoxTextColorDisabled"],
160                     }
161                 }
162             });
163
164             theme.AddStyleWithoutClone("Tizen.NUI.Components.Popup", new PopupStyle()
165             {
166                 Size = new Size(500, 280),
167                 BackgroundColor = (Color)theme.Resources["PopupBackgroundColor"],
168                 ImageShadow = new ImageShadow()
169                 {
170                     Url = (string)theme.Resources["PopupImageShadowUrl"],
171                     Border = new Rectangle(24, 24, 24, 24),
172                     Extents = new Vector2(48, 48)
173                 },
174                 Title = new TextLabelStyle()
175                 {
176                     PointSize = 16,
177                     Padding = new Extents(20, 20, 20, 20),
178                 },
179                 Buttons = new ButtonStyle()
180                 {
181                     Size = new Size(0, 80),
182                     BackgroundColor = new Selector<Color>()
183                     {
184                         Normal = (Color)theme.Resources["PopupButtonBackgroundColorNormal"],
185                         Pressed = (Color)theme.Resources["PopupButtonBackgroundColorPressed"],
186                     },
187                     Overlay = new ImageViewStyle()
188                     {
189                         BackgroundColor = new Selector<Color>()
190                         {
191                             Normal = (Color)theme.Resources["PopupButtonOverlayBackgroundColorNormal"],
192                             Pressed = (Color)theme.Resources["PopupButtonOverlayBackgroundColorPressed"],
193                             Other = (Color)theme.Resources["PopupButtonOverlayBackgroundColorSelected"],
194                         },
195                     },
196                     Text = new TextLabelStyle()
197                     {
198                         TextColor = (Color)theme.Resources["PopupButtonTextColor"],
199                     }
200                 }
201             });
202
203             theme.AddStyleWithoutClone("Tizen.NUI.Components.Progress", new ProgressStyle()
204             {
205                 Size = new Size(200, 5),
206                 Track = new ImageViewStyle()
207                 {
208                     BackgroundColor = (Color)theme.Resources["ProgressTrackBackgroundColor"],
209                 },
210                 Buffer = new ImageViewStyle()
211                 {
212                     BackgroundColor = (Color)theme.Resources["ProgressBufferBackgroundColor"],
213                 },
214                 Progress = new ImageViewStyle()
215                 {
216                     BackgroundColor = (Color)theme.Resources["ProgressProgressBackgroundColor"],
217                 },
218             });
219
220             theme.AddStyleWithoutClone("Tizen.NUI.Components.RadioButton", new ButtonStyle()
221             {
222                 Size = new Size(30, 30),
223                 Icon = new ImageViewStyle()
224                 {
225                     Opacity = new Selector<float?>()
226                     {
227                         Normal = 1.0f,
228                         Disabled = 0.4f,
229                         Selected = 1.0f,
230                     },
231                     BackgroundImage = new Selector<string>()
232                     {
233                         Pressed = (string)theme.Resources["RadioButtonIconBackgroundImagePressed"],
234                         Selected = (string)theme.Resources["RadioButtonIconBackgroundImageSelected"],
235                         Other = (string)theme.Resources["RadioButtonIconBackgroundImageOther"],
236                     }
237                 },
238                 Text = new TextLabelStyle()
239                 {
240                     PointSize = 12,
241                     TextColor = new Selector<Color>()
242                     {
243                         Normal = (Color)theme.Resources["RadioButtonTextColorNormal"],
244                         Pressed = (Color)theme.Resources["RadioButtonTextColorPressed"],
245                         Disabled = (Color)theme.Resources["RadioButtonTextColorDisabled"],
246                     }
247                 }
248             });
249
250             theme.AddStyleWithoutClone("Tizen.NUI.Components.Slider", new SliderStyle()
251             {
252                 Size = new Size(200, 50),
253                 TrackThickness = 5,
254                 Track = new ImageViewStyle()
255                 {
256                     BackgroundColor = (Color)theme.Resources["SliderTrackColor"],
257                 },
258                 Progress = new ImageViewStyle()
259                 {
260                     BackgroundColor = (Color)theme.Resources["SliderProgressColor"],
261                 },
262                 Thumb = new ImageViewStyle()
263                 {
264                     Size = new Size(50, 50),
265                     ResourceUrl = (string)theme.Resources["SliderThumbImageResourceUrl"],
266                     BackgroundImage = new Selector<string>()
267                     {
268                         Normal = (string)theme.Resources["SliderThumbBackgroundImageNormal"],
269                         Pressed = (string)theme.Resources["SliderThumbBackgroundImagePressed"],
270                     }
271                 },
272             });
273
274             theme.AddStyleWithoutClone("Tizen.NUI.Components.Switch", new SwitchStyle()
275             {
276                 Size = new Size(96, 60),
277                 Track = new ImageViewStyle()
278                 {
279                     Size = new Size(96, 60),
280                     ResourceUrl = new Selector<string>()
281                     {
282                         Normal = (string)theme.Resources["SwitchTrackImageResourceUrlNormal"],
283                         Selected = (string)theme.Resources["SwitchTrackImageResourceUrlSelected"],
284                         Disabled = (string)theme.Resources["SwitchTrackImageResourceUrlDisabled"],
285                         DisabledSelected = (string)theme.Resources["SwitchTrackImageResourceUrlDisabledSelected"],
286                     }
287                 },
288                 Thumb = new ImageViewStyle()
289                 {
290                     Size = new Size(60, 60),
291                     ResourceUrl = new Selector<string>()
292                     {
293                         Normal = (string)theme.Resources["SwitchThumbImageResourceUrlNormal"],
294                         Disabled = (string)theme.Resources["SwitchThumbImageResourceUrlDisabled"],
295                         Selected = (string)theme.Resources["SwitchThumbImageResourceUrlSelected"],
296                     }
297                 },
298                 Text = new TextLabelStyle()
299                 {
300                     PointSize = 12,
301                     TextColor = new Selector<Color>()
302                     {
303                         Normal = (Color)theme.Resources["SwitchTextColorNormal"],
304                         Pressed = (Color)theme.Resources["SwitchTextColorPressed"],
305                         Disabled = (Color)theme.Resources["SwitchTextColorDisabled"],
306                     }
307                 }
308             });
309
310             theme.AddStyleWithoutClone("Tizen.NUI.Components.Tab", new TabStyle()
311             {
312                 Size = new Size(480, 80),
313                 BackgroundColor = (Color)theme.Resources["TabBackgroundColor"],
314                 UnderLine = new ViewStyle()
315                 {
316                     Size = new Size(0, 6),
317                     BackgroundColor = (Color)theme.Resources["TabUnderLineBackgroundColor"],
318                 },
319                 Text = new TextLabelStyle()
320                 {
321                     PointSize = 16,
322                     TextColor = new Selector<Color>()
323                     {
324                         Normal = (Color)theme.Resources["TabTextColorNormal"],
325                         Selected = (Color)theme.Resources["TabTextColorSelected"],
326                     }
327                 }
328             });
329
330             theme.AddStyleWithoutClone("Tizen.NUI.Components.Toast", new ToastStyle()
331             {
332                 Size = new Size(480, 80),
333                 BackgroundColor = (Color)theme.Resources["ToastBackgroundColor"],
334                 Text = new TextLabelStyle()
335                 {
336                     Padding = new Extents(12, 12, 8, 8)
337                 }
338             });
339
340             theme.AddStyleWithoutClone("Tizen.NUI.Components.Loading", new LoadingStyle()
341             {
342                 LoadingSize = new Size(100, 100),
343             });
344
345             theme.AddStyleWithoutClone("Tizen.NUI.Components.Pagination", new PaginationStyle()
346             {
347                 IndicatorImageUrl = new Selector<string>()
348                 {
349                     Normal = (string)theme.Resources["PaginationIndicatorImageUrlNormal"],
350                     Selected = (string)theme.Resources["PaginationIndicatorImageUrlSelected"],
351                 }
352             });
353
354             theme.AddStyleWithoutClone("Tizen.NUI.Components.Scrollbar", new ScrollbarStyle()
355             {
356                 TrackThickness = 6,
357                 ThumbThickness = 6,
358                 TrackColor = (Color)theme.Resources["ScrollbarTrackColor"],
359                 ThumbColor = (Color)theme.Resources["ScrollbarThumbColor"],
360                 TrackPadding = 4
361             });
362
363             return theme;
364         }
365     }
366 }
367
368 #endif