mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-20 15:30:09 +00:00
XCharts 2.0
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
/******************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/******************************************/
|
||||
/************************************************/
|
||||
/* */
|
||||
/* Copyright (c) 2018 - 2021 monitor1394 */
|
||||
/* https://github.com/monitor1394 */
|
||||
/* */
|
||||
/************************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
#if dUI_TextMeshPro
|
||||
using TMPro;
|
||||
#endif
|
||||
|
||||
namespace XCharts
|
||||
{
|
||||
@@ -18,18 +21,20 @@ namespace XCharts
|
||||
public class TextStyle : SubComponent
|
||||
{
|
||||
[SerializeField] private Font m_Font;
|
||||
|
||||
[SerializeField] private float m_Rotate = 0;
|
||||
[SerializeField] private Vector2 m_Offset = Vector2.zero;
|
||||
[SerializeField] private Color m_Color = Color.clear;
|
||||
[SerializeField] private Color m_BackgroundColor = Color.clear;
|
||||
[SerializeField] private int m_FontSize = 18;
|
||||
[SerializeField] private int m_FontSize = 0;
|
||||
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
|
||||
[SerializeField] private float m_LineSpacing = 1f;
|
||||
// [SerializeField] private float m_PaddingLeft = 0f;
|
||||
// [SerializeField] private float m_PaddingRight = 0f;
|
||||
// [SerializeField] private float m_PaddingTop = 0f;
|
||||
// [SerializeField] private float m_PaddingBottom = 0f;
|
||||
|
||||
[SerializeField] private TextAnchor m_Alignment = TextAnchor.MiddleCenter;
|
||||
#if dUI_TextMeshPro
|
||||
[SerializeField] private TMP_FontAsset m_TMPFont;
|
||||
[SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal;
|
||||
[SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Rotation of text.
|
||||
/// 文本的旋转。
|
||||
@@ -38,7 +43,7 @@ namespace XCharts
|
||||
public float rotate
|
||||
{
|
||||
get { return m_Rotate; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the offset of position.
|
||||
@@ -48,7 +53,7 @@ namespace XCharts
|
||||
public Vector2 offset
|
||||
{
|
||||
get { return m_Offset; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
|
||||
@@ -61,7 +66,7 @@ namespace XCharts
|
||||
public Color color
|
||||
{
|
||||
get { return m_Color; }
|
||||
set { if (PropertyUtility.SetColor(ref m_Color, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
@@ -71,7 +76,7 @@ namespace XCharts
|
||||
public Color backgroundColor
|
||||
{
|
||||
get { return m_BackgroundColor; }
|
||||
set { if (PropertyUtility.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the font of text. When `null`, the theme's font is used by default.
|
||||
@@ -81,7 +86,7 @@ namespace XCharts
|
||||
public Font font
|
||||
{
|
||||
get { return m_Font; }
|
||||
set { if (PropertyUtility.SetClass(ref m_Font, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// font size.
|
||||
@@ -91,7 +96,7 @@ namespace XCharts
|
||||
public int fontSize
|
||||
{
|
||||
get { return m_FontSize; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// font style.
|
||||
@@ -101,7 +106,7 @@ namespace XCharts
|
||||
public FontStyle fontStyle
|
||||
{
|
||||
get { return m_FontStyle; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// text line spacing.
|
||||
@@ -111,8 +116,34 @@ namespace XCharts
|
||||
public float lineSpacing
|
||||
{
|
||||
get { return m_LineSpacing; }
|
||||
set { if (PropertyUtility.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
|
||||
set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 对齐方式。
|
||||
/// </summary>
|
||||
public TextAnchor alignment
|
||||
{
|
||||
get { return m_Alignment; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Alignment, value)) SetComponentDirty(); }
|
||||
}
|
||||
#if dUI_TextMeshPro
|
||||
public TMP_FontAsset tmpFont
|
||||
{
|
||||
get { return m_TMPFont; }
|
||||
set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
|
||||
}
|
||||
|
||||
public FontStyles tmpFontStyle
|
||||
{
|
||||
get { return m_TMPFontStyle; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_TMPFontStyle, value)) SetComponentDirty(); }
|
||||
}
|
||||
public TextAlignmentOptions tmpAlignment
|
||||
{
|
||||
get { return m_TMPAlignment; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_TMPAlignment, value)) SetComponentDirty(); }
|
||||
}
|
||||
#endif
|
||||
|
||||
public TextStyle()
|
||||
{
|
||||
@@ -143,5 +174,44 @@ namespace XCharts
|
||||
this.color = color;
|
||||
this.rotate = rotate;
|
||||
}
|
||||
|
||||
public void Copy(TextStyle textStyle)
|
||||
{
|
||||
font = textStyle.font;
|
||||
rotate = textStyle.rotate;
|
||||
offset = textStyle.offset;
|
||||
color = textStyle.color;
|
||||
backgroundColor = textStyle.backgroundColor;
|
||||
fontSize = textStyle.fontSize;
|
||||
fontStyle = textStyle.fontStyle;
|
||||
lineSpacing = textStyle.lineSpacing;
|
||||
alignment = textStyle.alignment;
|
||||
#if dUI_TextMeshPro
|
||||
m_TMPFont = textStyle.tmpFont;
|
||||
m_TMPAlignment = textStyle.tmpAlignment;
|
||||
m_TMPFontStyle = textStyle.tmpFontStyle;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void UpdateAlignmentByLocation(Location location)
|
||||
{
|
||||
#if dUI_TextMeshPro
|
||||
m_TMPAlignment = location.runtimeTMPTextAlignment;
|
||||
#else
|
||||
m_Alignment = location.runtimeTextAlignment;
|
||||
#endif
|
||||
}
|
||||
|
||||
public Color GetColor(Color defaultColor)
|
||||
{
|
||||
if (ChartHelper.IsClearColor(color)) return defaultColor;
|
||||
else return color;
|
||||
}
|
||||
|
||||
public int GetFontSize(ComponentTheme defaultTheme)
|
||||
{
|
||||
if(fontSize == 0) return defaultTheme.fontSize;
|
||||
else return fontSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user