增加Title的TextStyle支持

This commit is contained in:
monitor1394
2019-12-15 21:36:59 +08:00
parent 335837f99d
commit beee233570
8 changed files with 58 additions and 33 deletions

View File

@@ -1,6 +1,7 @@
# 更新日志 # 更新日志
* (2019.12.15) 增加`Title``TextStyle`支持
* (2019.12.11) 修复`Legend`都隐藏时`Value轴`还显示数值的问题 * (2019.12.11) 修复`Legend`都隐藏时`Value轴`还显示数值的问题
* (2019.12.11) 修复`Series->Data->Size`重置为0后设置无效的问题 * (2019.12.11) 修复`Series->Data->Size`重置为0后设置无效的问题
* (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题 * (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题

View File

@@ -84,9 +84,9 @@
* `show`:是否显示标题组件。 * `show`:是否显示标题组件。
* `text`:主标题文本,支持使用 `\n` 换行。 * `text`:主标题文本,支持使用 `\n` 换行。
* `textFontSize`:主标题文字的字体大小 * `textStyle`:主标题文本样式 [TextStyle](#TextStyle)
* `subText`:副标题文本,支持使用 `\n` 换行。 * `subText`:副标题文本,支持使用 `\n` 换行。
* `subTextFontSize`:副标题文字的字体大小 * `subTextStyle`:副标题文本样式 [TextStyle](#TextStyle)
* `itemGap`:主副标题之间的间距。 * `itemGap`:主副标题之间的间距。
* `location`:标题显示位置 [Location](#Location)。 * `location`:标题显示位置 [Location](#Location)。

View File

@@ -21,9 +21,9 @@ namespace XCharts
drawRect.height = EditorGUIUtility.singleLineHeight; drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty show = prop.FindPropertyRelative("m_Show"); SerializedProperty show = prop.FindPropertyRelative("m_Show");
SerializedProperty text = prop.FindPropertyRelative("m_Text"); 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 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 m_ItemGap = prop.FindPropertyRelative("m_ItemGap");
SerializedProperty location = prop.FindPropertyRelative("m_Location"); SerializedProperty location = prop.FindPropertyRelative("m_Location");
@@ -35,17 +35,17 @@ namespace XCharts
EditorGUI.PropertyField(drawRect, text); EditorGUI.PropertyField(drawRect, text);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel; ++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_TextFontSize, new GUIContent("Font Size")); EditorGUI.PropertyField(drawRect, m_TextStyle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, subText); EditorGUI.PropertyField(drawRect, subText);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel; ++EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_SubTextFontSize, new GUIContent("Font Size")); EditorGUI.PropertyField(drawRect, m_SubTextStyle);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUI.GetPropertyHeight(m_SubTextStyle);
--EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap")); EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap"));
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
--EditorGUI.indentLevel;
EditorGUI.PropertyField(drawRect, location); EditorGUI.PropertyField(drawRect, location);
} }
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
@@ -56,9 +56,10 @@ namespace XCharts
float height = 0; float height = 0;
if (m_TitleModuleToggle) if (m_TitleModuleToggle)
{ {
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing; height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
SerializedProperty location = prop.FindPropertyRelative("m_Location"); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
height += EditorGUI.GetPropertyHeight(location); height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SubTextStyle"));
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Location"));
} }
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
return height; return height;

View File

@@ -19,11 +19,11 @@ namespace XCharts
{ {
[SerializeField] private bool m_Show = true; [SerializeField] private bool m_Show = true;
[SerializeField] private string m_Text; [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 string m_SubText;
[SerializeField] private int m_SubTextFontSize; [SerializeField] private TextStyle m_SubTextStyle = new TextStyle(14);
[SerializeField] private float m_ItemGap; [SerializeField] private float m_ItemGap = 8;
[SerializeField] private Location m_Location; [SerializeField] private Location m_Location = Location.defaultTop;
/// <summary> /// <summary>
/// [default:true] /// [default:true]
@@ -41,20 +41,30 @@ namespace XCharts
/// main title font size. /// main title font size.
/// 主标题文字的字体大小。 /// 主标题文字的字体大小。
/// </summary> /// </summary>
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; } }
/// <summary>
/// 主标题文本样式。
/// </summary>
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
/// <summary> /// <summary>
/// Subtitle text, supporting for \n for newlines. /// Subtitle text, supporting for \n for newlines.
/// 副标题文本,支持使用 \n 换行。 /// 副标题文本,支持使用 \n 换行。
/// </summary> /// </summary>
public string subText { get { return m_SubText; } set { m_SubText = value; } } public string subText { get { return m_SubText; } set { m_SubText = value; } }
/// <summary> /// <summary>
/// 副标题文本样式。
/// </summary>
public TextStyle subTextStyle { get { return m_SubTextStyle; } set { m_SubTextStyle = value; } }
/// <summary>
/// [default:14] /// [default:14]
/// subtitle font size. /// subtitle font size.
/// 副标题文字的字体大小。 /// 副标题文字的字体大小。
/// </summary> /// </summary>
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; } }
/// <summary> /// <summary>
/// [default:14] /// [default:8]
/// The gap between the main title and subtitle. /// The gap between the main title and subtitle.
/// 主副标题之间的间距。 /// 主副标题之间的间距。
/// </summary> /// </summary>
@@ -73,9 +83,9 @@ namespace XCharts
{ {
m_Show = true, m_Show = true,
m_Text = "Chart Title", m_Text = "Chart Title",
m_TextFontSize = 16, m_TextStyle = new TextStyle(16),
m_SubText = "", m_SubText = "",
m_SubTextFontSize = 14, m_SubTextStyle = new TextStyle(14),
m_ItemGap = 8, m_ItemGap = 8,
m_Location = Location.defaultTop m_Location = Location.defaultTop
}; };
@@ -86,9 +96,9 @@ namespace XCharts
{ {
m_Show = title.show; m_Show = title.show;
m_Text = title.text; m_Text = title.text;
m_TextFontSize = title.textFontSize; m_TextStyle.Copy(title.textStyle);
m_SubTextStyle.Copy(title.subTextStyle);
m_SubText = title.subText; m_SubText = title.subText;
m_SubTextFontSize = title.subTextFontSize;
m_ItemGap = title.itemGap; m_ItemGap = title.itemGap;
m_Location.Copy(title.location); m_Location.Copy(title.location);
} }
@@ -117,9 +127,9 @@ namespace XCharts
} }
return m_Show == other.show && return m_Show == other.show &&
m_Text.Equals(other.text) && m_Text.Equals(other.text) &&
m_TextFontSize == other.textFontSize && m_TextStyle.Equals(other.textStyle) &&
m_SubText.Equals(other.subText) && m_SubText.Equals(other.subText) &&
m_SubTextFontSize == other.subTextFontSize && m_SubTextStyle.Equals(other.subTextStyle) &&
m_ItemGap == other.itemGap && m_ItemGap == other.itemGap &&
m_Location.Equals(other.location); m_Location.Equals(other.location);
} }

View File

@@ -35,6 +35,8 @@ namespace XCharts
/// </summary> /// </summary>
public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } } 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); } }
/// <summary> /// <summary>
/// the color of text. /// the color of text.
/// 文本的颜色。 /// 文本的颜色。
@@ -81,6 +83,15 @@ namespace XCharts
this.rotate = rotate; 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() public TextStyle Clone()
{ {
var textStyle = new TextStyle(); var textStyle = new TextStyle();

View File

@@ -160,7 +160,7 @@ namespace XCharts
Vector2 anchorMax = m_Title.location.runtimeAnchorMax; Vector2 anchorMax = m_Title.location.runtimeAnchorMax;
Vector2 pivot = m_Title.location.runtimePivot; Vector2 pivot = m_Title.location.runtimePivot;
Vector3 titlePosition = m_Title.location.GetPosition(chartWidth, chartHeight); 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; float titleWid = chartWidth;
var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax, var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax,
@@ -170,20 +170,22 @@ namespace XCharts
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform, Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot, 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.alignment = anchor;
titleText.gameObject.SetActive(m_Title.show); 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"); titleText.text = m_Title.text.Replace("\\n", "\n");
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform, Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot, 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.alignment = anchor;
subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText)); 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"); subText.text = m_Title.subText.Replace("\\n", "\n");
} }

View File

@@ -25,7 +25,7 @@ namespace XCharts
public class XChartsMgr : MonoBehaviour public class XChartsMgr : MonoBehaviour
{ {
public const string version = "1.0.5"; 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_NowVersion;
[SerializeField] private string m_NewVersion; [SerializeField] private string m_NewVersion;

View File

@@ -1,7 +1,7 @@
{ {
"version": "1.0.5", "version": "1.0.5",
"date": "20191211", "date": "20191215",
"checkdate": "20191211", "checkdate": "20191215",
"desc": "欢迎 Github 上点 Star 支持,非常感谢!", "desc": "欢迎 Github 上点 Star 支持,非常感谢!",
"homepage": "https://github.com/monitor1394/unity-ugui-XCharts" "homepage": "https://github.com/monitor1394/unity-ugui-XCharts"
} }