From a9f95e93e517da634abe6e7f77e3f03afd24a07f Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Mon, 5 Dec 2022 14:22:48 +0900 Subject: [PATCH] [NUI] Add SystemSettings.FontTypeChanged in Text components Setting FontFamily to UseSystemSetting in NUI Theme, the default font family follows the system setting. Signed-off-by: Bowon Ryu --- .../src/public/BaseComponents/TextEditor.cs | 93 +++++++++++++++++++++ .../BaseComponents/TextEditorBindableProperty.cs | 6 +- .../src/public/BaseComponents/TextField.cs | 93 +++++++++++++++++++++ .../BaseComponents/TextFieldBindableProperty.cs | 6 +- .../src/public/BaseComponents/TextLabel.cs | 94 ++++++++++++++++++++++ .../BaseComponents/TextLabelBindableProperty.cs | 7 +- src/Tizen.NUI/src/public/Common/NUIConstants.cs | 13 +++ .../src/public/Theme/DefaultThemeCommon.cs | 6 +- 8 files changed, 302 insertions(+), 16 deletions(-) diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs index 39b0d74..3a3f3ff 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs @@ -32,6 +32,9 @@ namespace Tizen.NUI.BaseComponents /// 3 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; + } + /// /// The TranslatableText property.
/// The text can set the SID value.
@@ -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); + } + /// /// The FontStyle property.
/// The requested font style to use.
@@ -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) diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs index 2875cb2..da5d79f 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs @@ -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)] diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs index c2bf3d5..a15df1e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -31,6 +31,9 @@ namespace Tizen.NUI.BaseComponents /// 3 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; + } + /// /// The TranslatableText property.
/// The text can set the SID value.
@@ -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); + } + /// /// The FontStyle property.
/// The requested font style to use.
@@ -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) diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs index 566ab43..b0d9c69 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs @@ -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)] diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index a4bfe7e..a3f8e3c 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -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; + } + /// /// The TranslatableText property.
/// The text can set the SID value.
@@ -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(); + } + /// /// The FontStyle property.
/// The requested font style to use.
@@ -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(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs index 82e06aa..abb797d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabelBindableProperty.cs @@ -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; } } diff --git a/src/Tizen.NUI/src/public/Common/NUIConstants.cs b/src/Tizen.NUI/src/public/Common/NUIConstants.cs index 7b5e4f9..0ece9f7 100755 --- a/src/Tizen.NUI/src/public/Common/NUIConstants.cs +++ b/src/Tizen.NUI/src/public/Common/NUIConstants.cs @@ -2037,6 +2037,19 @@ namespace Tizen.NUI } /// + /// FontFamily constant. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public struct FontFamily + { + /// + /// UseSystemSetting + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly string UseSystemSetting = string.Empty; + } + + /// /// Offset has left, right, bottom, top value. /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs b/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs index 5510be5..37dbe64 100644 --- a/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs +++ b/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs @@ -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), -- 2.7.4