From 6692a2dc06c1a537c7d4858dd8779ef19ed77bbe Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 23 Mar 2020 07:58:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`Title`=E7=9A=84`textStyle`?= =?UTF-8?q?=E5=92=8C`subTextStyle`=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + Runtime/Component/Main/Title.cs | 41 +++++++++++++++++++++++++----- Runtime/Helper/TitleHelper.cs | 34 +++++++++++++++++++++++++ Runtime/Helper/TitleHelper.cs.meta | 11 ++++++++ Runtime/Internal/BaseChart.cs | 8 ++++-- 5 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 Runtime/Helper/TitleHelper.cs create mode 100644 Runtime/Helper/TitleHelper.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ae7482e..6a150f11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 更新日志 +* (2020.03.23) 修复`Title`的`textStyle`和`subTextStyle`无效的问题 * (2020.03.22) 增加`BarChart`通过`barType`参数设置`胶囊柱状图` * (2020.03.21) 增加`BarChart`和`HeatmapChart`可通过`ignore`参数设置忽略数据的支持 * (2020.03.21) 增加`ItemStyle`的`tooltipFormatter`参数可单独配置`Serie`的`Tooltip`显示 diff --git a/Runtime/Component/Main/Title.cs b/Runtime/Component/Main/Title.cs index 69689725..0eadfc3a 100644 --- a/Runtime/Component/Main/Title.cs +++ b/Runtime/Component/Main/Title.cs @@ -46,37 +46,64 @@ namespace XCharts /// /// 主标题文本样式。 /// - public TextStyle textStyle { get { return m_TextStyle; } set { if (PropertyUtility.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } } + public TextStyle textStyle + { + get { return m_TextStyle; } + set { if (PropertyUtility.SetClass(ref m_TextStyle, value)) SetComponentDirty(); } + } /// /// Subtitle text, supporting for \n for newlines. /// 副标题文本,支持使用 \n 换行。 /// - public string subText { get { return m_SubText; } set { if (PropertyUtility.SetClass(ref m_SubText, value)) SetComponentDirty(); } } + public string subText + { + get { return m_SubText; } + set { if (PropertyUtility.SetClass(ref m_SubText, value)) SetComponentDirty(); } + } /// /// 副标题文本样式。 /// - public TextStyle subTextStyle { get { return m_SubTextStyle; } set { if (PropertyUtility.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); } } + public TextStyle subTextStyle + { + get { return m_SubTextStyle; } + set { if (PropertyUtility.SetClass(ref m_SubTextStyle, value)) SetComponentDirty(); } + } /// /// [default:14] /// subtitle font size. /// 副标题文字的字体大小。 /// [Obsolete("use subTextStyle instead.", true)] - public int subTextFontSize { get { return m_SubTextStyle.fontSize; } set { m_SubTextStyle.fontSize = value; } } + public int subTextFontSize + { + get { return m_SubTextStyle.fontSize; } + set { m_SubTextStyle.fontSize = value; } + } /// /// [default:8] /// The gap between the main title and subtitle. /// 主副标题之间的间距。 /// - public float itemGap { get { return m_ItemGap; } set { if (PropertyUtility.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); } } + public float itemGap + { + get { return m_ItemGap; } + set { if (PropertyUtility.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); } + } /// /// The location of title component. /// 标题显示位置。 /// - public Location location { get { return m_Location; } set { if (PropertyUtility.SetClass(ref m_Location, value)) SetComponentDirty(); } } + public Location location + { + get { return m_Location; } + set { if (PropertyUtility.SetClass(ref m_Location, value)) SetComponentDirty(); } + } public override bool vertsDirty { get { return false; } } - public override bool componentDirty { get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty || subTextStyle.componentDirty; } } + public override bool componentDirty + { + get { return m_ComponentDirty || location.componentDirty || textStyle.componentDirty || subTextStyle.componentDirty; } + } internal override void ClearComponentDirty() { diff --git a/Runtime/Helper/TitleHelper.cs b/Runtime/Helper/TitleHelper.cs new file mode 100644 index 00000000..64da6c76 --- /dev/null +++ b/Runtime/Helper/TitleHelper.cs @@ -0,0 +1,34 @@ +/******************************************/ +/* */ +/* Copyright (c) 2018 monitor1394 */ +/* https://github.com/monitor1394 */ +/* */ +/******************************************/ +using UnityEngine; +using UnityEngine.UI; + +namespace XCharts +{ + internal static class TitleHelper + { + public static Font GetTextFont(Title title, ThemeInfo themeInfo) + { + return (title.textStyle.font != null) ? title.textStyle.font : themeInfo.font; + } + + public static Color GetTextColor(Title title, ThemeInfo themeInfo) + { + return title.textStyle.color != Color.clear ? title.textStyle.color : (Color)themeInfo.titleTextColor; + } + + public static Font GetSubTextFont(Title title, ThemeInfo themeInfo) + { + return (title.subTextStyle.font != null) ? title.subTextStyle.font : themeInfo.font; + } + + public static Color GetSubTextColor(Title title, ThemeInfo themeInfo) + { + return title.subTextStyle.color != Color.clear ? title.subTextStyle.color : (Color)themeInfo.titleSubTextColor; + } + } +} \ No newline at end of file diff --git a/Runtime/Helper/TitleHelper.cs.meta b/Runtime/Helper/TitleHelper.cs.meta new file mode 100644 index 00000000..8328b249 --- /dev/null +++ b/Runtime/Helper/TitleHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8c96205317b864d6c8c08ec45c27933c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 8c4b56ea..4edb6392 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -233,8 +233,10 @@ namespace XCharts titleObject.transform.localPosition = titlePosition; ChartHelper.HideAllObject(titleObject); + var textFont = TitleHelper.GetTextFont(title, themeInfo); + var textColor = TitleHelper.GetTextColor(title, themeInfo); Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, - m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot, + textFont, textColor, anchor, anchorMin, anchorMax, pivot, new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize, m_Title.textStyle.rotate, m_Title.textStyle.fontStyle, m_Title.textStyle.lineSpacing); @@ -243,8 +245,10 @@ namespace XCharts titleText.transform.localPosition = Vector3.zero + m_Title.textStyle.offsetv3; titleText.text = m_Title.text.Replace("\\n", "\n"); + var subTextFont = TitleHelper.GetSubTextFont(title, themeInfo); + var subTextColor = TitleHelper.GetSubTextColor(title, themeInfo); Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform, - m_ThemeInfo.font, m_ThemeInfo.titleSubTextColor, anchor, anchorMin, anchorMax, pivot, + subTextFont, subTextColor, anchor, anchorMin, anchorMax, pivot, new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize, m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle, m_Title.subTextStyle.lineSpacing);