mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-21 16:00:24 +00:00
增加Title的TextStyle支持
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
# 更新日志
|
||||
|
||||
* (2019.12.15) 增加`Title`的`TextStyle`支持
|
||||
* (2019.12.11) 修复`Legend`都隐藏时`Value轴`还显示数值的问题
|
||||
* (2019.12.11) 修复`Series->Data->Size`重置为0后设置无效的问题
|
||||
* (2019.12.06) 修复数据过小时`AxisLabel`直接科学计数法显示的问题
|
||||
|
||||
@@ -84,9 +84,9 @@
|
||||
|
||||
* `show`:是否显示标题组件。
|
||||
* `text`:主标题文本,支持使用 `\n` 换行。
|
||||
* `textFontSize`:主标题文字的字体大小。
|
||||
* `textStyle`:主标题文本样式 [TextStyle](#TextStyle)。
|
||||
* `subText`:副标题文本,支持使用 `\n` 换行。
|
||||
* `subTextFontSize`:副标题文字的字体大小。
|
||||
* `subTextStyle`:副标题文本样式 [TextStyle](#TextStyle)。
|
||||
* `itemGap`:主副标题之间的间距。
|
||||
* `location`:标题显示位置 [Location](#Location)。
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ namespace XCharts
|
||||
drawRect.height = EditorGUIUtility.singleLineHeight;
|
||||
SerializedProperty show = prop.FindPropertyRelative("m_Show");
|
||||
SerializedProperty text = prop.FindPropertyRelative("m_Text");
|
||||
SerializedProperty m_TextFontSize = prop.FindPropertyRelative("m_TextFontSize");
|
||||
SerializedProperty m_TextStyle = prop.FindPropertyRelative("m_TextStyle");
|
||||
SerializedProperty subText = prop.FindPropertyRelative("m_SubText");
|
||||
SerializedProperty m_SubTextFontSize = prop.FindPropertyRelative("m_SubTextFontSize");
|
||||
SerializedProperty m_SubTextStyle = prop.FindPropertyRelative("m_SubTextStyle");
|
||||
SerializedProperty m_ItemGap = prop.FindPropertyRelative("m_ItemGap");
|
||||
SerializedProperty location = prop.FindPropertyRelative("m_Location");
|
||||
|
||||
@@ -35,17 +35,17 @@ namespace XCharts
|
||||
EditorGUI.PropertyField(drawRect, text);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_TextFontSize, new GUIContent("Font Size"));
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_TextStyle);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_TextStyle);
|
||||
--EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, subText);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
++EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_SubTextFontSize, new GUIContent("Font Size"));
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_SubTextStyle);
|
||||
drawRect.y += EditorGUI.GetPropertyHeight(m_SubTextStyle);
|
||||
--EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, m_ItemGap, new GUIContent("Item Gap"));
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
--EditorGUI.indentLevel;
|
||||
EditorGUI.PropertyField(drawRect, location);
|
||||
}
|
||||
--EditorGUI.indentLevel;
|
||||
@@ -56,9 +56,10 @@ namespace XCharts
|
||||
float height = 0;
|
||||
if (m_TitleModuleToggle)
|
||||
{
|
||||
height += 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
|
||||
SerializedProperty location = prop.FindPropertyRelative("m_Location");
|
||||
height += EditorGUI.GetPropertyHeight(location);
|
||||
height += 3 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_TextStyle"));
|
||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_SubTextStyle"));
|
||||
height += EditorGUI.GetPropertyHeight(prop.FindPropertyRelative("m_Location"));
|
||||
}
|
||||
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
return height;
|
||||
|
||||
@@ -19,11 +19,11 @@ namespace XCharts
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private string m_Text;
|
||||
[SerializeField] private int m_TextFontSize;
|
||||
[SerializeField] private TextStyle m_TextStyle = new TextStyle(16);
|
||||
[SerializeField] private string m_SubText;
|
||||
[SerializeField] private int m_SubTextFontSize;
|
||||
[SerializeField] private float m_ItemGap;
|
||||
[SerializeField] private Location m_Location;
|
||||
[SerializeField] private TextStyle m_SubTextStyle = new TextStyle(14);
|
||||
[SerializeField] private float m_ItemGap = 8;
|
||||
[SerializeField] private Location m_Location = Location.defaultTop;
|
||||
|
||||
/// <summary>
|
||||
/// [default:true]
|
||||
@@ -41,20 +41,30 @@ namespace XCharts
|
||||
/// main title font size.
|
||||
/// 主标题文字的字体大小。
|
||||
/// </summary>
|
||||
public int textFontSize { get { return m_TextFontSize; } set { m_TextFontSize = value; } }
|
||||
[Obsolete("use textStyle instead.", false)]
|
||||
public int textFontSize { get { return m_TextStyle.fontSize; } set { m_TextStyle.fontSize = value; } }
|
||||
/// <summary>
|
||||
/// 主标题文本样式。
|
||||
/// </summary>
|
||||
public TextStyle textStyle { get { return m_TextStyle; } set { m_TextStyle = value; } }
|
||||
/// <summary>
|
||||
/// Subtitle text, supporting for \n for newlines.
|
||||
/// 副标题文本,支持使用 \n 换行。
|
||||
/// </summary>
|
||||
public string subText { get { return m_SubText; } set { m_SubText = value; } }
|
||||
/// <summary>
|
||||
/// 副标题文本样式。
|
||||
/// </summary>
|
||||
public TextStyle subTextStyle { get { return m_SubTextStyle; } set { m_SubTextStyle = value; } }
|
||||
/// <summary>
|
||||
/// [default:14]
|
||||
/// subtitle font size.
|
||||
/// 副标题文字的字体大小。
|
||||
/// </summary>
|
||||
public int subTextFontSize { get { return m_SubTextFontSize; } set { m_SubTextFontSize = value; } }
|
||||
[Obsolete("use subTextStyle instead.", false)]
|
||||
public int subTextFontSize { get { return m_SubTextStyle.fontSize; } set { m_SubTextStyle.fontSize = value; } }
|
||||
/// <summary>
|
||||
/// [default:14]
|
||||
/// [default:8]
|
||||
/// The gap between the main title and subtitle.
|
||||
/// 主副标题之间的间距。
|
||||
/// </summary>
|
||||
@@ -73,9 +83,9 @@ namespace XCharts
|
||||
{
|
||||
m_Show = true,
|
||||
m_Text = "Chart Title",
|
||||
m_TextFontSize = 16,
|
||||
m_TextStyle = new TextStyle(16),
|
||||
m_SubText = "",
|
||||
m_SubTextFontSize = 14,
|
||||
m_SubTextStyle = new TextStyle(14),
|
||||
m_ItemGap = 8,
|
||||
m_Location = Location.defaultTop
|
||||
};
|
||||
@@ -86,9 +96,9 @@ namespace XCharts
|
||||
{
|
||||
m_Show = title.show;
|
||||
m_Text = title.text;
|
||||
m_TextFontSize = title.textFontSize;
|
||||
m_TextStyle.Copy(title.textStyle);
|
||||
m_SubTextStyle.Copy(title.subTextStyle);
|
||||
m_SubText = title.subText;
|
||||
m_SubTextFontSize = title.subTextFontSize;
|
||||
m_ItemGap = title.itemGap;
|
||||
m_Location.Copy(title.location);
|
||||
}
|
||||
@@ -117,9 +127,9 @@ namespace XCharts
|
||||
}
|
||||
return m_Show == other.show &&
|
||||
m_Text.Equals(other.text) &&
|
||||
m_TextFontSize == other.textFontSize &&
|
||||
m_TextStyle.Equals(other.textStyle) &&
|
||||
m_SubText.Equals(other.subText) &&
|
||||
m_SubTextFontSize == other.subTextFontSize &&
|
||||
m_SubTextStyle.Equals(other.subTextStyle) &&
|
||||
m_ItemGap == other.itemGap &&
|
||||
m_Location.Equals(other.location);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ namespace XCharts
|
||||
/// </summary>
|
||||
public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||
|
||||
public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
|
||||
|
||||
/// <summary>
|
||||
/// the color of text.
|
||||
/// 文本的颜色。
|
||||
@@ -81,6 +83,15 @@ namespace XCharts
|
||||
this.rotate = rotate;
|
||||
}
|
||||
|
||||
public void Copy(TextStyle style)
|
||||
{
|
||||
this.fontSize = style.fontSize;
|
||||
this.fontStyle = style.fontStyle;
|
||||
this.color = style.color;
|
||||
this.rotate = style.rotate;
|
||||
this.offset = style.offset;
|
||||
}
|
||||
|
||||
public TextStyle Clone()
|
||||
{
|
||||
var textStyle = new TextStyle();
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace XCharts
|
||||
Vector2 anchorMax = m_Title.location.runtimeAnchorMax;
|
||||
Vector2 pivot = m_Title.location.runtimePivot;
|
||||
Vector3 titlePosition = m_Title.location.GetPosition(chartWidth, chartHeight);
|
||||
Vector3 subTitlePosition = -new Vector3(0, m_Title.textFontSize + m_Title.itemGap, 0);
|
||||
Vector3 subTitlePosition = -new Vector3(0, m_Title.textStyle.fontSize + m_Title.itemGap, 0);
|
||||
float titleWid = chartWidth;
|
||||
|
||||
var titleObject = ChartHelper.AddObject(s_TitleObjectName, transform, anchorMin, anchorMax,
|
||||
@@ -170,20 +170,22 @@ namespace XCharts
|
||||
|
||||
Text titleText = ChartHelper.AddTextObject(s_TitleObjectName, titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.textFontSize), m_Title.textFontSize);
|
||||
new Vector2(titleWid, m_Title.textStyle.fontSize), m_Title.textStyle.fontSize, m_Title.textStyle.rotate,
|
||||
m_Title.textStyle.fontStyle);
|
||||
|
||||
titleText.alignment = anchor;
|
||||
titleText.gameObject.SetActive(m_Title.show);
|
||||
titleText.transform.localPosition = Vector2.zero;
|
||||
titleText.transform.localPosition = Vector3.zero + m_Title.textStyle.offsetv3;
|
||||
titleText.text = m_Title.text.Replace("\\n", "\n");
|
||||
|
||||
Text subText = ChartHelper.AddTextObject(s_TitleObjectName + "_sub", titleObject.transform,
|
||||
m_ThemeInfo.font, m_ThemeInfo.titleTextColor, anchor, anchorMin, anchorMax, pivot,
|
||||
new Vector2(titleWid, m_Title.subTextFontSize), m_Title.subTextFontSize);
|
||||
new Vector2(titleWid, m_Title.subTextStyle.fontSize), m_Title.subTextStyle.fontSize,
|
||||
m_Title.subTextStyle.rotate, m_Title.subTextStyle.fontStyle);
|
||||
|
||||
subText.alignment = anchor;
|
||||
subText.gameObject.SetActive(m_Title.show && !string.IsNullOrEmpty(m_Title.subText));
|
||||
subText.transform.localPosition = subTitlePosition;
|
||||
subText.transform.localPosition = subTitlePosition + m_Title.subTextStyle.offsetv3;
|
||||
subText.text = m_Title.subText.Replace("\\n", "\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace XCharts
|
||||
public class XChartsMgr : MonoBehaviour
|
||||
{
|
||||
public const string version = "1.0.5";
|
||||
public const int date = 20191211;
|
||||
public const int date = 20191215;
|
||||
|
||||
[SerializeField] private string m_NowVersion;
|
||||
[SerializeField] private string m_NewVersion;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": "1.0.5",
|
||||
"date": "20191211",
|
||||
"checkdate": "20191211",
|
||||
"date": "20191215",
|
||||
"checkdate": "20191215",
|
||||
"desc": "欢迎 Github 上点 Star 支持,非常感谢!",
|
||||
"homepage": "https://github.com/monitor1394/unity-ugui-XCharts"
|
||||
}
|
||||
Reference in New Issue
Block a user