diff --git a/CHANGELOG.md b/CHANGELOG.md index 211de884..c5097c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ ## master +* (2022.04.19) 增加`Label`的`rotate`支持设置旋转 * (2022.04.17) 修复`Bar`在数值为负数时动画无效的问题 * (2022.04.17) 增加`ItemStyle`的`BorderGap`支持设置边框间距 * (2022.04.16) 优化`Bar`的`Border`和`Capsule`胶囊柱图 diff --git a/Editor/ChildComponents/LabelStyleDrawer.cs b/Editor/ChildComponents/LabelStyleDrawer.cs index bd933807..07ac205f 100644 --- a/Editor/ChildComponents/LabelStyleDrawer.cs +++ b/Editor/ChildComponents/LabelStyleDrawer.cs @@ -18,6 +18,7 @@ namespace XCharts.Editor PropertyField(prop, "m_Position"); PropertyField(prop, "m_Offset"); PropertyField(prop, "m_AutoOffset"); + PropertyField(prop, "m_Rotate"); PropertyField(prop, "m_Distance"); PropertyField(prop, "m_Formatter"); PropertyField(prop, "m_NumericFormatter"); diff --git a/Runtime/Component/Child/LabelStyle.cs b/Runtime/Component/Child/LabelStyle.cs index 86513731..0f941db2 100644 --- a/Runtime/Component/Child/LabelStyle.cs +++ b/Runtime/Component/Child/LabelStyle.cs @@ -70,6 +70,7 @@ namespace XCharts.Runtime [SerializeField] protected bool m_Show = true; [SerializeField] Position m_Position = Position.Outside; [SerializeField] protected Vector3 m_Offset; + [SerializeField] protected float m_Rotate; [SerializeField] protected float m_Distance; [SerializeField] protected string m_Formatter; [SerializeField] protected float m_PaddingLeftRight = 2f; @@ -88,6 +89,7 @@ namespace XCharts.Runtime m_Position = Position.Outside; m_Offset = Vector3.zero; m_Distance = 0; + m_Rotate = 0; m_PaddingLeftRight = 2f; m_PaddingTopBottom = 2f; m_BackgroundWidth = 0; @@ -142,6 +144,15 @@ namespace XCharts.Runtime set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetVerticesDirty(); } } /// + /// Rotation of label. + /// |文本的旋转。 + /// + public float rotate + { + get { return m_Rotate; } + set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); } + } + /// /// 距离轴线的距离。 /// public float distance diff --git a/Runtime/Internal/Pools/SerieLabelPool.cs b/Runtime/Internal/Pools/SerieLabelPool.cs index 8a2bac29..5eee1690 100644 --- a/Runtime/Internal/Pools/SerieLabelPool.cs +++ b/Runtime/Internal/Pools/SerieLabelPool.cs @@ -27,12 +27,12 @@ namespace XCharts.Runtime m_ReleaseDic.Remove(element.GetInstanceID()); element.name = name; element.transform.SetParent(parent); - element.transform.localEulerAngles = new Vector3(0, 0, label.textStyle.rotate); var text = new ChartText(element); text.SetColor(color); text.SetFontAndSizeAndStyle(label.textStyle, theme.common); ChartHelper.SetActive(element, true); } + element.transform.localEulerAngles = new Vector3(0, 0, label.rotate); return element; } diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index d639fc69..f0eb1159 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -237,7 +237,7 @@ namespace XCharts.Runtime { GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate); - if(chartText == null) + if (chartText == null) chartText = new ChartText(); #if dUI_TextMeshPro RemoveComponent(txtObj); @@ -435,9 +435,29 @@ namespace XCharts.Runtime internal static GameObject AddSerieLabel(string name, Transform parent, float width, float height, Color color, TextStyle textStyle, ThemeStyle theme) { - var anchorMin = new Vector2(0.5f, 0.5f); - var anchorMax = new Vector2(0.5f, 0.5f); - var pivot = new Vector2(0.5f, 0.5f); + Vector3 anchorMin, anchorMax, pivot; + switch (textStyle.alignment) + { + case TextAnchor.LowerLeft: + case TextAnchor.UpperLeft: + case TextAnchor.MiddleLeft: + anchorMin = new Vector2(0f, 0.5f); + anchorMax = new Vector2(0f, 0.5f); + pivot = new Vector2(0f, 0.5f); + break; + case TextAnchor.LowerRight: + case TextAnchor.UpperRight: + case TextAnchor.MiddleRight: + anchorMin = new Vector2(1, 0.5f); + anchorMax = new Vector2(1, 0.5f); + pivot = new Vector2(1, 0.5f); + break; + default: + anchorMin = new Vector2(0.5f, 0.5f); + anchorMax = new Vector2(0.5f, 0.5f); + pivot = new Vector2(0.5f, 0.5f); + break; + } var sizeDelta = (width != 0 && height != 0) ? new Vector2(width, height) : new Vector2(50, textStyle.GetFontSize(theme.common) + 2); @@ -450,7 +470,6 @@ namespace XCharts.Runtime txt.SetLocalPosition(new Vector2(0, 0)); txt.SetLocalEulerAngles(Vector3.zero); labelObj.transform.localPosition = Vector3.zero; - labelObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate); return labelObj; }