2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
21 namespace Tizen.NUI.Components
23 internal partial class DefaultThemeCreator
25 private HashSet<ExternalThemeKeyList> actionSet;
27 private DefaultThemeCreator() { }
29 public static IThemeCreator Instance { get; set; } = new DefaultThemeCreator();
31 public HashSet<ExternalThemeKeyList> GetExternalThemeKeyListSet()
33 if (actionSet != null)
38 actionSet = new HashSet<ExternalThemeKeyList>()
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),
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),
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),
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),
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),
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),
88 (new ExternalThemeKeyList(typeof(Pagination), typeof(PaginationStyle)))
89 .AddSelector("/IndicatorImageUrl", (ViewStyle style, Selector<string> value) => ((PaginationStyle)style).IndicatorImageUrl = value),
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),
97 (new ExternalThemeKeyList(typeof(RecyclerViewItem), typeof(RecyclerViewItemStyle)))
98 .AddBackgroundSelector("/Background", SetBackgroundColor, SetBackgroundImage, ControlState.Selected)
99 .Add<Rectangle>("/BackgroundImageBorder", SetBackgroundBorder),
102 (new ExternalThemeKeyList(typeof(DefaultTitleItem), typeof(DefaultTitleItemStyle)))
103 .AddBackgroundSelector("/Background", SetBackgroundColor, SetBackgroundImage)
104 .Add<Rectangle>("/BackgroundImageBorder", SetBackgroundBorder),
107 (new ExternalThemeKeyList(typeof(AppBar), typeof(AppBarStyle))),
113 public static void Preload()
115 ThemeManager.AddPackageTheme(Instance);
116 Instance.GetExternalThemeKeyListSet();
119 private static void SetBackgroundColor(ViewStyle style, Selector<Color> value) => style.BackgroundColor = value;
121 private static void SetBackgroundImage(ViewStyle style, Selector<string> value) => style.BackgroundImage = value;
123 private static void SetBackgroundBorder(ViewStyle style, Rectangle value) => style.BackgroundImageBorder = value;
125 private static void SetButtonTextColor(ViewStyle style, Selector<Color> value) => ((ButtonStyle)style).Text.TextColor = value;
127 private static void SetButtonTextPixelSize(ViewStyle style, Selector<float?> value) => ((ButtonStyle)style).Text.PixelSize = value;
129 private static void SetButtonIconResourceUrl(ViewStyle style, Selector<string> value) => ((ButtonStyle)style).Icon.ResourceUrl = value;
131 private static void SetButtonIconBorder(ViewStyle style, Rectangle value) => ((ButtonStyle)style).Icon.Border = value;
133 private static void SetButtonIconBackgroundColor(ViewStyle style, Selector<Color> value) => ((ButtonStyle)style).Icon.BackgroundColor = value;
135 private static void SetButtonIconBackgroundImageUrl(ViewStyle style, Selector<string> value) => ((ButtonStyle)style).Icon.BackgroundImage = value;
137 private static void SetButtonIconBackgroundBorder(ViewStyle style, Rectangle value) => ((ButtonStyle)style).Icon.BackgroundImageBorder = value;