From d5647a448d3e4321886f52383aa2ea4f4144f6e7 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Tue, 26 Nov 2024 23:18:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`Tooltip`=E5=9C=A8=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E6=83=85=E5=86=B5=E4=B8=8B=E5=8F=AF=E8=83=BD=E4=BC=9A?= =?UTF-8?q?=E8=B6=85=E5=87=BA=E5=B1=8F=E5=B9=95=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation~/zh/changelog.md | 1 + Runtime/Component/Tooltip/TooltipHandler.cs | 4 ++-- Runtime/Component/Tooltip/TooltipHelper.cs | 14 +++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Documentation~/zh/changelog.md b/Documentation~/zh/changelog.md index a87c6fad..65daa66f 100644 --- a/Documentation~/zh/changelog.md +++ b/Documentation~/zh/changelog.md @@ -77,6 +77,7 @@ slug: /changelog ## master +* (2024.11.26) 修复`Tooltip`在特殊情况下可能会超出屏幕显示不完整的问题 * (2024.11.24) 修复`UITable`在拖拽时也会点选的问题 * (2024.11.22) 修复`Time`时间轴在开启`Animation`时动态变更效果异常的问题 * (2024.11.18) 优化`Line`在数据点过密时有更好的绘制效果 diff --git a/Runtime/Component/Tooltip/TooltipHandler.cs b/Runtime/Component/Tooltip/TooltipHandler.cs index ea88ab2d..21787aa1 100644 --- a/Runtime/Component/Tooltip/TooltipHandler.cs +++ b/Runtime/Component/Tooltip/TooltipHandler.cs @@ -546,7 +546,7 @@ namespace XCharts.Runtime tooltip.SetActive(m_ShowTooltip); tooltip.view.Refresh(); - TooltipHelper.LimitInRect(tooltip, chart.chartRect); + TooltipHelper.LimitInRect(chart, tooltip, chart.chartRect); return true; } @@ -633,7 +633,7 @@ namespace XCharts.Runtime tooltip.SetActive(m_ShowTooltip); if (tooltip.view != null) tooltip.view.Refresh(); - TooltipHelper.LimitInRect(tooltip, chart.chartRect); + TooltipHelper.LimitInRect(chart, tooltip, chart.chartRect); return true; } return false; diff --git a/Runtime/Component/Tooltip/TooltipHelper.cs b/Runtime/Component/Tooltip/TooltipHelper.cs index 4c462262..ffefaffc 100644 --- a/Runtime/Component/Tooltip/TooltipHelper.cs +++ b/Runtime/Component/Tooltip/TooltipHelper.cs @@ -58,7 +58,7 @@ namespace XCharts.Runtime return "-".Equals(itemFormatter) ||"{i}".Equals(itemFormatter, StringComparison.CurrentCultureIgnoreCase); } - public static void LimitInRect(Tooltip tooltip, Rect chartRect) + public static void LimitInRect(BaseChart chart, Tooltip tooltip, Rect chartRect) { if (tooltip.view == null) return; @@ -78,6 +78,18 @@ namespace XCharts.Runtime } if (pos.y > chartRect.y + chartRect.height) pos.y = chartRect.y + chartRect.height; + var screenGap = 10; + var screenPos = chart.LocalPointToScreenPoint(pos); + if (screenPos.x < screenGap) + pos.x += Mathf.Abs(screenPos.x) + screenGap; + if (screenPos.x + tooltip.context.width > Screen.width - screenGap) + pos.x -= Mathf.Abs(screenPos.x + tooltip.context.width - Screen.width) + screenGap; + + if (screenPos.y < tooltip.context.height + screenGap) + pos.y += Mathf.Abs(screenPos.y - tooltip.context.height) + screenGap; + if (screenPos.y > Screen.height - screenGap) + pos.y -= Mathf.Abs(screenPos.y - Screen.height) + screenGap; + tooltip.UpdateContentPos(pos, chartRect.width / 2, chartRect.height / 2); }