No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Title.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// Title component, including main title and subtitle.
  7. /// |标题组件,包含主标题和副标题。
  8. /// </summary>
  9. [Serializable]
  10. [ComponentHandler(typeof(TitleHander), true)]
  11. public class Title : MainComponent, IPropertyChanged
  12. {
  13. [SerializeField] private bool m_Show = true;
  14. [SerializeField] private string m_Text = "Chart Title";
  15. [SerializeField] private string m_SubText = "";
  16. [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
  17. [SerializeField] private LabelStyle m_SubLabelStyle = new LabelStyle();
  18. [SerializeField] private float m_ItemGap = 0;
  19. [SerializeField] private Location m_Location = Location.defaultTop;
  20. /// <summary>
  21. /// [default:true]
  22. /// Set this to false to prevent the title from showing.
  23. /// |是否显示标题组件。
  24. /// </summary>
  25. public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } }
  26. /// <summary>
  27. /// The main title text, supporting \n for newlines.
  28. /// |主标题文本,支持使用 \n 换行。
  29. /// </summary>
  30. public string text { get { return m_Text; } set { if (PropertyUtil.SetClass(ref m_Text, value)) SetComponentDirty(); } }
  31. /// <summary>
  32. /// The text style of main title.
  33. /// |主标题文本样式。
  34. /// </summary>
  35. public LabelStyle labelStyle
  36. {
  37. get { return m_LabelStyle; }
  38. set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
  39. }
  40. /// <summary>
  41. /// Subtitle text, supporting for \n for newlines.
  42. /// |副标题文本,支持使用 \n 换行。
  43. /// </summary>
  44. public string subText
  45. {
  46. get { return m_SubText; }
  47. set { if (PropertyUtil.SetClass(ref m_SubText, value)) SetComponentDirty(); }
  48. }
  49. /// <summary>
  50. /// The text style of sub title.
  51. /// |副标题文本样式。
  52. /// </summary>
  53. public LabelStyle subLabelStyle
  54. {
  55. get { return m_SubLabelStyle; }
  56. set { if (PropertyUtil.SetClass(ref m_SubLabelStyle, value)) SetComponentDirty(); }
  57. }
  58. /// <summary>
  59. /// [default:8]
  60. /// The gap between the main title and subtitle.
  61. /// |主副标题之间的间距。
  62. /// </summary>
  63. public float itemGap
  64. {
  65. get { return m_ItemGap; }
  66. set { if (PropertyUtil.SetStruct(ref m_ItemGap, value)) SetComponentDirty(); }
  67. }
  68. /// <summary>
  69. /// The location of title component.
  70. /// |标题显示位置。
  71. /// </summary>
  72. public Location location
  73. {
  74. get { return m_Location; }
  75. set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); }
  76. }
  77. public override bool vertsDirty { get { return false; } }
  78. public override bool componentDirty
  79. {
  80. get
  81. {
  82. return m_ComponentDirty ||
  83. location.componentDirty ||
  84. m_LabelStyle.componentDirty ||
  85. m_SubLabelStyle.componentDirty;
  86. }
  87. }
  88. public override void ClearComponentDirty()
  89. {
  90. base.ClearComponentDirty();
  91. location.ClearComponentDirty();
  92. m_LabelStyle.ClearComponentDirty();
  93. m_SubLabelStyle.ClearComponentDirty();
  94. }
  95. public void OnChanged()
  96. {
  97. m_Location.OnChanged();
  98. }
  99. }
  100. }