From 5bc14dd37ae7c3558b6d78aa5339c0709d397204 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Mon, 20 Jun 2022 13:41:28 +0800 Subject: [PATCH] [optimaze][tooltip] content rect limit (#202) --- CHANGELOG.md | 2 ++ Runtime/Component/Tooltip/TooltipHelper.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de0979f2..cb879504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,8 @@ ## master +* (2022.06.20) 优化`Tooltip`的边界限制 (#202) +* (2022.06.20) 修复`TextMeshPro`开启时编译错误 * (2022.06.20) 修复`Animation`的渐出动画不生效的问题 ## v3.0.1 diff --git a/Runtime/Component/Tooltip/TooltipHelper.cs b/Runtime/Component/Tooltip/TooltipHelper.cs index 9e099bd9..ce389f64 100644 --- a/Runtime/Component/Tooltip/TooltipHelper.cs +++ b/Runtime/Component/Tooltip/TooltipHelper.cs @@ -64,13 +64,18 @@ namespace XCharts.Runtime var pos = tooltip.view.GetTargetPos(); if (pos.x + tooltip.context.width > chartRect.x + chartRect.width) { - //pos.x = chartRect.x + chartRect.width - tooltip.context.width; - pos.x = pos.x - tooltip.context.width - tooltip.offset.x; + pos.x = tooltip.context.pointer.x - tooltip.context.width - tooltip.offset.x; + } + else if (pos.x < chartRect.x) + { + pos.x = tooltip.context.pointer.x - tooltip.context.width + Mathf.Abs(tooltip.offset.x); } if (pos.y - tooltip.context.height < chartRect.y) { pos.y = chartRect.y + tooltip.context.height; } + if (pos.y > chartRect.y + chartRect.height) + pos.y = chartRect.y + chartRect.height; tooltip.UpdateContentPos(pos); }