mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-24 01:40:06 +00:00
增加IconStyle的autoHideWhenLabelEmpty参数设置当label为空时是否自动隐藏图标
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.06.21) Add `iconStyle`'s `AutoHideWhenLabelEmpty` to set whether the icon is automatically hidden when `label` is empty
|
||||
|
||||
# # v2.2.3
|
||||
|
||||
* (2021.06.20) Release `v2.2.3` version
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
## master
|
||||
|
||||
* (2021.06.21) 增加`IconStyle`的`autoHideWhenLabelEmpty`参数设置当`label`为空时是否自动隐藏图标
|
||||
|
||||
## v2.2.3
|
||||
|
||||
* (2021.06.20) 发布`v2.2.3`版本
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace XCharts
|
||||
PropertyField(prop, "m_Width");
|
||||
PropertyField(prop, "m_Height");
|
||||
PropertyField(prop, "m_Offset");
|
||||
PropertyField(prop, "m_AutoHideWhenLabelEmpty");
|
||||
--EditorGUI.indentLevel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace XCharts
|
||||
[SerializeField] private float m_Width = 20;
|
||||
[SerializeField] private float m_Height = 20;
|
||||
[SerializeField] private Vector3 m_Offset;
|
||||
[SerializeField] private bool m_AutoHideWhenLabelEmpty = false;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
@@ -36,6 +37,7 @@ namespace XCharts
|
||||
m_Width = 20;
|
||||
m_Height = 20;
|
||||
m_Offset = Vector3.zero;
|
||||
m_AutoHideWhenLabelEmpty = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether the data icon is show.
|
||||
@@ -71,6 +73,10 @@ namespace XCharts
|
||||
/// 水平方向对齐方式。
|
||||
/// </summary>
|
||||
public Align align { get { return m_Align; } set { m_Align = value; } }
|
||||
/// <summary>
|
||||
/// 当label内容为空时是否自动隐藏图标
|
||||
/// </summary>
|
||||
public bool autoHideWhenLabelEmpty { get { return m_AutoHideWhenLabelEmpty; } set { m_AutoHideWhenLabelEmpty = value; } }
|
||||
public IconStyle Clone()
|
||||
{
|
||||
var iconStyle = new IconStyle();
|
||||
@@ -82,6 +88,7 @@ namespace XCharts
|
||||
iconStyle.height = height;
|
||||
iconStyle.offset = offset;
|
||||
iconStyle.align = align;
|
||||
iconStyle.autoHideWhenLabelEmpty = autoHideWhenLabelEmpty;
|
||||
return iconStyle;
|
||||
}
|
||||
|
||||
@@ -95,6 +102,7 @@ namespace XCharts
|
||||
height = iconStyle.height;
|
||||
offset = iconStyle.offset;
|
||||
align = iconStyle.align;
|
||||
autoHideWhenLabelEmpty = iconStyle.autoHideWhenLabelEmpty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,14 +576,14 @@ namespace XCharts
|
||||
{
|
||||
txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
|
||||
Vector2.zero, new Vector2(0, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis,
|
||||
labelName, true);
|
||||
labelName);
|
||||
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleLeft));
|
||||
}
|
||||
else
|
||||
{
|
||||
txt = ChartHelper.AddAxisLabelObject(i, objName + i, axisObj.transform, Vector2.zero,
|
||||
Vector2.zero, new Vector2(1, 0.5f), new Vector2(textWidth, textHeight), yAxis, theme.axis,
|
||||
labelName, true);
|
||||
labelName);
|
||||
txt.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleRight));
|
||||
}
|
||||
var labelWidth = AxisHelper.GetScaleWidth(yAxis, grid.runtimeHeight, i + 1, dataZoom);
|
||||
@@ -698,7 +698,7 @@ namespace XCharts
|
||||
xAxis.runtimeMaxValue, dataZoom, isPercentStack);
|
||||
var label = ChartHelper.AddAxisLabelObject(i, ChartCached.GetXAxisName(xAxisIndex, i), axisObj.transform,
|
||||
new Vector2(0, 1), new Vector2(0, 1), new Vector2(1, 0.5f), new Vector2(textWidth, textHeight),
|
||||
xAxis, theme.axis,labelName, true);
|
||||
xAxis, theme.axis, labelName);
|
||||
|
||||
if (i == 0) xAxis.axisLabel.SetRelatedText(label.label, labelWidth);
|
||||
label.label.SetAlignment(axisLabelTextStyle.GetAlignment(TextAnchor.MiddleCenter));
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace XCharts
|
||||
{
|
||||
public class ChartLabel : ChartObject
|
||||
{
|
||||
private bool m_AutoHideIconWhenLabelEmpty = false;
|
||||
private bool m_LabelAutoSize = true;
|
||||
private float m_LabelPaddingLeftRight = 3f;
|
||||
private float m_LabelPaddingTopBottom = 3f;
|
||||
@@ -48,6 +49,9 @@ namespace XCharts
|
||||
}
|
||||
}
|
||||
|
||||
public bool autoHideIconWhenLabelEmpty { set { m_AutoHideIconWhenLabelEmpty = value; } }
|
||||
public bool isIconActive { get; private set; }
|
||||
|
||||
public ChartLabel()
|
||||
{
|
||||
}
|
||||
@@ -91,24 +95,21 @@ namespace XCharts
|
||||
public void UpdateIcon(IconStyle iconStyle, Sprite sprite = null)
|
||||
{
|
||||
if (m_IconImage == null) return;
|
||||
SetIconActive(iconStyle.show);
|
||||
if (iconStyle.show)
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, true);
|
||||
m_IconImage.sprite = sprite == null ? iconStyle.sprite : sprite;
|
||||
m_IconImage.color = iconStyle.color;
|
||||
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
|
||||
m_IconOffest = iconStyle.offset;
|
||||
m_Align = iconStyle.align;
|
||||
m_AutoHideIconWhenLabelEmpty = iconStyle.autoHideWhenLabelEmpty;
|
||||
AdjustIconPos();
|
||||
if (iconStyle.layer == IconStyle.Layer.UnderLabel)
|
||||
m_IconRect.SetSiblingIndex(0);
|
||||
else
|
||||
m_IconRect.SetSiblingIndex(m_GameObject.transform.childCount - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, false);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetLabelWidth()
|
||||
@@ -156,6 +157,7 @@ namespace XCharts
|
||||
}
|
||||
public void SetIconActive(bool flag)
|
||||
{
|
||||
isIconActive = flag;
|
||||
if (m_IconImage) ChartHelper.SetActive(m_IconImage, flag);
|
||||
}
|
||||
|
||||
@@ -179,13 +181,17 @@ namespace XCharts
|
||||
return sizeChange;
|
||||
}
|
||||
AdjustIconPos();
|
||||
if (m_AutoHideIconWhenLabelEmpty && isIconActive)
|
||||
{
|
||||
ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void AdjustIconPos()
|
||||
{
|
||||
if (m_IconImage && m_IconImage.sprite != null && m_IconRect)
|
||||
if (m_IconImage && m_IconRect)
|
||||
{
|
||||
var iconX = 0f;
|
||||
switch (m_Align)
|
||||
|
||||
@@ -400,7 +400,7 @@ namespace XCharts
|
||||
}
|
||||
|
||||
public static ChartLabel AddAxisLabelObject(int index, string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax,
|
||||
Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme, string content, bool autoHideWhenContentEmpty = false)
|
||||
Vector2 pivot, Vector2 sizeDelta, Axis axis, ComponentTheme theme, string content)
|
||||
{
|
||||
var textStyle = axis.axisLabel.textStyle;
|
||||
var iconStyle = axis.iconStyle;
|
||||
@@ -414,10 +414,6 @@ namespace XCharts
|
||||
GameObject.DestroyImmediate(oldText);
|
||||
}
|
||||
var labelShow = axis.axisLabel.show && (axis.axisLabel.interval == 0 || index % (axis.axisLabel.interval + 1) == 0);
|
||||
if (autoHideWhenContentEmpty && string.IsNullOrEmpty(content))
|
||||
{
|
||||
labelShow &= false;
|
||||
}
|
||||
label.label = AddTextObject("Text", label.gameObject.transform, anchorMin, anchorMax, pivot, sizeDelta, textStyle, theme);
|
||||
label.icon = ChartHelper.AddIcon("Icon", label.gameObject.transform, iconStyle.width, iconStyle.height);
|
||||
label.SetAutoSize(false);
|
||||
|
||||
Reference in New Issue
Block a user