mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 15:30:09 +00:00
3.0 - unitypackage
This commit is contained in:
89
Runtime/Component/Title/TitleStyle.cs
Normal file
89
Runtime/Component/Title/TitleStyle.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
/// <summary>
|
||||
/// the title of serie.
|
||||
/// 标题相关设置。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TitleStyle : ChildComponent
|
||||
{
|
||||
[SerializeField] private bool m_Show;
|
||||
[FormerlySerializedAs("m_textStyle")]
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show title.
|
||||
/// 是否显示标题。
|
||||
/// </summary>
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
/// 文本的颜色。
|
||||
/// </summary>
|
||||
public TextStyle textStyle
|
||||
{
|
||||
get { return m_TextStyle; }
|
||||
set { if (PropertyUtil.SetClass(ref m_TextStyle, value, true)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
public override bool componentDirty { get { return m_ComponentDirty || textStyle.componentDirty; } }
|
||||
|
||||
public override void ClearComponentDirty()
|
||||
{
|
||||
base.ClearComponentDirty();
|
||||
textStyle.ClearComponentDirty();
|
||||
}
|
||||
|
||||
public ChartText runtimeText { get; set; }
|
||||
|
||||
public bool IsInited()
|
||||
{
|
||||
return runtimeText != null;
|
||||
}
|
||||
|
||||
public void SetActive(bool active)
|
||||
{
|
||||
if (runtimeText != null)
|
||||
{
|
||||
runtimeText.SetActive(active);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePosition(Vector3 pos)
|
||||
{
|
||||
if (runtimeText != null)
|
||||
{
|
||||
runtimeText.SetLocalPosition(pos + new Vector3(m_TextStyle.offset.x, m_TextStyle.offset.y));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetText(string text)
|
||||
{
|
||||
if (runtimeText == null) return;
|
||||
var oldText = runtimeText.GetText();
|
||||
if (oldText != null && !oldText.Equals(text))
|
||||
{
|
||||
if (!ChartHelper.IsClearColor(textStyle.color)) runtimeText.SetColor(textStyle.color);
|
||||
runtimeText.SetText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
if (runtimeText != null)
|
||||
{
|
||||
runtimeText.SetColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user