mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-25 02:10:16 +00:00
[optimize][legend] support background and padding
This commit is contained in:
@@ -52,6 +52,7 @@ namespace XCharts.Runtime
|
||||
var iconObj = ChartHelper.AddObject("icon", btnObj.transform, anchorMin, anchorMax, pivot, iconSizeDelta);
|
||||
var img = ChartHelper.GetOrAddComponent<Image>(btnObj);
|
||||
img.color = Color.clear;
|
||||
img.raycastTarget = true;
|
||||
ChartHelper.GetOrAddComponent<Button>(btnObj);
|
||||
ChartHelper.GetOrAddComponent<Image>(iconObj);
|
||||
|
||||
@@ -69,9 +70,22 @@ namespace XCharts.Runtime
|
||||
item.SetIconImage(legend.GetIcon(i));
|
||||
item.SetContentPosition(legend.labelStyle.offset);
|
||||
item.SetContent(content);
|
||||
//item.SetBackground(legend.background);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void SetLegendBackground(Legend legend, ImageStyle style)
|
||||
{
|
||||
var background = legend.context.background;
|
||||
if (background == null) return;
|
||||
ChartHelper.SetActive(background, style.show);
|
||||
if (!style.show) return;
|
||||
var rect = background.gameObject.GetComponent<RectTransform>();
|
||||
rect.localPosition = legend.context.center;
|
||||
rect.sizeDelta = new Vector2(legend.context.width, legend.context.height);
|
||||
ChartHelper.SetBackground(background, style);
|
||||
}
|
||||
|
||||
public static void ResetItemPosition(Legend legend, Vector3 chartPos, float chartWidth, float chartHeight)
|
||||
{
|
||||
legend.location.UpdateRuntimeData(chartWidth, chartHeight);
|
||||
@@ -122,8 +136,19 @@ namespace XCharts.Runtime
|
||||
startY = chartPos.y + legendRuntimeHeight + legend.location.runtimeBottom;
|
||||
break;
|
||||
}
|
||||
if (!legend.padding.show)
|
||||
{
|
||||
legend.context.center = new Vector2(startX + legend.context.width / 2, startY - legend.context.height / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
legend.context.center = new Vector2(startX + legend.context.width / 2 - legend.padding.left,
|
||||
startY - legend.context.height / 2 + legend.padding.top);
|
||||
}
|
||||
|
||||
if (isVertical) SetVerticalItemPosition(legend, legendMaxHeight, startX, startY);
|
||||
else SetHorizonalItemPosition(legend, legendMaxWidth, startX, startY);
|
||||
SetLegendBackground(legend, legend.background);
|
||||
}
|
||||
|
||||
private static void SetVerticalItemPosition(Legend legend, float legendMaxHeight, float startX, float startY)
|
||||
@@ -214,6 +239,11 @@ namespace XCharts.Runtime
|
||||
legend.context.height = realHeight > 0 ? realHeight : height;
|
||||
legend.context.width = realWidth + width;
|
||||
}
|
||||
if (legend.padding.show)
|
||||
{
|
||||
legend.context.width += legend.padding.left + legend.padding.right;
|
||||
legend.context.height += legend.padding.top + legend.padding.bottom;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsBeyondWidth(Legend legend, float maxWidth)
|
||||
|
||||
Reference in New Issue
Block a user