Files
XCharts/Runtime/Component/Sub/TitleStyle.cs

87 lines
2.4 KiB
C#
Raw Normal View History

2019-11-30 21:24:04 +08:00
/*
/******************************************/
/* */
/* Copyright (c) 2018 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/******************************************/
using System;
using UnityEngine;
using UnityEngine.UI;
2020-03-08 10:47:48 +08:00
using UnityEngine.Serialization;
2019-11-30 21:24:04 +08:00
namespace XCharts
{
/// <summary>
/// the title of serie.
/// 标题相关设置。
/// </summary>
[Serializable]
2020-03-08 10:47:48 +08:00
public class TitleStyle : SubComponent
2019-11-30 21:24:04 +08:00
{
[SerializeField] private bool m_Show;
2020-03-08 10:47:48 +08:00
[FormerlySerializedAs("m_textStyle")]
[SerializeField] private TextStyle m_TextStyle = new TextStyle(18);
2019-11-30 21:24:04 +08:00
/// <summary>
/// Whether to show title.
/// 是否显示标题。
/// </summary>
2020-03-08 10:47:48 +08:00
public bool show
{
get { return m_Show; }
set { if (PropertyUtility.SetStruct(ref m_Show, value)) SetComponentDirty(); }
}
2019-11-30 21:24:04 +08:00
/// <summary>
/// the color of text.
/// 文本的颜色。
/// </summary>
2020-03-08 10:47:48 +08:00
public TextStyle textStyle
2019-11-30 21:24:04 +08:00
{
2020-03-08 10:47:48 +08:00
get { return m_TextStyle; }
set { if (PropertyUtility.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); }
2019-11-30 21:24:04 +08:00
}
2020-03-08 10:47:48 +08:00
public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } }
2019-11-30 21:24:04 +08:00
2020-03-08 10:47:48 +08:00
internal override void ClearComponentDirty()
2019-11-30 21:24:04 +08:00
{
2020-03-08 10:47:48 +08:00
base.ClearComponentDirty();
textStyle.ClearComponentDirty();
2019-11-30 21:24:04 +08:00
}
2020-03-08 10:47:48 +08:00
public Text runtimeText { get; set; }
2019-11-30 21:24:04 +08:00
public bool IsInited()
{
return runtimeText != null;
}
public void SetActive(bool active)
{
if (runtimeText)
{
ChartHelper.SetActive(runtimeText, active);
}
}
public void UpdatePosition(Vector3 pos)
{
if (runtimeText)
{
2020-03-08 10:47:48 +08:00
runtimeText.transform.localPosition = pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y);
2019-11-30 21:24:04 +08:00
}
}
public void SetText(string text)
{
2020-03-08 10:47:48 +08:00
if (runtimeText && !runtimeText.text.Equals(text))
2019-11-30 21:24:04 +08:00
{
if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.color = textStyle.color;
2019-11-30 21:24:04 +08:00
runtimeText.text = text;
}
}
}
}