*
*/
using System;
-using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
namespace Tizen.NUI
{
- /// <summary></summary>
+ /// <summary>
+ /// <para>
+ /// Basically, the Theme is a dictionary of <seealso cref="ViewStyle"/>s that can decorate NUI <seealso cref="View"/>s.
+ /// Each ViewStyle item is identified by a string key that can be matched the <seealso cref="View.StyleName"/>.
+ /// </para>
+ /// <para>
+ /// The main purpose of providing Theme is to separate style details from the structure.
+ /// Managing style separately makes it easier to customize the look of application by user context.
+ /// Also since a Theme can be created from xaml file, it can be treated as a resource.
+ /// This enables sharing styles with other applications.
+ /// </para>
+ /// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class Theme : BindableObject, IResourcesProvider
{
{
if (string.IsNullOrEmpty(xamlFile))
{
- throw new ArgumentNullException("The xaml file path cannot be null or empty string", nameof(xamlFile));
+ throw new ArgumentNullException(nameof(xamlFile), "The xaml file path cannot be null or empty string");
}
LoadFromXaml(xamlFile);
/// </summary>
/// <param name="xamlFile">An absolute path to the xaml file.</param>
/// <param name="themeResource">An absolute path to the theme resource file.</param>
- /// <exception cref="ArgumentNullException">Thrown when the given xamlFile is null or empty string.</exception>
+ /// <exception cref="ArgumentNullException">Thrown when the given xamlFile or themeResource is null or empty string.</exception>
/// <exception cref="System.IO.IOException">Thrown when there are file IO problems.</exception>
/// <exception cref="Exception">Thrown when the content of the xaml file is not valid xaml form.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
this.xamlFile = xamlFile;
}
- /// <summary></summary>
+ /// <summary>
+ /// The string key to identify the Theme.
+ /// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string Id { get; set; }
/// </summary>
/// <param name="viewType">The type of View.</param>
/// <returns>Founded style instance.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when the given viewType is null.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public ViewStyle GetStyle(Type viewType)
{
- var currentType = viewType;
+ var currentType = viewType ?? throw new ArgumentNullException(nameof(viewType));
ViewStyle resultStyle = null;
do
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
-using Tizen.NUI.Xaml;
using Tizen.NUI.BaseComponents;
namespace Tizen.NUI
{
- /// <summary></summary>
+ /// <summary>
+ /// This static module provides methods that can manage NUI <seealso cref="Theme"/>.
+ /// </summary>
+ /// <example>
+ /// To apply custom theme to the application, try <seealso cref="ApplyTheme(Theme)"/>.
+ /// <code>
+ /// var customTheme = new Theme(res + "customThemeFile.xaml");
+ /// ThemeManager.ApplyTheme(customTheme);
+ /// </code>
+ /// </example>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ThemeManager
{
private static Theme defaultTheme;
private static bool isLoadingDefault = false;
private static Profile? currentProfile;
- private static List<Theme> builtinThemes = new List<Theme>(); // Themes provided by framework.
+ private static readonly List<Theme> builtinThemes = new List<Theme>(); // Themes provided by framework.
internal static List<Theme> customThemes = new List<Theme>(); // Themes registered by user.
static ThemeManager() {}
/// <summary>
+ /// An event invoked after the theme has changed by <seealso cref="ApplyTheme(Theme)"/>.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static event EventHandler<ThemeChangedEventArgs> ThemeChanged;
internal static Theme CurrentTheme
{
- get
- {
- if (currentTheme == null)
- {
- currentTheme = DefaultTheme;
- }
- return currentTheme;
- }
+ get => currentTheme ?? (currentTheme = DefaultTheme);
set
{
currentTheme = value;
}
catch
{
+ // Note
+ // Do not rethrow exception.
+ // In some machine, profile may not exits.
Tizen.Log.Info("NUI", "Unknown device profile\n");
}
finally
[EditorBrowsable(EditorBrowsableState.Never)]
public static void ApplyFallbackTheme(Theme fallbackTheme)
{
- DefaultTheme = fallbackTheme ?? throw new ArgumentNullException("Invalid theme.");
+ DefaultTheme = fallbackTheme ?? throw new ArgumentNullException(nameof(fallbackTheme));
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static void ApplyTheme(Theme theme)
{
- var newTheme = (Theme)theme?.Clone() ?? throw new ArgumentNullException("Invalid theme.");
+ var newTheme = (Theme)theme?.Clone() ?? throw new ArgumentNullException(nameof(theme));
if (string.IsNullOrEmpty(newTheme.Id))
{
}
/// <summary>
+ /// <para>
/// Note that this API is to support legacy Tizen.NUI.Components.StyleManager.
/// Please use <seealso cref="ApplyTheme(Theme)"/> instead.
- ///
+ /// </para>
+ /// <para>
/// Apply theme to the NUI using theme id.
/// The id of theme should be either a registered custom theme or a built-in theme.
/// You can register custom theme using <seealso cref="RegisterTheme(Theme)"/>.
/// This will change the appreance of the existing components with property <seealso cref="View.ThemeChangeSensitive"/> on.
/// This also affects all components created afterwards.
+ /// </para>
/// </summary>
/// <param name="themeId">The theme Id.</param>
/// <exception cref="ArgumentNullException">Thrown when the given themeId is null.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public static void ApplyTheme(string themeId)
{
- if (themeId == null) throw new ArgumentNullException("Invalid themeId");
+ if (themeId == null) throw new ArgumentNullException(nameof(themeId));
int index = customThemes.FindIndex(x => x.Id.Equals(themeId, StringComparison.OrdinalIgnoreCase));
if (index >= 0)
CurrentTheme = customThemes[index];
return;
}
-
+
index = builtinThemes.FindIndex(x => string.Equals(x.Id, themeId, StringComparison.OrdinalIgnoreCase));
if (index >= 0)
{
}
/// <summary>
- /// Note that this API is to support legacy Tizen.NUI.Components.StyleManager.
- ///
- /// Register a custom theme that can be used as an id when calling <seealso cref="ApplyTheme(string)"/>.
+ /// <para> Note that this API is to support legacy Tizen.NUI.Components.StyleManager. </para>
+ /// <para> Register a custom theme that can be used as an id when calling <seealso cref="ApplyTheme(string)"/>. </para>
/// </summary>
/// <param name="theme">The theme instance.</param>
- /// <exception cref="ArgumentException">Thrown when the given theme is null or invalid.</exception>
+ /// <exception cref="ArgumentNullException">Thrown when the given theme is null.</exception>
+ /// <exception cref="ArgumentException">Thrown when the given theme id is invalid.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public static void RegisterTheme(Theme theme)
{
- if (theme == null || string.IsNullOrEmpty(theme.Id)) throw new ArgumentException("Invalid theme.");
+ if (theme == null) throw new ArgumentNullException(nameof(theme));
+ if (string.IsNullOrEmpty(theme.Id)) throw new ArgumentException("Invalid theme id.");
int index = customThemes.FindIndex(x => x.Id.Equals(theme.Id, StringComparison.OrdinalIgnoreCase));
if (index >= 0)
[EditorBrowsable(EditorBrowsableState.Never)]
public static ViewStyle GetStyle(string styleName)
{
- if (styleName == null) throw new ArgumentNullException("Invalid style name");
+ if (styleName == null) throw new ArgumentNullException(nameof(styleName));
if (!ThemeApplied) return null;
[EditorBrowsable(EditorBrowsableState.Never)]
public static ViewStyle GetStyle(Type viewType)
{
- if (viewType == null) throw new ArgumentNullException("Invalid viewType");
+ if (viewType == null) throw new ArgumentNullException(nameof(viewType));
if (!ThemeApplied) return null;
[EditorBrowsable(EditorBrowsableState.Never)]
public static Theme GetBuiltinTheme(string themeId)
{
- if (themeId == null) throw new ArgumentNullException("Invalid themeId");
+ if (themeId == null) throw new ArgumentNullException(nameof(themeId));
Theme result = null;
int index = builtinThemes.FindIndex(x => string.Equals(x.Id, themeId, StringComparison.OrdinalIgnoreCase));