mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 02:40:13 +00:00
增加IconStyle的align参数设置图标的水平对齐
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2021.06.12) Add `iconStyle` `align` parameter to set the horizontal alignment of the icon
|
||||||
* (2021.06.12) Optimized import of `Theme` and automatic font refresh (#148)
|
* (2021.06.12) Optimized import of `Theme` and automatic font refresh (#148)
|
||||||
* (2021.06.10) Fixed compatibility issues with `Unity` version (#154)
|
* (2021.06.10) Fixed compatibility issues with `Unity` version (#154)
|
||||||
* (2021.06.05) Improved Candlestickchart support for inverse (#152)
|
* (2021.06.05) Improved Candlestickchart support for inverse (#152)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2021.06.12) 增加`IconStyle`的`align`参数设置图标的水平对齐
|
||||||
* (2021.06.12) 优化主题`Theme`的导入和字体自动刷新 (#148)
|
* (2021.06.12) 优化主题`Theme`的导入和字体自动刷新 (#148)
|
||||||
* (2021.06.10) 修复`Unity`版本兼容问题 (#154)
|
* (2021.06.10) 修复`Unity`版本兼容问题 (#154)
|
||||||
* (2021.06.05) 完善`CandlestickChart`对`inverse`的支持 (#152)
|
* (2021.06.05) 完善`CandlestickChart`对`inverse`的支持 (#152)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
++EditorGUI.indentLevel;
|
++EditorGUI.indentLevel;
|
||||||
PropertyField(prop, "m_Layer");
|
PropertyField(prop, "m_Layer");
|
||||||
|
PropertyField(prop, "m_Align");
|
||||||
PropertyField(prop, "m_Sprite");
|
PropertyField(prop, "m_Sprite");
|
||||||
PropertyField(prop, "m_Color");
|
PropertyField(prop, "m_Color");
|
||||||
PropertyField(prop, "m_Width");
|
PropertyField(prop, "m_Width");
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ namespace XCharts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 对齐方式
|
/// 对齐方式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum SerieAlign
|
public enum Align
|
||||||
{
|
{
|
||||||
Center,
|
Center,
|
||||||
Left,
|
Left,
|
||||||
@@ -337,7 +337,7 @@ namespace XCharts
|
|||||||
|
|
||||||
[SerializeField] private SerieDataSortType m_DataSortType = SerieDataSortType.Descending;
|
[SerializeField] private SerieDataSortType m_DataSortType = SerieDataSortType.Descending;
|
||||||
[SerializeField] private Orient m_Orient = Orient.Vertical;
|
[SerializeField] private Orient m_Orient = Orient.Vertical;
|
||||||
[SerializeField] private SerieAlign m_Align = SerieAlign.Center;
|
[SerializeField] private Align m_Align = Align.Center;
|
||||||
[SerializeField] private float m_Left;
|
[SerializeField] private float m_Left;
|
||||||
[SerializeField] private float m_Right;
|
[SerializeField] private float m_Right;
|
||||||
[SerializeField] private float m_Top;
|
[SerializeField] private float m_Top;
|
||||||
@@ -1045,7 +1045,7 @@ namespace XCharts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 组件水平方向对齐方式。
|
/// 组件水平方向对齐方式。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SerieAlign align
|
public Align align
|
||||||
{
|
{
|
||||||
get { return m_Align; }
|
get { return m_Align; }
|
||||||
set { if (PropertyUtil.SetStruct(ref m_Align, value)) SetVerticesDirty(); }
|
set { if (PropertyUtil.SetStruct(ref m_Align, value)) SetVerticesDirty(); }
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace XCharts
|
|||||||
}
|
}
|
||||||
[SerializeField] private bool m_Show;
|
[SerializeField] private bool m_Show;
|
||||||
[SerializeField] private Layer m_Layer;
|
[SerializeField] private Layer m_Layer;
|
||||||
|
[SerializeField] private Align m_Align = Align.Left;
|
||||||
[SerializeField] private Sprite m_Sprite;
|
[SerializeField] private Sprite m_Sprite;
|
||||||
[SerializeField] private Color m_Color = Color.white;
|
[SerializeField] private Color m_Color = Color.white;
|
||||||
[SerializeField] private float m_Width = 20;
|
[SerializeField] private float m_Width = 20;
|
||||||
@@ -66,7 +67,10 @@ namespace XCharts
|
|||||||
/// 图标偏移。
|
/// 图标偏移。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
|
public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } }
|
||||||
|
/// <summary>
|
||||||
|
/// 水平方向对齐方式。
|
||||||
|
/// </summary>
|
||||||
|
public Align align { get { return m_Align; } set { m_Align = value; } }
|
||||||
public IconStyle Clone()
|
public IconStyle Clone()
|
||||||
{
|
{
|
||||||
var iconStyle = new IconStyle();
|
var iconStyle = new IconStyle();
|
||||||
@@ -77,6 +81,7 @@ namespace XCharts
|
|||||||
iconStyle.width = width;
|
iconStyle.width = width;
|
||||||
iconStyle.height = height;
|
iconStyle.height = height;
|
||||||
iconStyle.offset = offset;
|
iconStyle.offset = offset;
|
||||||
|
iconStyle.align = align;
|
||||||
return iconStyle;
|
return iconStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +94,7 @@ namespace XCharts
|
|||||||
width = iconStyle.width;
|
width = iconStyle.width;
|
||||||
height = iconStyle.height;
|
height = iconStyle.height;
|
||||||
offset = iconStyle.offset;
|
offset = iconStyle.offset;
|
||||||
|
align = iconStyle.align;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace XCharts
|
|||||||
private RectTransform m_IconRect;
|
private RectTransform m_IconRect;
|
||||||
private RectTransform m_ObjectRect;
|
private RectTransform m_ObjectRect;
|
||||||
private Vector3 m_IconOffest;
|
private Vector3 m_IconOffest;
|
||||||
|
private Align m_Align = Align.Left;
|
||||||
|
|
||||||
private Image m_IconImage;
|
private Image m_IconImage;
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ namespace XCharts
|
|||||||
m_LabelText = new ChartText(labelObj);
|
m_LabelText = new ChartText(labelObj);
|
||||||
m_LabelRect = m_LabelText.gameObject.GetComponent<RectTransform>();
|
m_LabelRect = m_LabelText.gameObject.GetComponent<RectTransform>();
|
||||||
m_ObjectRect = labelObj.GetComponent<RectTransform>();
|
m_ObjectRect = labelObj.GetComponent<RectTransform>();
|
||||||
|
m_Align = Align.Left;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAutoSize(bool flag)
|
public void SetAutoSize(bool flag)
|
||||||
@@ -96,6 +98,7 @@ namespace XCharts
|
|||||||
m_IconImage.color = iconStyle.color;
|
m_IconImage.color = iconStyle.color;
|
||||||
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
|
m_IconRect.sizeDelta = new Vector2(iconStyle.width, iconStyle.height);
|
||||||
m_IconOffest = iconStyle.offset;
|
m_IconOffest = iconStyle.offset;
|
||||||
|
m_Align = iconStyle.align;
|
||||||
AdjustIconPos();
|
AdjustIconPos();
|
||||||
if (iconStyle.layer == IconStyle.Layer.UnderLabel)
|
if (iconStyle.layer == IconStyle.Layer.UnderLabel)
|
||||||
m_IconRect.SetSiblingIndex(0);
|
m_IconRect.SetSiblingIndex(0);
|
||||||
@@ -185,22 +188,47 @@ namespace XCharts
|
|||||||
if (m_IconImage && m_IconImage.sprite != null && m_IconRect)
|
if (m_IconImage && m_IconImage.sprite != null && m_IconRect)
|
||||||
{
|
{
|
||||||
var iconX = 0f;
|
var iconX = 0f;
|
||||||
switch (m_LabelText.text.alignment)
|
switch (m_Align)
|
||||||
{
|
{
|
||||||
case TextAnchor.LowerLeft:
|
case Align.Left:
|
||||||
case TextAnchor.UpperLeft:
|
switch (m_LabelText.text.alignment)
|
||||||
case TextAnchor.MiddleLeft:
|
{
|
||||||
iconX = -m_ObjectRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2;
|
case TextAnchor.LowerLeft:
|
||||||
|
case TextAnchor.UpperLeft:
|
||||||
|
case TextAnchor.MiddleLeft:
|
||||||
|
iconX = -m_ObjectRect.sizeDelta.x / 2 - m_IconRect.sizeDelta.x / 2;
|
||||||
|
break;
|
||||||
|
case TextAnchor.LowerRight:
|
||||||
|
case TextAnchor.UpperRight:
|
||||||
|
case TextAnchor.MiddleRight:
|
||||||
|
iconX = m_ObjectRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2;
|
||||||
|
break;
|
||||||
|
case TextAnchor.LowerCenter:
|
||||||
|
case TextAnchor.UpperCenter:
|
||||||
|
case TextAnchor.MiddleCenter:
|
||||||
|
iconX = -m_LabelText.GetPreferredWidth() / 2 - m_IconRect.sizeDelta.x / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TextAnchor.LowerRight:
|
case Align.Right:
|
||||||
case TextAnchor.UpperRight:
|
switch (m_LabelText.text.alignment)
|
||||||
case TextAnchor.MiddleRight:
|
{
|
||||||
iconX = m_ObjectRect.sizeDelta.x / 2 - m_LabelText.GetPreferredWidth() - m_IconRect.sizeDelta.x / 2;
|
case TextAnchor.LowerLeft:
|
||||||
break;
|
case TextAnchor.UpperLeft:
|
||||||
case TextAnchor.LowerCenter:
|
case TextAnchor.MiddleLeft:
|
||||||
case TextAnchor.UpperCenter:
|
iconX = m_ObjectRect.sizeDelta.x / 2 + m_IconRect.sizeDelta.x / 2;
|
||||||
case TextAnchor.MiddleCenter:
|
break;
|
||||||
iconX = -m_LabelText.GetPreferredWidth() / 2 - m_IconRect.sizeDelta.x / 2;
|
case TextAnchor.LowerRight:
|
||||||
|
case TextAnchor.UpperRight:
|
||||||
|
case TextAnchor.MiddleRight:
|
||||||
|
iconX = m_IconRect.sizeDelta.x / 2;
|
||||||
|
break;
|
||||||
|
case TextAnchor.LowerCenter:
|
||||||
|
case TextAnchor.UpperCenter:
|
||||||
|
case TextAnchor.MiddleCenter:
|
||||||
|
iconX = m_LabelText.GetPreferredWidth() / 2 + m_IconRect.sizeDelta.x / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_IconRect.anchoredPosition = m_IconOffest + new Vector3(iconX, 0);
|
m_IconRect.anchoredPosition = m_IconOffest + new Vector3(iconX, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user