[NUI] CheckBox, RadioButton and Switch can place text without setting text size ...
[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
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
20
21 namespace Tizen.NUI.Components
22 {
23     internal partial class DefaultThemeCreator
24     {
25         private HashSet<ExternalThemeKeyList> actionSet;
26
27         private DefaultThemeCreator() { }
28
29         public static IThemeCreator Instance { get; set; } = new DefaultThemeCreator();
30
31         public HashSet<ExternalThemeKeyList> GetExternalThemeKeyListSet()
32         {
33             if (actionSet != null)
34             {
35                 return actionSet;
36             }
37
38             actionSet = new HashSet<ExternalThemeKeyList>()
39             {
40                 // Button
41                 (new ExternalThemeKeyList(typeof(Button), typeof(ButtonStyle)))
42                     .AddBackgroundSelector("/Background", SetBackgroundColor, SetBackgroundImage)
43                     .Add<Rectangle>("/BackgroundImageBorder", SetBackgroundBorder)
44                     .AddSelector<Color>("/Text/TextColor", SetButtonTextColor)
45                     .AddSelector<float?>("/Text/PixelSize", SetButtonTextPixelSize),
46
47                 // CheckBox
48                 (new ExternalThemeKeyList(typeof(CheckBox), typeof(ButtonStyle)))
49                     .AddSelector<string>("/Icon/ResourceUrl", SetButtonIconResourceUrl, ControlState.Selected, ControlState.DisabledSelected)
50                     .Add<Rectangle>("/Icon/Border", SetButtonIconBorder)
51                     .AddSelector<Color>("/Text/TextColor", SetButtonTextColor, ControlState.Selected, ControlState.DisabledSelected)
52                     .AddSelector<float?>("/Text/PixelSize", SetButtonTextPixelSize, ControlState.Selected, ControlState.DisabledSelected),
53
54                 // RadioButton
55                 (new ExternalThemeKeyList(typeof(RadioButton), typeof(ButtonStyle)))
56                     .AddSelector<string>("/Icon/ResourceUrl", SetButtonIconResourceUrl, ControlState.Selected, ControlState.DisabledSelected)
57                     .Add<Rectangle>("/Icon/Border", SetButtonIconBorder)
58                     .AddSelector<Color>("/Text/TextColor", SetButtonTextColor, ControlState.Selected, ControlState.DisabledSelected)
59                     .AddSelector<float?>("/Text/PixelSize", SetButtonTextPixelSize, ControlState.Selected, ControlState.DisabledSelected),
60
61                 // Switch
62                 (new ExternalThemeKeyList(typeof(Switch), typeof(SwitchStyle)))
63                     .AddSelector<string>("/Track/ResourceUrl", (ViewStyle style, Selector<string> value) => ((SwitchStyle)style).Track.ResourceUrl = value, ControlState.Selected, ControlState.DisabledSelected)
64                     .AddSelector<string>("/Thumb/ResourceUrl", (ViewStyle style, Selector<string> value) => ((SwitchStyle)style).Thumb.ResourceUrl = value, ControlState.Selected, ControlState.DisabledSelected)
65                     .Add<Rectangle>("/Track/Border", (ViewStyle style, Rectangle value) => ((SwitchStyle)style).Track.Border = value)
66                     .Add<Rectangle>("/Thumb/Border", (ViewStyle style, Rectangle value) => ((SwitchStyle)style).Thumb.Border = value)
67                     .AddSelector<Color>("/Text/TextColor", SetButtonTextColor, ControlState.Selected, ControlState.DisabledSelected)
68                     .AddSelector<float?>("/Text/PixelSize", SetButtonTextPixelSize, ControlState.Selected, ControlState.DisabledSelected),
69
70                 // Progress
71                 (new ExternalThemeKeyList(typeof(Progress), typeof(ProgressStyle)))
72                     .AddSelector("/Track/Background", (ViewStyle style, Selector<Color> value) => ((ProgressStyle)style).Track.BackgroundColor = value)
73                     .AddSelector("/Buffer/Background", (ViewStyle style, Selector<Color> value) => ((ProgressStyle)style).Buffer.BackgroundColor = value)
74                     .AddSelector("/Progress/Background", (ViewStyle style, Selector<Color> value) => ((ProgressStyle)style).Progress.BackgroundColor = value)
75                     .AddSelector("/Track/ResourceUrl", (ViewStyle style, Selector<string> value) => ((ProgressStyle)style).Track.ResourceUrl = value)
76                     .AddSelector("/Buffer/ResourceUrl", (ViewStyle style, Selector<string> value) => ((ProgressStyle)style).Buffer.ResourceUrl = value)
77                     .AddSelector("/Progress/ResourceUrl", (ViewStyle style, Selector<string> value) => ((ProgressStyle)style).Progress.ResourceUrl = value),
78
79                 // Slider
80                 (new ExternalThemeKeyList(typeof(Slider), typeof(SliderStyle)))
81                     .AddSelector("/Track/Background", (ViewStyle style, Selector<Color> value) => ((SliderStyle)style).Track.BackgroundColor = value)
82                     .AddSelector("/Progress/Background", (ViewStyle style, Selector<Color> value) => ((SliderStyle)style).Progress.BackgroundColor = value)
83                     .AddSelector("/Thumb/Background", (ViewStyle style, Selector<Color> value) => ((SliderStyle)style).Thumb.BackgroundColor = value)
84                     .AddSelector("/Thumb/ResourceUrl", (ViewStyle style, Selector<string> value) => ((SliderStyle)style).Thumb.ResourceUrl = value)
85                     .AddSelector("/ValueIndicatorImage/ResourceUrl", (ViewStyle style, Selector<string> value) => ((SliderStyle)style).ValueIndicatorImage.ResourceUrl = value),
86                 
87                 // Pagination
88                 (new ExternalThemeKeyList(typeof(Pagination), typeof(PaginationStyle)))
89                     .AddSelector("/IndicatorImageUrl", (ViewStyle style, Selector<string> value) => ((PaginationStyle)style).IndicatorImageUrl = value),
90                 
91                 // Scrollbar
92                 (new ExternalThemeKeyList(typeof(Scrollbar), typeof(ScrollbarStyle)))
93                     .Add("/TrackColor", (ViewStyle style, Color value) => ((ScrollbarStyle)style).TrackColor = value)
94                     .Add("/ThumbColor", (ViewStyle style, Color value) => ((ScrollbarStyle)style).ThumbColor = value),
95                 
96                 // RecyclerViewItem
97                 (new ExternalThemeKeyList(typeof(RecyclerViewItem), typeof(RecyclerViewItemStyle)))
98                     .AddBackgroundSelector("/Background", SetBackgroundColor, SetBackgroundImage, ControlState.Selected)
99                     .Add<Rectangle>("/BackgroundImageBorder", SetBackgroundBorder),
100                 
101                 // DefaultTitleItem
102                 (new ExternalThemeKeyList(typeof(DefaultTitleItem), typeof(DefaultTitleItemStyle)))
103                     .AddBackgroundSelector("/Background", SetBackgroundColor, SetBackgroundImage)
104                     .Add<Rectangle>("/BackgroundImageBorder", SetBackgroundBorder),
105
106                 // AppBar
107                 (new ExternalThemeKeyList(typeof(AppBar), typeof(AppBarStyle))),
108             };
109
110             return actionSet;
111         }
112
113         public static void Preload()
114         {
115             ThemeManager.AddPackageTheme(Instance);
116             Instance.GetExternalThemeKeyListSet();
117         }
118
119         private static void SetBackgroundColor(ViewStyle style, Selector<Color> value) => style.BackgroundColor = value;
120
121         private static void SetBackgroundImage(ViewStyle style, Selector<string> value) => style.BackgroundImage = value;
122
123         private static void SetBackgroundBorder(ViewStyle style, Rectangle value) => style.BackgroundImageBorder = value;
124
125         private static void SetButtonTextColor(ViewStyle style, Selector<Color> value) => ((ButtonStyle)style).Text.TextColor = value;
126
127         private static void SetButtonTextPixelSize(ViewStyle style, Selector<float?> value) => ((ButtonStyle)style).Text.PixelSize = value;
128
129         private static void SetButtonIconResourceUrl(ViewStyle style, Selector<string> value) => ((ButtonStyle)style).Icon.ResourceUrl = value;
130
131         private static void SetButtonIconBorder(ViewStyle style, Rectangle value) => ((ButtonStyle)style).Icon.Border = value;
132
133         private static void SetButtonIconBackgroundColor(ViewStyle style, Selector<Color> value) => ((ButtonStyle)style).Icon.BackgroundColor = value;
134
135         private static void SetButtonIconBackgroundImageUrl(ViewStyle style, Selector<string> value) => ((ButtonStyle)style).Icon.BackgroundImage = value;
136
137         private static void SetButtonIconBackgroundBorder(ViewStyle style, Rectangle value) => ((ButtonStyle)style).Icon.BackgroundImageBorder = value;
138     }
139 }
140