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

97 lines
2.7 KiB
C#
Raw Normal View History

2019-11-30 21:24:04 +08:00
/*
2021-01-11 08:54:28 +08:00
/************************************************/
/* */
/* Copyright (c) 2018 - 2021 monitor1394 */
/* https://github.com/monitor1394 */
/* */
/************************************************/
2019-11-30 21:24:04 +08:00
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")]
2021-01-11 08:54:28 +08:00
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
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; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
2020-03-08 10:47:48 +08:00
}
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; }
2021-01-11 08:54:28 +08:00
set { if (PropertyUtil.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
2021-05-16 23:38:06 +08:00
public 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
}
2021-01-11 08:54:28 +08:00
public ChartText runtimeText { get; set; }
2019-11-30 21:24:04 +08:00
public bool IsInited()
{
return runtimeText != null;
}
public void SetActive(bool active)
{
2021-01-11 08:54:28 +08:00
if (runtimeText != null)
2019-11-30 21:24:04 +08:00
{
2021-01-11 08:54:28 +08:00
runtimeText.SetActive(active);
2019-11-30 21:24:04 +08:00
}
}
public void UpdatePosition(Vector3 pos)
{
2021-01-11 08:54:28 +08:00
if (runtimeText != null)
2019-11-30 21:24:04 +08:00
{
2021-01-11 08:54:28 +08:00
runtimeText.SetLocalPosition(pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y));
2019-11-30 21:24:04 +08:00
}
}
public void SetText(string text)
{
2021-01-11 08:54:28 +08:00
if (runtimeText == null) return;
var oldText = runtimeText.GetText();
if (oldText != null && !oldText.Equals(text))
2019-11-30 21:24:04 +08:00
{
2021-01-11 08:54:28 +08:00
if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.SetColor(textStyle.color);
runtimeText.SetText(text);
2019-11-30 21:24:04 +08:00
}
}
2021-03-25 12:55:52 +08:00
public void SetColor(Color color)
{
if (runtimeText != null)
{
runtimeText.SetColor(color);
}
}
2019-11-30 21:24:04 +08:00
}
}