Files
XCharts/Runtime/Internal/Utilities/UIHelper.cs

53 lines
2.3 KiB
C#
Raw Normal View History

2023-03-20 21:56:56 +08:00
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XUGL;
namespace XCharts.Runtime
{
/// <summary>
/// UI帮助类。
/// </summary>
public static class UIHelper
{
internal static void DrawBackground(VertexHelper vh, UIComponent component)
{
2024-01-16 22:29:15 +08:00
var background = component.background;
if (!background.show)
return;
if (background.image != null)
return;
var backgroundColor = component.theme.GetBackgroundColor(background);
var borderWidth = background.borderStyle.GetRuntimeBorderWidth();
var borderColor = background.borderStyle.GetRuntimeBorderColor();
var cornerRadius = background.borderStyle.GetRuntimeCornerRadius();
UGL.DrawRoundRectangleWithBorder(vh, component.graphRect, backgroundColor, backgroundColor, cornerRadius,
borderWidth, borderColor);
2023-03-20 21:56:56 +08:00
}
2024-12-04 08:19:40 +08:00
internal static void InitBackground(UIComponent component)
2023-03-20 21:56:56 +08:00
{
2024-12-04 08:19:40 +08:00
if (component.background.show == false ||
(component.background.image == null && ChartHelper.IsClearColor(component.background.imageColor)))
2023-03-20 21:56:56 +08:00
{
2024-12-04 08:19:40 +08:00
ChartHelper.DestoryGameObject(component.transform, "Background");
2023-03-20 21:56:56 +08:00
return;
}
2024-12-04 08:19:40 +08:00
var sizeDelta = component.background.imageWidth > 0 && component.background.imageHeight > 0 ?
new Vector2(component.background.imageWidth, component.background.imageHeight) :
component.graphSizeDelta;
var backgroundObj = ChartHelper.AddObject("Background", component.transform, component.graphMinAnchor,
component.graphMaxAnchor, component.graphPivot, sizeDelta);
backgroundObj.hideFlags = component.chartHideFlags;
2023-03-20 21:56:56 +08:00
var backgroundImage = ChartHelper.EnsureComponent<Image>(backgroundObj);
2024-12-04 08:19:40 +08:00
ChartHelper.UpdateRectTransform(backgroundObj, component.graphMinAnchor,
component.graphMaxAnchor, component.graphPivot, sizeDelta);
ChartHelper.SetBackground(backgroundImage, component.background);
2023-03-20 21:56:56 +08:00
backgroundObj.transform.SetSiblingIndex(0);
2024-12-04 08:19:40 +08:00
backgroundObj.SetActive(component.background.show && component.background.image != null);
2023-03-20 21:56:56 +08:00
}
}
}