Files
XCharts/Runtime/Component/Title/Title.cs

105 lines
3.7 KiB
C#
Raw Normal View History

using System;
2022-05-22 22:17:38 +08:00
using UnityEngine;
2022-02-19 22:37:57 +08:00
namespace XCharts.Runtime
{
/// <summary>
/// Title component, including main title and subtitle.
2022-03-24 08:37:06 +08:00
/// |标题组件,包含主标题和副标题。
/// </summary>
[Serializable]
2021-11-23 13:20:07 +08:00
[ComponentHandler(typeof(TitleHander), true)]
public class Title : MainComponent, IPropertyChanged
{
[SerializeField] private bool m_Show = true;
2021-11-23 13:20:07 +08:00
[SerializeField] private string m_Text = "Chart Title";
[SerializeField] private string m_SubText = "";
2022-04-26 08:24:45 +08:00
[SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
[SerializeField] private LabelStyle m_SubLabelStyle = new LabelStyle();
2021-11-23 13:20:07 +08:00
[SerializeField] private float m_ItemGap = 0;
2019-12-15 21:36:59 +08:00
[SerializeField] private Location m_Location = Location.defaultTop;
/// <summary>
/// [default:true]
/// Set this to false to prevent the title from showing.
2022-03-24 08:37:06 +08:00
/// |是否显示标题组件。
/// </summary>
2021-01-11 08:54:28 +08:00
public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
/// <summary>
2020-07-10 09:13:26 +08:00
/// The main title text, supporting \n for newlines.
2022-03-24 08:37:06 +08:00
/// |主标题文本,支持使用 \n 换行。
/// </summary>
2021-01-11 08:54:28 +08:00
public string text { get { return m_Text; } set { if (PropertyUtil.SetClass(ref m_Text, value)) SetComponentDirty(); } }
2019-12-15 21:36:59 +08:00
/// <summary>
2020-07-10 09:13:26 +08:00
/// The text style of main title.
2022-03-24 08:37:06 +08:00
/// |主标题文本样式。
2019-12-15 21:36:59 +08:00
/// </summary>
2022-04-26 08:24:45 +08:00
public LabelStyle labelStyle
{
2022-04-26 08:24:45 +08:00
get { return m_LabelStyle; }
set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
/// Subtitle text, supporting for \n for newlines.
2022-03-24 08:37:06 +08:00
/// |副标题文本,支持使用 \n 换行。
/// </summary>
public string subText
{
get { return m_SubText; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetClass(ref m_SubText, value)) SetComponentDirty(); }
}
/// <summary>
2020-07-10 09:13:26 +08:00
/// The text style of sub title.
2022-03-24 08:37:06 +08:00
/// |副标题文本样式。
2019-12-15 21:36:59 +08:00
/// </summary>
2022-04-26 08:24:45 +08:00
public LabelStyle subLabelStyle
{
2022-04-26 08:24:45 +08:00
get { return m_SubLabelStyle; }
set { if (PropertyUtil.SetClass(ref m_SubLabelStyle, value)) SetComponentDirty(); }
}
/// <summary>
2019-12-15 21:36:59 +08:00
/// [default:8]
/// The gap between the main title and subtitle.
2022-03-24 08:37:06 +08:00
/// |主副标题之间的间距。
/// </summary>
public float itemGap
{
get { return m_ItemGap; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); }
}
/// <summary>
/// The location of title component.
2022-03-24 08:37:06 +08:00
/// |标题显示位置。
/// </summary>
public Location location
{
get { return m_Location; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); }
}
public override bool vertsDirty { get { return false; } }
public override bool componentDirty
{
2021-11-23 13:20:07 +08:00
get
{
2022-05-22 22:17:38 +08:00
return m_ComponentDirty ||
location.componentDirty ||
m_LabelStyle.componentDirty ||
m_SubLabelStyle.componentDirty;
2021-11-23 13:20:07 +08:00
}
}
2021-05-16 23:38:06 +08:00
public override void ClearComponentDirty()
{
base.ClearComponentDirty();
location.ClearComponentDirty();
2022-04-26 08:24:45 +08:00
m_LabelStyle.ClearComponentDirty();
m_SubLabelStyle.ClearComponentDirty();
}
public void OnChanged()
{
m_Location.OnChanged();
}
}
}