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