[NUI] Add SystemSettings.FontTypeChanged in Text components
authorBowon Ryu <bowon.ryu@samsung.com>
Mon, 5 Dec 2022 05:22:48 +0000 (14:22 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 26 Apr 2023 01:53:38 +0000 (10:53 +0900)
Setting FontFamily to UseSystemSetting in NUI Theme,
the default font family follows the system setting.

Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/TextField.cs
src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs
src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs
src/Tizen.NUI/src/public/Common/NUIConstants.cs
src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs

index 39b0d74..3a3f3ff 100755 (executable)
@@ -32,6 +32,9 @@ namespace Tizen.NUI.BaseComponents
     /// <since_tizen> 3 </since_tizen>
     public partial class TextEditor : View
     {
+        static private string defaultFontFamily = "TizenSans";
+        private string fontFamily = defaultFontFamily;
+        private bool hasSystemFontTypeChanged = false;
         private string textEditorTextSid = null;
         private string textEditorPlaceHolderTextSid = null;
         private bool systemlangTextFlag = false;
@@ -96,6 +99,11 @@ namespace Tizen.NUI.BaseComponents
             TextChanged += TextEditorTextChanged;
         }
 
+        private bool HasStyle()
+        {
+            return ThemeManager.GetStyle(this.GetType()) == null ? false : true;
+        }
+
         /// <summary>
         /// The TranslatableText property.<br />
         /// The text can set the SID value.<br />
@@ -229,6 +237,50 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private string InternalFontFamily
+        {
+            get
+            {
+                if (HasStyle())
+                    return fontFamily;
+                else
+                    return Object.InternalGetPropertyString(this.SwigCPtr, TextEditor.Property.FontFamily);
+            }
+            set
+            {
+                string newFontFamily;
+
+                if (string.Equals(fontFamily, value)) return;
+
+                fontFamily = value;
+                if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting)
+                {
+                    try
+                    {
+                        newFontFamily = SystemSettings.FontType;
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine("{0} Exception caught.", e);
+                        newFontFamily = defaultFontFamily;
+                    }
+                    AddSystemSettingsFontTypeChanged();
+                }
+                else
+                {
+                    newFontFamily = fontFamily;
+                    RemoveSystemSettingsFontTypeChanged();
+                }
+
+                SetInternalFontFamily(newFontFamily);
+            }
+        }
+
+        private void SetInternalFontFamily(string fontFamily)
+        {
+            Object.InternalSetPropertyString(this.SwigCPtr, TextEditor.Property.FontFamily, (string)fontFamily);
+        }
+
         /// <summary>
         /// The FontStyle property.<br />
         /// The requested font style to use.<br />
@@ -2457,6 +2509,8 @@ namespace Tizen.NUI.BaseComponents
                 SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged;
             }
 
+            RemoveSystemSettingsFontTypeChanged();
+
             removeFontSizeChangedCallback();
 
             //Release your own unmanaged resources here.
@@ -2593,6 +2647,45 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private void SystemSettingsFontTypeChanged(object sender, FontTypeChangedEventArgs e)
+        {
+            SetInternalFontFamily(e.Value);
+        }
+
+        private void AddSystemSettingsFontTypeChanged()
+        {
+            if (HasStyle() && !hasSystemFontTypeChanged)
+            {
+                try
+                {
+                    SystemSettings.FontTypeChanged += SystemSettingsFontTypeChanged;
+                    hasSystemFontTypeChanged = true;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("{0} Exception caught.", e);
+                    hasSystemFontTypeChanged = false;
+                }
+            }
+        }
+        
+        private void RemoveSystemSettingsFontTypeChanged()
+        {
+            if (hasSystemFontTypeChanged)
+            {
+                try
+                {
+                    SystemSettings.FontTypeChanged -= SystemSettingsFontTypeChanged;
+                    hasSystemFontTypeChanged = false;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("{0} Exception caught.", e);
+                    hasSystemFontTypeChanged = true;
+                }
+            }
+        }
+
         private void TextEditorTextChanged(object sender, TextChangedEventArgs e)
         {
             if (!isSettingTextInCSharp)
index 2875cb2..da5d79f 100755 (executable)
@@ -74,15 +74,13 @@ namespace Tizen.NUI.BaseComponents
             var textEditor = (TextEditor)bindable;
             if (newValue != null)
             {
-
-                Object.InternalSetPropertyString(textEditor.SwigCPtr, TextEditor.Property.FontFamily, (string)newValue);
+                textEditor.InternalFontFamily = (string)newValue;
             }
         }),
         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
         {
             var textEditor = (TextEditor)bindable;
-
-            return Object.InternalGetPropertyString(textEditor.SwigCPtr, TextEditor.Property.FontFamily);
+            return textEditor.InternalFontFamily;
         }));
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
index c2bf3d5..a15df1e 100755 (executable)
@@ -31,6 +31,9 @@ namespace Tizen.NUI.BaseComponents
     /// <since_tizen> 3 </since_tizen>
     public partial class TextField : View
     {
+        static private string defaultFontFamily = "TizenSans";
+        private string fontFamily = defaultFontFamily;
+        private bool hasSystemFontTypeChanged = false;
         private string textFieldTextSid = null;
         private string textFieldPlaceHolderTextSid = null;
         private string textFieldPlaceHolderTextFocusedSid = null;
@@ -114,6 +117,11 @@ namespace Tizen.NUI.BaseComponents
             ExceedPolicyClip
         }
 
+        private bool HasStyle()
+        {
+            return ThemeManager.GetStyle(this.GetType()) == null ? false : true;
+        }
+
         /// <summary>
         /// The TranslatableText property.<br />
         /// The text can set the SID value.<br />
@@ -298,6 +306,50 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private string InternalFontFamily
+        {
+            get
+            {
+                if (HasStyle())
+                    return fontFamily;
+                else
+                    return Object.InternalGetPropertyString(this.SwigCPtr, TextField.Property.FontFamily);
+            }
+            set
+            {
+                string newFontFamily;
+
+                if (string.Equals(fontFamily, value)) return;
+
+                fontFamily = value;
+                if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting)
+                {
+                    try
+                    {
+                        newFontFamily = SystemSettings.FontType;
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine("{0} Exception caught.", e);
+                        newFontFamily = defaultFontFamily;
+                    }
+                    AddSystemSettingsFontTypeChanged();
+                }
+                else
+                {
+                    newFontFamily = fontFamily;
+                    RemoveSystemSettingsFontTypeChanged();
+                }
+
+                SetInternalFontFamily(newFontFamily);
+            }
+        }
+
+        private void SetInternalFontFamily(string fontFamily)
+        {
+            Object.InternalSetPropertyString(this.SwigCPtr, TextField.Property.FontFamily, (string)fontFamily);
+        }
+
         /// <summary>
         /// The FontStyle property.<br />
         /// The requested font style to use.<br />
@@ -2458,6 +2510,8 @@ namespace Tizen.NUI.BaseComponents
                 SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged;
             }
 
+            RemoveSystemSettingsFontTypeChanged();
+
             removeFontSizeChangedCallback();
 
             if (type == DisposeTypes.Explicit)
@@ -2605,6 +2659,45 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private void SystemSettingsFontTypeChanged(object sender, FontTypeChangedEventArgs e)
+        {
+            SetInternalFontFamily(e.Value);
+        }
+
+        private void AddSystemSettingsFontTypeChanged()
+        {
+            if (HasStyle() && !hasSystemFontTypeChanged)
+            {
+                try
+                {
+                    SystemSettings.FontTypeChanged += SystemSettingsFontTypeChanged;
+                    hasSystemFontTypeChanged = true;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("{0} Exception caught.", e);
+                    hasSystemFontTypeChanged = false;
+                }
+            }
+        }
+        
+        private void RemoveSystemSettingsFontTypeChanged()
+        {
+            if (hasSystemFontTypeChanged)
+            {
+                try
+                {
+                    SystemSettings.FontTypeChanged -= SystemSettingsFontTypeChanged;
+                    hasSystemFontTypeChanged = false;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("{0} Exception caught.", e);
+                    hasSystemFontTypeChanged = true;
+                }
+            }
+        }
+
         private void TextFieldTextChanged(object sender, TextChangedEventArgs e)
         {
             if (!isSettingTextInCSharp)
index 566ab43..b0d9c69 100755 (executable)
@@ -137,15 +137,13 @@ namespace Tizen.NUI.BaseComponents
             var textField = (TextField)bindable;
             if (newValue != null)
             {
-
-                Object.InternalSetPropertyString(textField.SwigCPtr, TextField.Property.FontFamily, (string)newValue);
+                textField.InternalFontFamily = (string)newValue;
             }
         }),
         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
         {
             var textField = (TextField)bindable;
-
-            return Object.InternalGetPropertyString(textField.SwigCPtr, TextField.Property.FontFamily);
+            return textField.InternalFontFamily;
         }));
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
index a4bfe7e..a3f8e3c 100755 (executable)
@@ -81,6 +81,9 @@ namespace Tizen.NUI.BaseComponents
 
         static TextLabel() { }
 
+        static private string defaultFontFamily = "TizenSans";
+        private string fontFamily = defaultFontFamily;
+        private bool hasSystemFontTypeChanged = false;
         private string textLabelSid = null;
         private bool systemlangTextFlag = false;
         private TextLabelSelectorData selectorData;
@@ -166,6 +169,11 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private bool HasStyle()
+        {
+            return ThemeManager.GetStyle(this.GetType()) == null ? false : true;
+        }
+
         /// <summary>
         /// The TranslatableText property.<br />
         /// The text can set the SID value.<br />
@@ -253,6 +261,51 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private string InternalFontFamily
+        {
+            get
+            {
+                if (HasStyle())
+                    return fontFamily;
+                else
+                    return Object.InternalGetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily);
+            }
+            set
+            {
+                string newFontFamily;
+
+                if (string.Equals(fontFamily, value)) return;
+
+                fontFamily = value;
+                if (fontFamily == Tizen.NUI.FontFamily.UseSystemSetting)
+                {
+                    try
+                    {
+                        newFontFamily = SystemSettings.FontType;
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine("{0} Exception caught.", e);
+                        newFontFamily = defaultFontFamily;
+                    }
+                    AddSystemSettingsFontTypeChanged();
+                }
+                else
+                {
+                    newFontFamily = fontFamily;
+                    RemoveSystemSettingsFontTypeChanged();
+                }
+
+                SetInternalFontFamily(newFontFamily);
+            }
+        }
+
+        private void SetInternalFontFamily(string fontFamily)
+        {
+            Object.InternalSetPropertyString(this.SwigCPtr, TextLabel.Property.FontFamily, (string)fontFamily);
+            RequestLayout();
+        }
+
         /// <summary>
         /// The FontStyle property.<br />
         /// The requested font style to use.<br />
@@ -1519,6 +1572,8 @@ namespace Tizen.NUI.BaseComponents
                 SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged;
             }
 
+            RemoveSystemSettingsFontTypeChanged();
+
             removeFontSizeChangedCallback();
 
             if (type == DisposeTypes.Explicit)
@@ -1614,6 +1669,45 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private void SystemSettingsFontTypeChanged(object sender, FontTypeChangedEventArgs e)
+        {
+            SetInternalFontFamily(e.Value);
+        }
+
+        private void AddSystemSettingsFontTypeChanged()
+        {
+            if (HasStyle() && !hasSystemFontTypeChanged)
+            {
+                try
+                {
+                    SystemSettings.FontTypeChanged += SystemSettingsFontTypeChanged;
+                    hasSystemFontTypeChanged = true;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("{0} Exception caught.", e);
+                    hasSystemFontTypeChanged = false;
+                }
+            }
+        }
+        
+        private void RemoveSystemSettingsFontTypeChanged()
+        {
+            if (hasSystemFontTypeChanged)
+            {
+                try
+                {
+                    SystemSettings.FontTypeChanged -= SystemSettingsFontTypeChanged;
+                    hasSystemFontTypeChanged = false;
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine("{0} Exception caught.", e);
+                    hasSystemFontTypeChanged = true;
+                }
+            }
+        }
+
         private void RequestLayout()
         {
             Layout?.RequestLayout();
index 82e06aa..abb797d 100755 (executable)
@@ -92,8 +92,7 @@ namespace Tizen.NUI.BaseComponents
         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
         {
             var textLabel = (TextLabel)bindable;
-
-            return Object.InternalGetPropertyString(textLabel.SwigCPtr, TextLabel.Property.FontFamily);
+            return textLabel.InternalFontFamily;
         }));
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -909,9 +908,7 @@ namespace Tizen.NUI.BaseComponents
         {
             if (value != null)
             {
-
-                Object.InternalSetPropertyString(SwigCPtr, TextLabel.Property.FontFamily, value);
-                RequestLayout();
+                InternalFontFamily = (string)value;
             }
         }
 
index 7b5e4f9..0ece9f7 100755 (executable)
@@ -2037,6 +2037,19 @@ namespace Tizen.NUI
     }
 
     /// <summary>
+    /// FontFamily constant.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public struct FontFamily
+    {
+        /// <summary>
+        /// UseSystemSetting
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly string UseSystemSetting = string.Empty;
+    }
+
+    /// <summary>
     /// Offset has left, right, bottom, top value.
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
index 5510be5..37dbe64 100644 (file)
@@ -37,7 +37,7 @@ namespace Tizen.NUI
             // TextLabel style.
             theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextLabel", new TextLabelStyle()
             {
-                FontFamily = "TizenSans",
+                FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
                 PixelSize = 24,
                 TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
                 FontStyle = new PropertyMap().Add("weight", new PropertyValue("regular")),
@@ -50,7 +50,7 @@ namespace Tizen.NUI
             // TextField style.
             theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextField", new TextFieldStyle()
             {
-                FontFamily = "TizenSans",
+                FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
                 PixelSize = 24,
                 TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
                 PlaceholderTextColor = new Vector4(0.79f, 0.79f, 0.79f, 1),
@@ -87,7 +87,7 @@ namespace Tizen.NUI
             // TextEditor style.
             theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextEditor", new TextEditorStyle()
             {
-                FontFamily = "TizenSans",
+                FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
                 PixelSize = 24,
                 TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
                 PlaceholderTextColor = new Color(0.79f, 0.79f, 0.79f, 1),