mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-16 13:30:10 +00:00
增加Tooltip的FontSize、FontStyle配置字体大小和样式
This commit is contained in:
@@ -19,6 +19,8 @@ namespace XCharts
|
||||
SerializedProperty m_FixedHeight = prop.FindPropertyRelative("m_FixedHeight");
|
||||
SerializedProperty m_MinWidth = prop.FindPropertyRelative("m_MinWidth");
|
||||
SerializedProperty m_MinHeight = prop.FindPropertyRelative("m_MinHeight");
|
||||
SerializedProperty m_FontSize = prop.FindPropertyRelative("m_FontSize");
|
||||
SerializedProperty m_FontStyle = prop.FindPropertyRelative("m_FontStyle");
|
||||
|
||||
ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
@@ -36,13 +38,17 @@ namespace XCharts
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_MinHeight);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_FontSize);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
EditorGUI.PropertyField(drawRect, m_FontStyle);
|
||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
if (m_TooltipModuleToggle)
|
||||
return 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
|
||||
return 9 * EditorGUIUtility.singleLineHeight + 8 * EditorGUIUtility.standardVerticalSpacing;
|
||||
else
|
||||
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace XCharts
|
||||
[SerializeField] private float m_FixedHeight = 0;
|
||||
[SerializeField] private float m_MinWidth = 0;
|
||||
[SerializeField] private float m_MinHeight = 0;
|
||||
[SerializeField] private int m_FontSize = 18;
|
||||
[SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
|
||||
|
||||
private GameObject m_GameObject;
|
||||
private GameObject m_Content;
|
||||
@@ -96,6 +98,16 @@ namespace XCharts
|
||||
/// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。
|
||||
/// </summary>
|
||||
public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } }
|
||||
/// <summary>
|
||||
/// font size.
|
||||
/// 文字的字体大小。
|
||||
/// </summary>
|
||||
public int fontSize { get { return m_FontSize; } set { m_FontSize = value; } }
|
||||
/// <summary>
|
||||
/// font style.
|
||||
/// 文字的字体风格。
|
||||
/// </summary>
|
||||
public FontStyle fontStyle { get { return m_FontStyle; } set { m_FontStyle = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// The data index currently indicated by Tooltip.
|
||||
|
||||
@@ -308,7 +308,8 @@ namespace XCharts
|
||||
DestroyImmediate(tooltipObject.GetComponent<Image>());
|
||||
var parent = tooltipObject.transform;
|
||||
ChartHelper.HideAllObject(tooltipObject.transform);
|
||||
GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font);
|
||||
GameObject content = ChartHelper.AddTooltipContent("content", parent, m_ThemeInfo.font,
|
||||
m_Tooltip.fontSize, m_Tooltip.fontStyle);
|
||||
m_Tooltip.SetObj(tooltipObject);
|
||||
m_Tooltip.SetContentObj(content);
|
||||
m_Tooltip.SetContentBackgroundColor(m_ThemeInfo.tooltipBackgroundColor);
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace XCharts
|
||||
return btnObj.GetComponent<Button>();
|
||||
}
|
||||
|
||||
public static GameObject AddTooltipContent(string name, Transform parent, Font font)
|
||||
public static GameObject AddTooltipContent(string name, Transform parent, Font font, int fontSize, FontStyle fontStyle)
|
||||
{
|
||||
var anchorMax = new Vector2(0, 1);
|
||||
var anchorMin = new Vector2(0, 1);
|
||||
@@ -184,7 +184,7 @@ namespace XCharts
|
||||
var img = GetOrAddComponent<Image>(tooltipObj);
|
||||
img.color = Color.black;
|
||||
Text txt = AddTextObject("Text", tooltipObj.transform, font, Color.white, TextAnchor.UpperLeft,
|
||||
anchorMin, anchorMax, pivot, sizeDelta);
|
||||
anchorMin, anchorMax, pivot, sizeDelta, fontSize, 0, fontStyle);
|
||||
txt.text = "Text";
|
||||
txt.transform.localPosition = new Vector2(3, -3);
|
||||
tooltipObj.transform.localPosition = Vector3.zero;
|
||||
|
||||
Reference in New Issue
Block a user