From f2001fbc82aca9417e2b96f122650416c83652db Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sun, 27 Nov 2022 17:28:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96`Comment`=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E7=94=A8`Location=E4=BB=A3=E6=9B=BFPosition`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/zh/changelog.md | 1 + Editor/ChildComponents/CommentItemDrawer.cs | 2 +- Runtime/Component/Comment/Comment.cs | 14 +++++++++++++- Runtime/Component/Comment/CommentHander.cs | 5 ++++- Runtime/Component/Comment/CommentItem.cs | 17 +++++++++++------ 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index 0267b6af..e6391cba 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -64,6 +64,7 @@ slug: /changelog ## master +* (2022.11.27) 优化`Comment`的位置,用`Location代替Position` * (2022.11.27) 优化`Tooltip`的`LineStyle`支持设置`Shadow`时的颜色 * (2022.11.26) 优化`LabelLine`的`symbol`默认不显示 * (2022.11.26) 修复`LineChart`在`XY`都为数值轴时添加无序数据显示异常的问题 diff --git a/Editor/ChildComponents/CommentItemDrawer.cs b/Editor/ChildComponents/CommentItemDrawer.cs index 962ba612..a674af30 100644 --- a/Editor/ChildComponents/CommentItemDrawer.cs +++ b/Editor/ChildComponents/CommentItemDrawer.cs @@ -15,7 +15,7 @@ namespace XCharts.Editor { ++EditorGUI.indentLevel; PropertyField(prop, "m_Content"); - PropertyField(prop, "m_Position"); + PropertyField(prop, "m_Location"); //PropertyField(prop, "m_MarkRect"); //PropertyField(prop, "m_MarkStyle"); PropertyField(prop, "m_LabelStyle"); diff --git a/Runtime/Component/Comment/Comment.cs b/Runtime/Component/Comment/Comment.cs index 4274a774..f5a8dbef 100644 --- a/Runtime/Component/Comment/Comment.cs +++ b/Runtime/Component/Comment/Comment.cs @@ -10,7 +10,7 @@ namespace XCharts.Runtime /// [Serializable] [ComponentHandler(typeof(CommentHander), true)] - public class Comment : MainComponent + public class Comment : MainComponent, IPropertyChanged { [SerializeField] private bool m_Show = true; [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle(); @@ -65,5 +65,17 @@ namespace XCharts.Runtime } return m_MarkStyle; } + + /// + /// Callback handling when parameters change. + /// |参数变更时的回调处理。 + /// + public void OnChanged() + { + foreach (var item in items) + { + item.location.OnChanged(); + } + } } } \ No newline at end of file diff --git a/Runtime/Component/Comment/CommentHander.cs b/Runtime/Component/Comment/CommentHander.cs index f5985528..eef0f5d2 100644 --- a/Runtime/Component/Comment/CommentHander.cs +++ b/Runtime/Component/Comment/CommentHander.cs @@ -12,6 +12,7 @@ namespace XCharts.Runtime public override void InitComponent() { var comment = component; + comment.OnChanged(); comment.painter = null; comment.refreshComponent = delegate() { @@ -30,10 +31,12 @@ namespace XCharts.Runtime { var item = comment.items[i]; var labelStyle = comment.GetLabelStyle(i); + var labelPos = chart.chartPosition + item.location.GetPosition(chart.chartWidth, chart.chartHeight); var label = ChartHelper.AddChartLabel(s_CommentObjectName + i, commentObj.transform, labelStyle, chart.theme.common, GetContent(item), Color.clear, TextAnchor.MiddleCenter); label.SetActive(comment.show && item.show); - label.SetPosition(item.position + labelStyle.offset); + label.SetPosition(labelPos); + label.text.SetLocalPosition(labelStyle.offset); } }; comment.refreshComponent(); diff --git a/Runtime/Component/Comment/CommentItem.cs b/Runtime/Component/Comment/CommentItem.cs index 5a3a891f..2b7ab9dd 100644 --- a/Runtime/Component/Comment/CommentItem.cs +++ b/Runtime/Component/Comment/CommentItem.cs @@ -12,10 +12,11 @@ namespace XCharts.Runtime { [SerializeField] private bool m_Show = true; [SerializeField] private string m_Content = "comment"; - [SerializeField] private Vector3 m_Position; [SerializeField] private Rect m_MarkRect; [SerializeField] private CommentMarkStyle m_MarkStyle = new CommentMarkStyle() { show = false }; [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle() { show = false }; + [SerializeField] [Since("v3.5.0")]private Location m_Location = new Location() { align = Location.Align.TopLeft, top = 0.125f }; + /// /// Set this to false to prevent this comment item from showing. @@ -23,11 +24,6 @@ namespace XCharts.Runtime /// public bool show { get { return m_Show; } set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetComponentDirty(); } } /// - /// position of comment. - /// |注解项的位置坐标。 - /// - public Vector3 position { get { return m_Position; } set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetComponentDirty(); } } - /// /// content of comment. /// |注解的文本内容。支持模板参数,可以参考Tooltip的itemFormatter。 /// @@ -51,5 +47,14 @@ namespace XCharts.Runtime get { return m_LabelStyle; } set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); } } + /// + /// The location of comment. + /// |Comment显示的位置。 + /// + public Location location + { + get { return m_Location; } + set { if (PropertyUtil.SetClass(ref m_Location, value)) SetComponentDirty(); } + } } } \ No newline at end of file