修复Label在初始化时会堆积的问题

This commit is contained in:
monitor1394
2024-07-09 23:16:08 +08:00
parent 94d1398bd3
commit cdac6acd8c
4 changed files with 25 additions and 24 deletions

View File

@@ -50,7 +50,7 @@ namespace XCharts.Runtime
var borderColor = component.borderStyle.GetRuntimeBorderColor(); var borderColor = component.borderStyle.GetRuntimeBorderColor();
var cornerRadius = component.borderStyle.GetRuntimeCornerRadius(); var cornerRadius = component.borderStyle.GetRuntimeCornerRadius();
UGL.DrawRoundRectangleWithBorder(vh, chart.chartRect, backgroundColor, backgroundColor, cornerRadius, UGL.DrawRoundRectangleWithBorder(vh, chart.chartRect, backgroundColor, backgroundColor, cornerRadius,
borderWidth, borderColor); borderWidth, borderColor, 0, 1f);
} }
} }
} }

View File

@@ -56,7 +56,7 @@ namespace XCharts.Runtime
protected override void Awake() protected override void Awake()
{ {
raycastTarget = false; raycastTarget = false;
SetActive(true); SetActive(false, true);
} }
public void SetTextPadding(TextPadding padding) public void SetTextPadding(TextPadding padding)
@@ -200,10 +200,13 @@ namespace XCharts.Runtime
return m_Active; return m_Active;
} }
public void SetActive(bool flag) public void SetActive(bool flag, bool force = false)
{ {
m_Active = flag; if (m_Active == flag && !force) return;
ChartHelper.SetActive(gameObject, flag); if (ChartHelper.SetActive(gameObject, flag))
{
m_Active = flag;
}
} }
public void SetTextActive(bool flag) public void SetTextActive(bool flag)
@@ -247,7 +250,7 @@ namespace XCharts.Runtime
AdjustIconPos(); AdjustIconPos();
if (m_HideIconIfTextEmpty && isIconActive) if (m_HideIconIfTextEmpty && isIconActive)
{ {
ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text)); SetIconActive(!string.IsNullOrEmpty(text));
} }
} }
return false; return false;

View File

@@ -41,22 +41,22 @@ namespace XCharts.Runtime
return s_Builder.ToString(); return s_Builder.ToString();
} }
public static void SetActive(GameObject gameObject, bool active) public static bool SetActive(GameObject gameObject, bool active)
{ {
if (gameObject == null) return; if (gameObject == null) return false;
SetActive(gameObject.transform, active); return SetActive(gameObject.transform, active);
} }
public static void SetActive(Image image, bool active) public static bool SetActive(Image image, bool active)
{ {
if (image == null) return; if (image == null) return false;
SetActive(image.gameObject, active); return SetActive(image.gameObject, active);
} }
public static void SetActive(Text text, bool active) public static bool SetActive(Text text, bool active)
{ {
if (text == null) return; if (text == null) return false;
SetActive(text.gameObject, active); return SetActive(text.gameObject, active);
} }
/// <summary> /// <summary>
@@ -64,12 +64,14 @@ namespace XCharts.Runtime
/// </summary> /// </summary>
/// <param name="transform"></param> /// <param name="transform"></param>
/// <param name="active"></param> /// <param name="active"></param>
public static void SetActive(Transform transform, bool active) public static bool SetActive(Transform transform, bool active)
{ {
if (transform == null) return; if (transform == null) return false;
if (active) transform.localScale = Vector3.one; if (active) transform.localScale = Vector3.one;
else transform.localScale = Vector3.zero; else transform.localScale = Vector3.zero;
return true;
} }
public static void HideAllObject(GameObject obj, string match = null) public static void HideAllObject(GameObject obj, string match = null)
{ {
if (obj == null) return; if (obj == null) return;
@@ -460,7 +462,7 @@ namespace XCharts.Runtime
label.color = (!labelStyle.background.autoColor || autoColor == Color.clear) ? label.color = (!labelStyle.background.autoColor || autoColor == Color.clear) ?
labelStyle.background.color : autoColor; labelStyle.background.color : autoColor;
label.sprite = labelStyle.background.sprite; label.sprite = labelStyle.background.sprite;
if(label.type != labelStyle.background.type) if (label.type != labelStyle.background.type)
label.type = labelStyle.background.type; label.type = labelStyle.background.type;
} }
else else

View File

@@ -368,7 +368,7 @@ namespace XCharts.Runtime
var textName = string.Format("{0}_{1}_{2}_{3}", s_SerieLabelObjectName, serie.index, serieData.index, i); var textName = string.Format("{0}_{1}_{2}_{3}", s_SerieLabelObjectName, serie.index, serieData.index, i);
var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common, var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common,
"", dataAutoColor, TextAnchor.MiddleCenter); "", dataAutoColor, TextAnchor.MiddleCenter);
label.SetActive(serieLabel.show); label.SetActive(false);
serieData.context.dataLabels.Add(label); serieData.context.dataLabels.Add(label);
} }
} }
@@ -377,7 +377,7 @@ namespace XCharts.Runtime
var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index); var textName = ChartCached.GetSerieLabelName(s_SerieLabelObjectName, serie.index, serieData.index);
var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common, var label = ChartHelper.AddChartLabel(textName, serieLabelRoot.transform, serieLabel, chart.theme.common,
"", dataAutoColor, TextAnchor.MiddleCenter); "", dataAutoColor, TextAnchor.MiddleCenter);
label.SetActive(serieLabel.show); label.SetActive(false);
serieData.labelObject = label; serieData.labelObject = label;
} }
@@ -581,10 +581,6 @@ namespace XCharts.Runtime
{ {
foreach (var serieData in serie.data) foreach (var serieData in serie.data)
{ {
if (serieData.labelObject == null && serieData.context.dataLabels.Count <= 0)
{
continue;
}
serieData.SetLabelActive(false); serieData.SetLabelActive(false);
} }
} }