2019-05-11 04:33:54 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace XCharts
|
|
|
|
|
|
{
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Title component, including main title and subtitle.
|
|
|
|
|
|
/// 标题组件,包含主标题和副标题。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
[Serializable]
|
2019-10-14 18:13:08 +08:00
|
|
|
|
public class Title : MainComponent, IPropertyChanged, IEquatable<Title>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-08-01 23:49:30 +08:00
|
|
|
|
[SerializeField] private bool m_Show = true;
|
2019-05-11 04:33:54 +08:00
|
|
|
|
[SerializeField] private string m_Text;
|
|
|
|
|
|
[SerializeField] private int m_TextFontSize;
|
|
|
|
|
|
[SerializeField] private string m_SubText;
|
|
|
|
|
|
[SerializeField] private int m_SubTextFontSize;
|
|
|
|
|
|
[SerializeField] private float m_ItemGap;
|
|
|
|
|
|
[SerializeField] private Location m_Location;
|
|
|
|
|
|
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// [default:true]
|
|
|
|
|
|
/// Set this to false to prevent the title from showing.
|
|
|
|
|
|
/// 是否显示标题组件。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public bool show { get { return m_Show; } set { m_Show = value; } }
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The main title text, supporting for \n for newlines.
|
|
|
|
|
|
/// 主标题文本,支持使用 \n 换行。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public string text { get { return m_Text; } set { m_Text = value; } }
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// [default:16]
|
|
|
|
|
|
/// main title font size.
|
|
|
|
|
|
/// 主标题文字的字体大小。
|
|
|
|
|
|
/// </summary>
|
2019-06-21 09:34:33 +08:00
|
|
|
|
public int textFontSize { get { return m_TextFontSize; } set { m_TextFontSize = value; } }
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Subtitle text, supporting for \n for newlines.
|
|
|
|
|
|
/// 副标题文本,支持使用 \n 换行。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public string subText { get { return m_SubText; } set { m_Text = value; } }
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// [default:14]
|
|
|
|
|
|
/// subtitle font size.
|
|
|
|
|
|
/// 副标题文字的字体大小。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public int subTextFontSize { get { return m_SubTextFontSize; } set { m_SubTextFontSize = value; } }
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// [default:14]
|
|
|
|
|
|
/// The gap between the main title and subtitle.
|
|
|
|
|
|
/// 主副标题之间的间距。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public float itemGap { get { return m_ItemGap; } set { m_ItemGap = value; } }
|
2019-08-01 23:49:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The location of title component.
|
|
|
|
|
|
/// 标题显示位置。
|
|
|
|
|
|
/// </summary>
|
2019-05-11 04:33:54 +08:00
|
|
|
|
public Location location { get { return m_Location; } set { m_Location = value; } }
|
|
|
|
|
|
|
|
|
|
|
|
public static Title defaultTitle
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var title = new Title
|
|
|
|
|
|
{
|
|
|
|
|
|
m_Show = true,
|
|
|
|
|
|
m_Text = "Chart Title",
|
|
|
|
|
|
m_TextFontSize = 16,
|
|
|
|
|
|
m_SubText = "",
|
|
|
|
|
|
m_SubTextFontSize = 14,
|
|
|
|
|
|
m_ItemGap = 14,
|
|
|
|
|
|
m_Location = Location.defaultTop
|
|
|
|
|
|
};
|
|
|
|
|
|
return title;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Copy(Title title)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_Show = title.show;
|
|
|
|
|
|
m_Text = title.text;
|
|
|
|
|
|
m_TextFontSize = title.textFontSize;
|
|
|
|
|
|
m_SubText = title.subText;
|
|
|
|
|
|
m_SubTextFontSize = title.subTextFontSize;
|
|
|
|
|
|
m_ItemGap = title.itemGap;
|
|
|
|
|
|
m_Location.Copy(title.location);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
|
{
|
2019-06-17 04:29:19 +08:00
|
|
|
|
if (ReferenceEquals(null, obj))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (obj is Title)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Equals((Title)obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Equals(Title other)
|
|
|
|
|
|
{
|
2019-06-17 04:29:19 +08:00
|
|
|
|
if (ReferenceEquals(null, other))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-05-11 04:33:54 +08:00
|
|
|
|
return m_Show == other.show &&
|
|
|
|
|
|
m_Text.Equals(other.text) &&
|
|
|
|
|
|
m_TextFontSize == other.textFontSize &&
|
|
|
|
|
|
m_SubText.Equals(other.subText) &&
|
|
|
|
|
|
m_SubTextFontSize == other.subTextFontSize &&
|
|
|
|
|
|
m_ItemGap == other.itemGap &&
|
|
|
|
|
|
m_Location.Equals(other.location);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-17 04:29:19 +08:00
|
|
|
|
public static bool operator ==(Title left, Title right)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-06-17 04:29:19 +08:00
|
|
|
|
if (ReferenceEquals(left, null) && ReferenceEquals(right, null))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return Equals(left, right);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-06-17 04:29:19 +08:00
|
|
|
|
public static bool operator !=(Title left, Title right)
|
2019-05-11 04:33:54 +08:00
|
|
|
|
{
|
2019-06-17 04:29:19 +08:00
|
|
|
|
return !(left == right);
|
2019-05-11 04:33:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
|
{
|
|
|
|
|
|
return base.GetHashCode();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_Location.OnChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|