修复Tooltip在图表设置其他锚点时手机上显示位置异常的问题

This commit is contained in:
monitor1394
2024-11-30 23:45:28 +08:00
parent 6c42fe6399
commit bc1a11c4e3
7 changed files with 61 additions and 48 deletions

View File

@@ -90,7 +90,44 @@ namespace XCharts.Runtime
if (screenPos.y > Screen.height - screenGap)
pos.y -= Mathf.Abs(screenPos.y - Screen.height) + screenGap;
tooltip.UpdateContentPos(pos, chartRect.width / 2, chartRect.height / 2);
Debug.Log("rect: " + chartRect);
UpdateContentPos(tooltip, pos, chartRect);
}
/// <summary>
/// 更新文本框位置
/// </summary>
/// <param name="pos"></param>
private static void UpdateContentPos(Tooltip tooltip, Vector2 pos, Rect chartRect)
{
if (tooltip.view != null)
{
var width = chartRect.width;
var height = chartRect.height;
switch (tooltip.position)
{
case Tooltip.Position.Auto:
#if UNITY_ANDROID || UNITY_IOS
if (tooltip.fixedY == 0) pos.y = chartRect.x + ChartHelper.GetActualValue(0.7f, height);
else pos.y = chartRect.y + ChartHelper.GetActualValue(tooltip.fixedY, height);
#endif
break;
case Tooltip.Position.Custom:
pos = new Vector2(chartRect.x, chartRect.y);
pos.x += ChartHelper.GetActualValue(tooltip.fixedX, width);
pos.y += ChartHelper.GetActualValue(tooltip.fixedY, height);
break;
case Tooltip.Position.FixedX:
pos = new Vector2(chartRect.x, pos.y);
pos.x += ChartHelper.GetActualValue(tooltip.fixedX, width);
break;
case Tooltip.Position.FixedY:
pos = new Vector2(pos.x, chartRect.y);
pos.y += ChartHelper.GetActualValue(tooltip.fixedY, height);
break;
}
tooltip.view.UpdatePosition(pos);
}
}
public static string GetItemNumericFormatter(Tooltip tooltip, Serie serie, SerieData serieData)