Skip to content

Commit

Permalink
[NUI] Minimize system settings API calls in Text
Browse files Browse the repository at this point in the history
Each text component's call to the system API takes a lot of time.
Especially for FontType, initialization of FontConfig occurs natively and consumes most of the time.

This patch updates through static classes only when a specific value is needed.

TODO: manager should handle all events.

Signed-off-by: Bowon Ryu <[email protected]>
  • Loading branch information
wonrst committed Feb 25, 2025
1 parent 22c03f2 commit 3ddcfc7
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Samsung Electronics Co., Ltd.
* Copyright (c) 2025 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.
Expand Down Expand Up @@ -58,10 +58,24 @@ public static void Remove(EventHandler<FontSizeChangedEventArgs> handler)

private static void SystemFontSizeChanged(object sender, FontSizeChangedEventArgs args)
{
fontSize = args.Value;
proxy.Invoke(sender, args);
Finished?.Invoke(sender, args);
}

public static SystemSettingsFontSize FontSize
{
get
{
if (fontSize == null)
{
fontSize = SystemSettings.FontSize;
}
return fontSize ?? SystemSettingsFontSize.Normal;
}
}

private static SystemSettingsFontSize? fontSize = null;
private static WeakEvent<EventHandler<FontSizeChangedEventArgs>> proxy = new WeakEvent<EventHandler<FontSizeChangedEventArgs>>();
}
}
81 changes: 81 additions & 0 deletions src/Tizen.NUI/src/internal/Common/SystemFontTypeChangedManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2025 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.
*
*/

extern alias TizenSystemSettings;
using TizenSystemSettings.Tizen.System;

using System;

namespace Tizen.NUI
{
/// <summary>
/// A static class which adds user handler to the SystemSettings.FontTypeChanged event.
/// This class also adds user handler to the last of the SystemSettings.FontTypeChanged event.
/// </summary>
internal static class SystemFontTypeChangedManager
{
static SystemFontTypeChangedManager()
{
SystemSettings.FontTypeChanged += SystemFontTypeChanged;
}

/// <summary>
/// The handler invoked last after all handlers added to the SystemSettings.FontTypeChanged event are invoked.
/// </summary>
public static event EventHandler<FontTypeChangedEventArgs> Finished;

/// <summary>
/// Adds the given handler to the SystemSettings.FontTypeChanged event.
/// </summary>
/// <param name="handler">A handler to be added to the event</param>
public static void Add(EventHandler<FontTypeChangedEventArgs> handler)
{
proxy.Add(handler);
}

/// <summary>
/// Removes the given handler from the SystemSettings.FontTypeChanged event.
/// </summary>
/// <param name="handler">A handler to be added to the event</param>
public static void Remove(EventHandler<FontTypeChangedEventArgs> handler)
{
proxy.Remove(handler);
}

private static void SystemFontTypeChanged(object sender, FontTypeChangedEventArgs args)
{
fontType = args.Value;
proxy.Invoke(sender, args);
Finished?.Invoke(sender, args);
}

public static string FontType
{
get
{
if (string.IsNullOrEmpty(fontType))
{
fontType = SystemSettings.FontType;
}
return fontType;
}
}

private static string fontType = string.Empty;
private static WeakEvent<EventHandler<FontTypeChangedEventArgs>> proxy = new WeakEvent<EventHandler<FontTypeChangedEventArgs>>();
}
}
11 changes: 5 additions & 6 deletions src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2021 Samsung Electronics Co., Ltd.
* Copyright(c) 2025 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.
Expand Down Expand Up @@ -34,7 +34,6 @@ public partial class TextEditor : View
{
static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextEditor";
static private string defaultFontFamily = "TizenSans";
private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged();
private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged();
private string textEditorTextSid = null;
private string textEditorPlaceHolderTextSid = null;
Expand Down Expand Up @@ -486,7 +485,7 @@ private string InternalFontFamily
{
try
{
newFontFamily = SystemSettings.FontType;
newFontFamily = SystemFontTypeChangedManager.FontType;
}
catch (Exception e)
{
Expand Down Expand Up @@ -3424,7 +3423,7 @@ private float InternalFontSizeScale

try
{
systemSettingsFontSize = SystemSettings.FontSize;
systemSettingsFontSize = SystemFontSizeChangedManager.FontSize;
}
catch (Exception e)
{
Expand Down Expand Up @@ -3978,7 +3977,7 @@ private void AddSystemSettingsFontTypeChanged()
{
try
{
systemFontTypeChanged.Add(SystemSettingsFontTypeChanged);
SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged);
hasSystemFontTypeChanged = true;
}
catch (Exception e)
Expand All @@ -3995,7 +3994,7 @@ private void RemoveSystemSettingsFontTypeChanged()
{
try
{
systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged);
SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged);
hasSystemFontTypeChanged = false;
}
catch (Exception e)
Expand Down
11 changes: 5 additions & 6 deletions src/Tizen.NUI/src/public/BaseComponents/TextField.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2021 Samsung Electronics Co., Ltd.
* Copyright(c) 2025 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.
Expand Down Expand Up @@ -33,7 +33,6 @@ public partial class TextField : View
{
static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextField";
static private string defaultFontFamily = "TizenSans";
private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged();
private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged();
private string textFieldTextSid = null;
private string textFieldPlaceHolderTextSid = null;
Expand Down Expand Up @@ -636,7 +635,7 @@ private string InternalFontFamily
{
try
{
newFontFamily = SystemSettings.FontType;
newFontFamily = SystemFontTypeChangedManager.FontType;
}
catch (Exception e)
{
Expand Down Expand Up @@ -3602,7 +3601,7 @@ private float InternalFontSizeScale

try
{
systemSettingsFontSize = SystemSettings.FontSize;
systemSettingsFontSize = SystemFontSizeChangedManager.FontSize;
}
catch (Exception e)
{
Expand Down Expand Up @@ -3975,7 +3974,7 @@ private void AddSystemSettingsFontTypeChanged()
{
try
{
systemFontTypeChanged.Add(SystemSettingsFontTypeChanged);
SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged);
hasSystemFontTypeChanged = true;
}
catch (Exception e)
Expand All @@ -3992,7 +3991,7 @@ private void RemoveSystemSettingsFontTypeChanged()
{
try
{
systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged);
SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged);
hasSystemFontTypeChanged = false;
}
catch (Exception e)
Expand Down
11 changes: 5 additions & 6 deletions src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2023 Samsung Electronics Co., Ltd.
* Copyright(c) 2025 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.
Expand Down Expand Up @@ -228,7 +228,6 @@ static TextLabel()
// Do nothing. Just call for load static values.
}

private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged();
private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged();
static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextLabel";
static private string defaultFontFamily = "BreezeSans";
Expand Down Expand Up @@ -555,7 +554,7 @@ private string InternalFontFamily
{
try
{
newFontFamily = SystemSettings.FontType;
newFontFamily = SystemFontTypeChangedManager.FontType;
}
catch (Exception e)
{
Expand Down Expand Up @@ -2560,7 +2559,7 @@ private float InternalFontSizeScale

try
{
systemSettingsFontSize = SystemSettings.FontSize;
systemSettingsFontSize = SystemFontSizeChangedManager.FontSize;
}
catch (Exception e)
{
Expand Down Expand Up @@ -2908,7 +2907,7 @@ private void AddSystemSettingsFontTypeChanged()
{
try
{
systemFontTypeChanged.Add(SystemSettingsFontTypeChanged);
SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged);
hasSystemFontTypeChanged = true;
}
catch (Exception e)
Expand All @@ -2925,7 +2924,7 @@ private void RemoveSystemSettingsFontTypeChanged()
{
try
{
systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged);
SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged);
hasSystemFontTypeChanged = false;
}
catch (Exception e)
Expand Down
6 changes: 3 additions & 3 deletions src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Theme Create()
// TextLabel style.
theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextLabel", new TextLabelStyle()
{
FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
FontFamily = "BreezeSans",
PixelSize = 24,
TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
FontStyle = new PropertyMap().Add("weight", "regular"),
Expand All @@ -52,7 +52,7 @@ public Theme Create()
// TextField style.
theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextField", new TextFieldStyle()
{
FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
FontFamily = "BreezeSans",
PixelSize = 24,
TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
PlaceholderTextColor = new Vector4(0.79f, 0.79f, 0.79f, 1),
Expand Down Expand Up @@ -89,7 +89,7 @@ public Theme Create()
// TextEditor style.
theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextEditor", new TextEditorStyle()
{
FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
FontFamily = "BreezeSans",
PixelSize = 24,
TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
PlaceholderTextColor = new Color(0.79f, 0.79f, 0.79f, 1),
Expand Down

0 comments on commit 3ddcfc7

Please sign in to comment.