修复TitletextStylesubTextStyle无效的问题

This commit is contained in:
monitor1394
2020-03-23 07:58:09 +08:00
parent 0d361555f3
commit 25941d2050
5 changed files with 86 additions and 9 deletions

View File

@@ -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`显示

View File

@@ -46,37 +46,64 @@ namespace XCharts
/// <summary>
/// 主标题文本样式。
/// </summary>
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(); }
}
/// <summary>
/// Subtitle text, supporting for \n for newlines.
/// 副标题文本,支持使用 \n 换行。
/// </summary>
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(); }
}
/// <summary>
/// 副标题文本样式。
/// </summary>
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(); }
}
/// <summary>
/// [default:14]
/// subtitle font size.
/// 副标题文字的字体大小。
/// </summary>
[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; }
}
/// <summary>
/// [default:8]
/// The gap between the main title and subtitle.
/// 主副标题之间的间距。
/// </summary>
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(); }
}
/// <summary>
/// The location of title component.
/// 标题显示位置。
/// </summary>
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()
{

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c96205317b864d6c8c08ec45c27933c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);