增加TooltipcolumnGapWidths参数设置列文本间隙距离

This commit is contained in:
monitor1394
2025-03-02 20:57:58 +08:00
parent ffed67d8ee
commit f9f2428142
4 changed files with 34 additions and 8 deletions

View File

@@ -79,6 +79,7 @@ slug: /changelog
## master
* (2025.03.02) 增加`Tooltip``columnGapWidths`参数设置列文本间隙距离
* (2025.03.01) 优化`Comment`的组件刷新
* (2025.02.23) 增加`Axis``Label``formatter`支持`{index}``{index-1}``{-index}``{-index-1}`通配符
* (2025.02.23) 增加`Bar``realtimeSort`支持实时排序

View File

@@ -41,6 +41,7 @@ namespace XCharts.Editor
});
PropertyField("m_LineStyle");
PropertyField("m_TitleLabelStyle");
PropertyListField("m_ColumnGapWidths");
PropertyListField("m_ContentLabelStyles");
--EditorGUI.indentLevel;
}

View File

@@ -145,6 +145,7 @@ namespace XCharts.Runtime
[SerializeField] private float m_TitleHeight = 25f;
[SerializeField] private float m_ItemHeight = 25f;
[SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255);
[SerializeField][Since("v3.14.0")] private List<float> m_ColumnGapWidths = new List<float>{15};
[SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
[SerializeField]
private LabelStyle m_TitleLabelStyle = new LabelStyle()
@@ -453,6 +454,15 @@ namespace XCharts.Runtime
set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
}
/// <summary>
/// the column gap width of content. When there is only one column, it only represents the gap width of the second column.
/// ||内容部分的列间距。当只有一列时,只表示第二列的间距。
/// </summary>
public List<float> columnGapWidths
{
get { return m_ColumnGapWidths; }
set { if (value != null) { m_ColumnGapWidths = value; SetComponentDirty(); } }
}
/// <summary>
/// the textstyle of title.
/// ||标题的文本样式。
/// </summary>
@@ -462,8 +472,8 @@ namespace XCharts.Runtime
set { if (value != null) { m_TitleLabelStyle = value; SetComponentDirty(); } }
}
/// <summary>
/// the textstyle list of content.
/// ||内容部分的文本样式列表。和列一一对应
/// the column text style list of content. The first represents the text style of the first column, and so on.
/// ||内容部分的文本样式列表。第一个表示第一列的文本样式,以此类推
/// </summary>
public List<LabelStyle> contentLabelStyles
{

View File

@@ -60,6 +60,7 @@ namespace XCharts.Runtime
ChartHelper.SetActive(gameObject, m_Active);
if (!flag)
{
m_ColumnMaxWidth.Clear();
foreach (var item in m_Items)
item.gameObject.SetActive(false);
}
@@ -75,8 +76,6 @@ namespace XCharts.Runtime
ChartHelper.SetActive(title, titleActive);
title.SetText(data.title);
m_ColumnMaxWidth.Clear();
var contentLabelStyle0 = tooltip.GetContentLabelStyle(0);
for (int i = 0; i < data.param.Count; i++)
{
var item = GetItem(i);
@@ -93,13 +92,17 @@ namespace XCharts.Runtime
column.SetActive(true);
column.SetText(param.columns[j]);
if (j == 0 && contentLabelStyle0 != null && ChartHelper.IsClearColor(contentLabelStyle0.textStyle.color))
column.text.SetColor(param.color);
if (j == 0)
{
var labelStyle = tooltip.GetContentLabelStyle(j);
if (labelStyle != null && ChartHelper.IsClearColor(labelStyle.textStyle.color))
column.text.SetColor(param.color);
}
if (j >= m_ColumnMaxWidth.Count)
m_ColumnMaxWidth.Add(0);
var columnWidth = column.GetWidth();
var columnWidth = column.text.GetPreferredWidth() + GetTooltipColumnGapWidth(tooltip, j);
if (m_ColumnMaxWidth[j] < columnWidth)
m_ColumnMaxWidth[j] = columnWidth;
}
@@ -117,6 +120,17 @@ namespace XCharts.Runtime
tooltip.gameObject.transform.SetAsLastSibling();
}
private static float GetTooltipColumnGapWidth(Tooltip tooltip, int index)
{
if (tooltip == null || tooltip.columnGapWidths.Count == 0) return 0;
if (tooltip.columnGapWidths.Count == 1) return index == 1 ? tooltip.columnGapWidths[0] : 0;
if (index < tooltip.columnGapWidths.Count)
{
return tooltip.columnGapWidths[index];
}
return 0;
}
private static bool IsSecondaryMark(SerieParams sp, string mark)
{
return sp.isSecondaryMark && mark == sp.marker;
@@ -163,7 +177,7 @@ namespace XCharts.Runtime
var xPos = 0f;
for (int j = 0; j < m_ColumnMaxWidth.Count; j++)
{
if(j >= item.columns.Count) break;
if (j >= item.columns.Count) break;
var deltaX = j == m_ColumnMaxWidth.Count - 1 ? maxWid - xPos : m_ColumnMaxWidth[j];
item.columns[j].text.SetSizeDelta(new Vector2(deltaX, tooltip.itemHeight));
item.columns[j].SetSize(deltaX, tooltip.itemHeight);