From: Jiyun Yang Date: Mon, 10 Feb 2020 02:04:37 +0000 (+0900) Subject: [NUI] Add default component styles (#1382) X-Git-Tag: submit/tizen_5.5/20200211.005151~1^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=318bba9c03189fe97c9481c9fd72566c3d95f1b9;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add default component styles (#1382) DefaultButtonStyle DefaultCheckBoxStyle DefaultSwitchStyle DefaultRadioButtonStyle Signed-off-by: Jiyun Yang --- diff --git a/packaging/PlatformFileList.txt b/packaging/PlatformFileList.txt index 9899785..144d30b 100755 --- a/packaging/PlatformFileList.txt +++ b/packaging/PlatformFileList.txt @@ -4,6 +4,18 @@ res/maps_marker_pin_48.png #mobile #mobile-emul #tv #wea res/maps_marker_pin_72.png #mobile #mobile-emul #tv #wearable res/maps_marker_sticker_48.png #mobile #mobile-emul #tv #wearable res/maps_marker_sticker_72.png #mobile #mobile-emul #tv #wearable +res/nui_component_default_checkbox_bg_n.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_checkbox_bg_p.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_checkbox_s.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_switch_thumb_d.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_switch_thumb_n.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_switch_track_d.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_switch_track_ds.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_switch_track_n.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_switch_track_s.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_radiobutton_n.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_radiobutton_p.png #common #mobile #mobile-emul #tv #wearable +res/nui_component_default_radiobutton_s.png #common #mobile #mobile-emul #tv #wearable Tizen.Account.AccountManager.dll #mobile #mobile-emul #tv #wearable Tizen.Account.FidoClient.dll #mobile #mobile-emul #wearable Tizen.Account.OAuth2.dll #mobile #mobile-emul #wearable diff --git a/src/Tizen.NUI.Components/Controls/Control.cs b/src/Tizen.NUI.Components/Controls/Control.cs index 7aa713c..c3f8a0f 100755 --- a/src/Tizen.NUI.Components/Controls/Control.cs +++ b/src/Tizen.NUI.Components/Controls/Control.cs @@ -53,6 +53,13 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public Control() : base() { + ViewStyle viewStyle = StyleManager.Instance.GetComponentStyle(this.GetType()); + + if (viewStyle != null) + { + ApplyStyle(viewStyle); + } + Initialize(null); } diff --git a/src/Tizen.NUI.Components/PreloadStyle/DefaultButtonStyle.cs b/src/Tizen.NUI.Components/PreloadStyle/DefaultButtonStyle.cs new file mode 100644 index 0000000..5e1dc24 --- /dev/null +++ b/src/Tizen.NUI.Components/PreloadStyle/DefaultButtonStyle.cs @@ -0,0 +1,60 @@ +/* + * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + /// + /// The default Button style + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class DefaultButtonStyle : StyleBase + { + /// + /// Return default Button style + /// + internal protected override ViewStyle GetAttributes() + { + ButtonStyle style = new ButtonStyle + { + BackgroundColor = new Selector + { + Normal = new Color(0.88f, 0.88f, 0.88f, 1), + Pressed = new Color(0.77f, 0.77f, 0.77f, 1), + Disabled = new Color(0.88f, 0.88f, 0.88f, 1) + }, + Text = new TextLabelStyle + { + PointSize = new Selector { All = DefaultStyle.PointSizeNormal }, + WidthResizePolicy = ResizePolicyType.FillToParent, + HeightResizePolicy = ResizePolicyType.FillToParent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + TextColor = new Selector + { + Normal = new Color(0.22f, 0.22f, 0.22f, 1), + Pressed = new Color(0.11f, 0.11f, 0.11f, 1), + Disabled = new Color(0.66f, 0.66f, 0.66f, 1) + }, + Text = "Button", + } + }; + return style; + } + } +} diff --git a/src/Tizen.NUI.Components/PreloadStyle/DefaultCheckBoxStyle.cs b/src/Tizen.NUI.Components/PreloadStyle/DefaultCheckBoxStyle.cs new file mode 100644 index 0000000..49d5972 --- /dev/null +++ b/src/Tizen.NUI.Components/PreloadStyle/DefaultCheckBoxStyle.cs @@ -0,0 +1,83 @@ +/* + * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + /// + /// The default CheckBox style + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class DefaultCheckBoxStyle : StyleBase + { + /// + /// Return default CheckBox style + /// + internal protected override ViewStyle GetAttributes() + { + ButtonStyle style = new ButtonStyle + { + Size = new Size(30, 30), + Icon = new ImageViewStyle + { + WidthResizePolicy = ResizePolicyType.DimensionDependency, + HeightResizePolicy = ResizePolicyType.SizeRelativeToParent, + SizeModeFactor = new Vector3(1, 1, 1), + Opacity = new Selector + { + Normal = 1.0f, + Selected = 1.0f, + Disabled = 0.4f, + DisabledSelected = 0.4f + }, + BackgroundImage = new Selector + { + Normal = DefaultStyle.GetResourcePath("nui_component_default_checkbox_bg_n.png"), + Pressed = DefaultStyle.GetResourcePath("nui_component_default_checkbox_bg_p.png"), + Selected = DefaultStyle.GetResourcePath("nui_component_default_checkbox_bg_p.png"), + Disabled = DefaultStyle.GetResourcePath("nui_component_default_checkbox_bg_n.png"), + DisabledSelected = DefaultStyle.GetResourcePath("nui_component_default_checkbox_bg_p.png"), + }, + ResourceUrl = new Selector + { + Normal = "", + Pressed = "", + Selected = DefaultStyle.GetResourcePath("nui_component_default_checkbox_s.png"), + Disabled = "", + DisabledSelected = DefaultStyle.GetResourcePath("nui_component_default_checkbox_s.png"), + } + }, + Text = new TextLabelStyle + { + PointSize = new Selector { All = DefaultStyle.PointSizeNormal }, + WidthResizePolicy = ResizePolicyType.FillToParent, + HeightResizePolicy = ResizePolicyType.FillToParent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + TextColor = new Selector + { + Normal = new Color(0.22f, 0.22f, 0.22f, 1), + Pressed = new Color(0.11f, 0.11f, 0.11f, 1), + Disabled = new Color(0.66f, 0.66f, 0.66f, 1) + } + } + }; + return style; + } + } +} diff --git a/src/Tizen.NUI.Components/PreloadStyle/DefaultRadioButtonStyle.cs b/src/Tizen.NUI.Components/PreloadStyle/DefaultRadioButtonStyle.cs new file mode 100644 index 0000000..ce45a95 --- /dev/null +++ b/src/Tizen.NUI.Components/PreloadStyle/DefaultRadioButtonStyle.cs @@ -0,0 +1,75 @@ +/* + * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + /// + /// The default RadioButton style + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class DefaultRadioButtonStyle : StyleBase + { + /// + /// Return default RadioButton style + /// + internal protected override ViewStyle GetAttributes() + { + ButtonStyle style = new ButtonStyle + { + Size = new Size(30, 30), + Icon = new ImageViewStyle + { + WidthResizePolicy = ResizePolicyType.DimensionDependency, + HeightResizePolicy = ResizePolicyType.SizeRelativeToParent, + SizeModeFactor = new Vector3(1, 1, 1), + Opacity = new Selector + { + Normal = 1.0f, + Selected = 1.0f, + Disabled = 0.4f, + DisabledSelected = 0.4f + }, + BackgroundImage = new Selector + { + Normal = DefaultStyle.GetResourcePath("nui_component_default_radiobutton_n.png"), + Pressed = DefaultStyle.GetResourcePath("nui_component_default_radiobutton_p.png"), + Selected = DefaultStyle.GetResourcePath("nui_component_default_radiobutton_s.png"), + Disabled = DefaultStyle.GetResourcePath("nui_component_default_radiobutton_n.png"), + DisabledSelected = DefaultStyle.GetResourcePath("nui_component_default_radiobutton_s.png"), + } + }, + Text = new TextLabelStyle + { + PointSize = new Selector { All = DefaultStyle.PointSizeNormal }, + WidthResizePolicy = ResizePolicyType.FillToParent, + HeightResizePolicy = ResizePolicyType.FillToParent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + TextColor = new Selector + { + Normal = new Color(0.22f, 0.22f, 0.22f, 1), + Pressed = new Color(0.11f, 0.11f, 0.11f, 1), + Disabled = new Color(0.66f, 0.66f, 0.66f, 1) + } + } + }; + return style; + } + } +} diff --git a/src/Tizen.NUI.Components/PreloadStyle/DefaultStyle.cs b/src/Tizen.NUI.Components/PreloadStyle/DefaultStyle.cs new file mode 100644 index 0000000..57bdd43 --- /dev/null +++ b/src/Tizen.NUI.Components/PreloadStyle/DefaultStyle.cs @@ -0,0 +1,31 @@ +/* + * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +using System.ComponentModel; + +namespace Tizen.NUI.Components +{ + internal static class DefaultStyle + { + internal const float PointSizeNormal = 12; + + static internal string GetResourcePath(string filename) + { + return "/usr/share/dotnet.tizen/framework/res/" + filename; + } + } +} diff --git a/src/Tizen.NUI.Components/PreloadStyle/DefaultSwitchStyle.cs b/src/Tizen.NUI.Components/PreloadStyle/DefaultSwitchStyle.cs new file mode 100644 index 0000000..f97e088 --- /dev/null +++ b/src/Tizen.NUI.Components/PreloadStyle/DefaultSwitchStyle.cs @@ -0,0 +1,77 @@ +/* + * Copyright(c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +using System.ComponentModel; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Components +{ + /// + /// The default Switch style + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class DefaultSwitchStyle : StyleBase + { + /// + /// Return default Switch style + /// + internal protected override ViewStyle GetAttributes() + { + SwitchStyle style = new SwitchStyle + { + Size = new Size(96, 60), + Track = new ImageViewStyle + { + ResourceUrl = new Selector + { + Normal = DefaultStyle.GetResourcePath("nui_component_default_switch_track_n.png"), + Selected = DefaultStyle.GetResourcePath("nui_component_default_switch_track_s.png"), + Disabled = DefaultStyle.GetResourcePath("nui_component_default_switch_track_d.png"), + DisabledSelected = DefaultStyle.GetResourcePath("nui_component_default_switch_track_ds.png"), + } + }, + Thumb = new ImageViewStyle + { + WidthResizePolicy = ResizePolicyType.DimensionDependency, + HeightResizePolicy = ResizePolicyType.SizeRelativeToParent, + SizeModeFactor = new Vector3(1, 1, 1), + ResourceUrl = new Selector + { + Normal = DefaultStyle.GetResourcePath("nui_component_default_switch_thumb_n.png"), + Selected = DefaultStyle.GetResourcePath("nui_component_default_switch_thumb_n.png"), + Disabled = DefaultStyle.GetResourcePath("nui_component_default_switch_thumb_d.png"), + DisabledSelected = DefaultStyle.GetResourcePath("nui_component_default_switch_thumb_d.png"), + }, + }, + Text = new TextLabelStyle + { + PointSize = new Selector { All = DefaultStyle.PointSizeNormal }, + WidthResizePolicy = ResizePolicyType.FillToParent, + HeightResizePolicy = ResizePolicyType.FillToParent, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + TextColor = new Selector + { + Normal = new Color(0.22f, 0.22f, 0.22f, 1), + Pressed = new Color(0.11f, 0.11f, 0.11f, 1), + Disabled = new Color(0.66f, 0.66f, 0.66f, 1) + } + }, + }; + return style; + } + } +} diff --git a/src/Tizen.NUI.Components/Tizen.NUI.Components.csproj b/src/Tizen.NUI.Components/Tizen.NUI.Components.csproj index de52169..039d6e9 100755 --- a/src/Tizen.NUI.Components/Tizen.NUI.Components.csproj +++ b/src/Tizen.NUI.Components/Tizen.NUI.Components.csproj @@ -19,6 +19,12 @@ + + + PreserveNewest + + + diff --git a/src/Tizen.NUI.Components/Utils/StyleManager.cs b/src/Tizen.NUI.Components/Utils/StyleManager.cs index 7c0d4e6..3bc0e85 100755 --- a/src/Tizen.NUI.Components/Utils/StyleManager.cs +++ b/src/Tizen.NUI.Components/Utils/StyleManager.cs @@ -29,9 +29,11 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public sealed class StyleManager { - private string theme = "default"; + private static readonly string defaultThemeName = "default"; + private string theme = defaultThemeName; private Dictionary> themeStyleSet = new Dictionary>(); private Dictionary defaultStyleSet = new Dictionary(); + private Dictionary> componentStyleByTheme = new Dictionary>(); private EventHandler themeChangeHander; /// @@ -41,6 +43,7 @@ namespace Tizen.NUI.Components private StyleManager() { } + /// /// An event for the theme changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.
///
@@ -160,6 +163,64 @@ namespace Tizen.NUI.Components } /// + /// Register a style for a component to theme. + /// + /// Theme + /// The type of ComponentStyle + /// The type of style + /// 6 + /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API. + [EditorBrowsable(EditorBrowsableState.Never)] + public void RegisterComponentStyle(string targetTheme, Type component, Type style) + { + if (targetTheme == null) + { + throw new ArgumentException("The argument targetTheme must be specified"); + } + + if (!componentStyleByTheme.ContainsKey(targetTheme)) + { + componentStyleByTheme.Add(targetTheme, new Dictionary()); + } + + if (componentStyleByTheme[targetTheme].ContainsKey(component)) + { + componentStyleByTheme[targetTheme][component] = Activator.CreateInstance(style) as StyleBase; + } + else + { + componentStyleByTheme[targetTheme].Add(component, Activator.CreateInstance(style) as StyleBase); + } + } + + /// + /// Get components style in the current theme. + /// + /// The type of component + [EditorBrowsable(EditorBrowsableState.Never)] + public ViewStyle GetComponentStyle(Type component) + { + var currentTheme = theme; + + if (!componentStyleByTheme.ContainsKey(theme)) + { + currentTheme = defaultThemeName; + } + + if (defaultThemeName.Equals(currentTheme) && !componentStyleByTheme.ContainsKey(defaultThemeName)) + { + LoadDefaultComponentStyle(); + } + + if (!componentStyleByTheme[currentTheme].ContainsKey(component)) + { + return null; + } + + return (componentStyleByTheme[currentTheme][component])?.GetAttributes(); + } + + /// /// ThemeChangeEventArgs is a class to record theme change event arguments which will sent to user. /// /// 6 @@ -173,5 +234,16 @@ namespace Tizen.NUI.Components [EditorBrowsable(EditorBrowsableState.Never)] public string CurrentTheme; } + + private void LoadDefaultComponentStyle() + { + componentStyleByTheme.Add(defaultThemeName, new Dictionary()); + + var defaultComponentsStyle = componentStyleByTheme[defaultThemeName]; + defaultComponentsStyle.Add(typeof(Button), new DefaultButtonStyle()); + defaultComponentsStyle.Add(typeof(CheckBox), new DefaultCheckBoxStyle()); + defaultComponentsStyle.Add(typeof(RadioButton), new DefaultRadioButtonStyle()); + defaultComponentsStyle.Add(typeof(Switch), new DefaultSwitchStyle()); + } } } diff --git a/src/Tizen.NUI.Components/res/nui_component_default_checkbox_bg_n.png b/src/Tizen.NUI.Components/res/nui_component_default_checkbox_bg_n.png new file mode 100755 index 0000000..fd70968 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_checkbox_bg_n.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_checkbox_bg_p.png b/src/Tizen.NUI.Components/res/nui_component_default_checkbox_bg_p.png new file mode 100755 index 0000000..9a3af3a Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_checkbox_bg_p.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_checkbox_s.png b/src/Tizen.NUI.Components/res/nui_component_default_checkbox_s.png new file mode 100755 index 0000000..4d22858 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_checkbox_s.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_n.png b/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_n.png new file mode 100755 index 0000000..d423241 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_n.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_p.png b/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_p.png new file mode 100755 index 0000000..e9dc2a0 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_p.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_s.png b/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_s.png new file mode 100755 index 0000000..d08e8e7 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_radiobutton_s.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_switch_thumb_d.png b/src/Tizen.NUI.Components/res/nui_component_default_switch_thumb_d.png new file mode 100755 index 0000000..cc87048 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_switch_thumb_d.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_switch_thumb_n.png b/src/Tizen.NUI.Components/res/nui_component_default_switch_thumb_n.png new file mode 100755 index 0000000..edafdc1 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_switch_thumb_n.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_switch_track_d.png b/src/Tizen.NUI.Components/res/nui_component_default_switch_track_d.png new file mode 100755 index 0000000..5c62b94 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_switch_track_d.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_switch_track_ds.png b/src/Tizen.NUI.Components/res/nui_component_default_switch_track_ds.png new file mode 100755 index 0000000..427763b Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_switch_track_ds.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_switch_track_n.png b/src/Tizen.NUI.Components/res/nui_component_default_switch_track_n.png new file mode 100755 index 0000000..93fd2c4 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_switch_track_n.png differ diff --git a/src/Tizen.NUI.Components/res/nui_component_default_switch_track_s.png b/src/Tizen.NUI.Components/res/nui_component_default_switch_track_s.png new file mode 100755 index 0000000..128f236 Binary files /dev/null and b/src/Tizen.NUI.Components/res/nui_component_default_switch_track_s.png differ