From beee233570e24006f5e30446353c5aa9af52fd15 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 15 Dec 2019 21:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Title=E7=9A=84TextStyle?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + Documentation/XCharts配置项手册.md | 4 +-- Editor/PropertyDrawers/TitleDrawer.cs | 21 ++++++++-------- Runtime/Component/Main/Title.cs | 36 +++++++++++++++++---------- Runtime/Component/Sub/TextStyle.cs | 11 ++++++++ Runtime/Internal/BaseChart.cs | 12 +++++---- Runtime/Utility/XChartsMgr.cs | 2 +- version.json | 4 +-- 8 files changed, 58 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 208065dd..19dfe713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 更新日志 +* (2019.12.15) 增加`Title`的`TextStyle`支持 * (2019.12.11) 修复`Legend`都隐藏时`Value轴`还显示数值的问题 * (2019.12.11) 修复`Series->Data->Size`重置为0后设置无效的问题 * (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题 diff --git a/Documentation/XCharts配置项手册.md b/Documentation/XCharts配置项手册.md index af1cd03c..f2a23a38 100644 --- a/Documentation/XCharts配置项手册.md +++ b/Documentation/XCharts配置项手册.md @@ -84,9 +84,9 @@ * `show`:是否显示标题组件。 * `text`:主标题文本,支持使用 `\n` 换行。 -* `textFontSize`:主标题文字的字体大小。 +* `textStyle`:主标题文本样式 [TextStyle](#TextStyle)。 * `subText`:副标题文本,支持使用 `\n` 换行。 -* `subTextFontSize`:副标题文字的字体大小。 +* `subTextStyle`:副标题文本样式 [TextStyle](#TextStyle)。 * `itemGap`:主副标题之间的间距。 * `location`:标题显示位置 [Location](#Location)。 diff --git a/Editor/PropertyDrawers/TitleDrawer.cs b/Editor/PropertyDrawers/TitleDrawer.cs index d28ebe52..7e7cb324 100644 --- a/Editor/PropertyDrawers/TitleDrawer.cs +++ b/Editor/PropertyDrawers/TitleDrawer.cs @@ -21,9 +21,9 @@ namespace XCharts drawRect.height = EditorGUIUtility.singleLineHeight; SerializedProperty show = prop.FindPropertyRelative("m_Show"); SerializedProperty text = prop.FindPropertyRelative("m_Text"); - SerializedProperty m_TextFontSize = prop.FindPropertyRelative("m_TextFontSize"); + SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle"); SerializedProperty subText = prop.FindPropertyRelative("m_SubText"); - SerializedProperty m_SubTextFontSize = prop.FindPropertyRelative("m_SubTextFontSize"); + SerializedProperty m_SubTextStyle = prop.FindPropertyRelative("m_SubTextStyle"); SerializedProperty m_ItemGap = prop.FindPropertyRelative("m_ItemGap"); SerializedProperty location = prop.FindPropertyRelative("m_Location"); @@ -35,17 +35,17 @@ namespace XCharts EditorGUI.PropertyField(drawRect, text); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_TextFontSize, new GUIContent("Font Size")); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_TextStyle); + drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle); --EditorGUI.indentLevel; EditorGUI.PropertyField(drawRect, subText); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; ++EditorGUI.indentLevel; - EditorGUI.PropertyField(drawRect, m_SubTextFontSize, new GUIContent("Font Size")); - drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_SubTextStyle); + drawRect.y += EditorGUI.GetPropertyHeight(m_SubTextStyle); + --EditorGUI.indentLevel; EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap")); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; - --EditorGUI.indentLevel; EditorGUI.PropertyField(drawRect, location); } --EditorGUI.indentLevel; @@ -56,9 +56,10 @@ namespace XCharts float height = 0; if (m_TitleModuleToggle) { - height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing; - SerializedProperty location = prop.FindPropertyRelative("m_Location"); - height += EditorGUI.GetPropertyHeight(location); + height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; + height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle")); + height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SubTextStyle")); + height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Location")); } height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; return height; diff --git a/Runtime/Component/Main/Title.cs b/Runtime/Component/Main/Title.cs index 136d5eeb..6138baf9 100644 --- a/Runtime/Component/Main/Title.cs +++ b/Runtime/Component/Main/Title.cs @@ -19,11 +19,11 @@ namespace XCharts { [SerializeField] private bool m_Show = true; [SerializeField] private string m_Text; - [SerializeField] private int m_TextFontSize; + [SerializeField] private TextStyle m_TextStyle = new TextStyle(16); [SerializeField] private string m_SubText; - [SerializeField] private int m_SubTextFontSize; - [SerializeField] private float m_ItemGap; - [SerializeField] private Location m_Location; + [SerializeField] private TextStyle m_SubTextStyle = new TextStyle(14); + [SerializeField] private float m_ItemGap = 8; + [SerializeField] private Location m_Location = Location.defaultTop; /// /// [default:true] @@ -41,20 +41,30 @@ namespace XCharts /// main title font size. /// 主标题文字的字体大小。 /// - public int textFontSize { get { return m_TextFontSize; } set { m_TextFontSize = value; } } + [Obsolete("use textStyle instead.", false)] + public int textFontSize { get { return m_TextStyle.fontSize; } set { m_TextStyle.fontSize = value; } } + /// + /// 主标题文本样式。 + /// + public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } } /// /// Subtitle text, supporting for \n for newlines. /// 副标题文本,支持使用 \n 换行。 /// public string subText { get { return m_SubText; } set { m_SubText = value; } } /// + /// 副标题文本样式。 + /// + public TextStyle subTextStyle { get { return m_SubTextStyle; } set { m_SubTextStyle = value; } } + /// /// [default:14] /// subtitle font size. /// 副标题文字的字体大小。 /// - public int subTextFontSize { get { return m_SubTextFontSize; } set { m_SubTextFontSize = value; } } + [Obsolete("use subTextStyle instead.", false)] + public int subTextFontSize { get { return m_SubTextStyle.fontSize; } set { m_SubTextStyle.fontSize = value; } } /// - /// [default:14] + /// [default:8] /// The gap between the main title and subtitle. /// 主副标题之间的间距。 /// @@ -73,9 +83,9 @@ namespace XCharts { m_Show = true, m_Text = "Chart Title", - m_TextFontSize = 16, + m_TextStyle = new TextStyle(16), m_SubText = "", - m_SubTextFontSize = 14, + m_SubTextStyle = new TextStyle(14), m_ItemGap = 8, m_Location = Location.defaultTop }; @@ -86,9 +96,9 @@ namespace XCharts { m_Show = title.show; m_Text = title.text; - m_TextFontSize = title.textFontSize; + m_TextStyle.Copy(title.textStyle); + m_SubTextStyle.Copy(title.subTextStyle); m_SubText = title.subText; - m_SubTextFontSize = title.subTextFontSize; m_ItemGap = title.itemGap; m_Location.Copy(title.location); } @@ -117,9 +127,9 @@ namespace XCharts } return m_Show == other.show && m_Text.Equals(other.text) && - m_TextFontSize == other.textFontSize && + m_TextStyle.Equals(other.textStyle) && m_SubText.Equals(other.subText) && - m_SubTextFontSize == other.subTextFontSize && + m_SubTextStyle.Equals(other.subTextStyle) && m_ItemGap == other.itemGap && m_Location.Equals(other.location); } diff --git a/Runtime/Component/Sub/TextStyle.cs b/Runtime/Component/Sub/TextStyle.cs index 31a68656..79518a4a 100644 --- a/Runtime/Component/Sub/TextStyle.cs +++ b/Runtime/Component/Sub/TextStyle.cs @@ -35,6 +35,8 @@ namespace XCharts /// public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } } + public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } } + /// /// the color of text. /// 文本的颜色。 @@ -81,6 +83,15 @@ namespace XCharts this.rotate = rotate; } + public void Copy(TextStyle style) + { + this.fontSize = style.fontSize; + this.fontStyle = style.fontStyle; + this.color = style.color; + this.rotate = style.rotate; + this.offset = style.offset; + } + public TextStyle Clone() { var textStyle = new TextStyle(); diff --git a/Runtime/Internal/BaseChart.cs b/Runtime/Internal/BaseChart.cs index 4655345f..2e474ee1 100644 --- a/Runtime/Internal/BaseChart.cs +++ b/Runtime/Internal/BaseChart.cs @@ -160,7 +160,7 @@ namespace XCharts Vector2 anchorMax = m_Title.location.runtimeAnchorMax; Vector2 pivot = m_Title.location.runtimePivot; Vector3 titlePosition = m_Title.location.GetPosition(chartWidth, chartHeight); - Vector3 subTitlePosition = -new Vector3(0, m_Title.textFontSize + m_Title.itemGap, 0); + Vector3 subTitlePosition = -new Vector3(0, m_Title.textStyle.fontSize + m_Title.itemGap, 0); float titleWid = chartWidth; var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax, @@ -170,20 +170,22 @@ namespace XCharts Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot, - new Vector2(titleWid, m_Title.textFontSize), m_Title.textFontSize); + new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize, m_Title.textStyle.rotate, + m_Title.textStyle.fontStyle); titleText.alignment = anchor; titleText.gameObject.SetActive(m_Title.show); - titleText.transform.localPosition = Vector2.zero; + titleText.transform.localPosition = Vector3.zero + m_Title.textStyle.offsetv3; titleText.text = m_Title.text.Replace("\\n", "\n"); Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform, m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot, - new Vector2(titleWid, m_Title.subTextFontSize), m_Title.subTextFontSize); + new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize, + m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle); subText.alignment = anchor; subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText)); - subText.transform.localPosition = subTitlePosition; + subText.transform.localPosition = subTitlePosition + m_Title.subTextStyle.offsetv3; subText.text = m_Title.subText.Replace("\\n", "\n"); } diff --git a/Runtime/Utility/XChartsMgr.cs b/Runtime/Utility/XChartsMgr.cs index 03b74a25..d6ebd8dd 100644 --- a/Runtime/Utility/XChartsMgr.cs +++ b/Runtime/Utility/XChartsMgr.cs @@ -25,7 +25,7 @@ namespace XCharts public class XChartsMgr : MonoBehaviour { public const string version = "1.0.5"; - public const int date = 20191211; + public const int date = 20191215; [SerializeField] private string m_NowVersion; [SerializeField] private string m_NewVersion; diff --git a/version.json b/version.json index dfe958d3..896d94cd 100644 --- a/version.json +++ b/version.json @@ -1,7 +1,7 @@ { "version": "1.0.5", - "date": "20191211", - "checkdate": "20191211", + "date": "20191215", + "checkdate": "20191215", "desc": "欢迎 Github 上点 Star 支持,非常感谢!", "homepage": "https://github.com/monitor1394/unity-ugui-XCharts" } \ No newline at end of file