From 074c1a3992e7c47b53a47ec753ba107ed32bab5c Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 25 Dec 2024 10:06:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`UISlider`=E6=89=A9=E5=B1=95?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Component/Child/Location.cs | 63 +++++++++++++++++++++++ Runtime/Internal/Utilities/ChartHelper.cs | 16 ++++++ Runtime/Internal/Utilities/UIHelper.cs | 13 ++++- 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/Runtime/Component/Child/Location.cs b/Runtime/Component/Child/Location.cs index 0d49d6c7..ea010f2c 100644 --- a/Runtime/Component/Child/Location.cs +++ b/Runtime/Component/Child/Location.cs @@ -349,6 +349,69 @@ namespace XCharts.Runtime } } + public Rect GetRect(float graphX, float graphY, float graphWidth, float graphHeight, float rectWidth, float rectHeight) + { + UpdateRuntimeData(graphWidth, graphWidth); + + float x, y, width, height; + + width = rectWidth == 0 ? graphWidth - runtimeLeft - runtimeRight : rectWidth; + height = rectHeight == 0 ? graphHeight - runtimeBottom - runtimeTop : rectHeight; + + switch (align) + { + case Align.BottomCenter: + x = graphX + runtimeLeft + (graphWidth - runtimeLeft - runtimeRight - width) / 2; + y = graphY + runtimeBottom; + break; + + case Align.BottomLeft: + x = graphX + runtimeLeft; + y = graphY + runtimeBottom; + break; + + case Align.BottomRight: + x = graphX + graphWidth - runtimeRight - width; + y = graphY + runtimeBottom; + break; + + case Align.Center: + x = graphX + runtimeLeft + (graphWidth - runtimeLeft - runtimeRight - width) / 2; + y = graphY + runtimeBottom + (graphHeight - runtimeBottom - runtimeTop - height) / 2; + break; + + case Align.CenterLeft: + x = graphX + runtimeLeft; + y = graphY + runtimeBottom + (graphHeight - runtimeBottom - runtimeTop - height) / 2; + break; + + case Align.CenterRight: + x = graphX + graphWidth - runtimeRight - width; + y = graphY + runtimeBottom + (graphHeight - runtimeBottom - runtimeTop - height) / 2; + break; + + case Align.TopCenter: + x = graphX + runtimeLeft + (graphWidth - runtimeLeft - runtimeRight - width) / 2; + y = graphY + graphHeight - runtimeTop - height; + break; + + case Align.TopLeft: + x = graphX + runtimeLeft; + y = graphY + graphHeight - runtimeTop - height; + break; + + case Align.TopRight: + x = graphX + graphWidth - runtimeRight - width; + y = graphY + graphHeight - runtimeTop - height; + break; + + default: + return new Rect(0, 0, 0, 0); + } + return new Rect(x, y, width, height); + } + + /// /// 属性变更时更新textAnchor,minAnchor,maxAnchor,pivot /// diff --git a/Runtime/Internal/Utilities/ChartHelper.cs b/Runtime/Internal/Utilities/ChartHelper.cs index dc138d23..c0bef4fc 100644 --- a/Runtime/Internal/Utilities/ChartHelper.cs +++ b/Runtime/Internal/Utilities/ChartHelper.cs @@ -791,6 +791,14 @@ namespace XCharts.Runtime return mod == 0 ? value : (value < 0 ? rate : rate + 1) * ceilRate; } + public static float GetMaxCeilRate(float value, float ceilRate) + { + if (ceilRate == 0) return value; + var mod = value % ceilRate; + int rate = (int)(value / ceilRate); + return mod == 0 ? value : (value < 0 ? rate : rate + 1) * ceilRate; + } + public static double GetMinCeilRate(double value, double ceilRate) { if (ceilRate == 0) return value; @@ -799,6 +807,14 @@ namespace XCharts.Runtime return mod == 0 ? value : (value < 0 ? rate - 1 : rate) * ceilRate; } + public static float GetMinCeilRate(float value, float ceilRate) + { + if (ceilRate == 0) return value; + var mod = value % ceilRate; + int rate = (int)(value / ceilRate); + return mod == 0 ? value : (value < 0 ? rate - 1 : rate) * ceilRate; + } + public static double GetMinDivisibleValue(double min, double ceilRate) { if (min == 0) return 0; diff --git a/Runtime/Internal/Utilities/UIHelper.cs b/Runtime/Internal/Utilities/UIHelper.cs index 781fd944..5fac7f8d 100644 --- a/Runtime/Internal/Utilities/UIHelper.cs +++ b/Runtime/Internal/Utilities/UIHelper.cs @@ -11,7 +11,7 @@ namespace XCharts.Runtime /// public static class UIHelper { - internal static void DrawBackground(VertexHelper vh, UIComponent component) + public static void DrawBackground(VertexHelper vh, UIComponent component) { var background = component.background; var rect = component.graphRect; @@ -34,10 +34,19 @@ namespace XCharts.Runtime if (background.image != null) return; var backgroundColor = component.theme.GetBackgroundColor(background); + DrawBackground(vh, background, backgroundColor); + } + + public static void DrawBackground(VertexHelper vh, Background background, Color32 color) + { + if (!background.show) + return; + if (background.image != null) + return; var borderWidth = background.borderStyle.GetRuntimeBorderWidth(); var borderColor = background.borderStyle.GetRuntimeBorderColor(); var cornerRadius = background.borderStyle.GetRuntimeCornerRadius(); - UGL.DrawRoundRectangleWithBorder(vh, background.rect, backgroundColor, backgroundColor, cornerRadius, + UGL.DrawRoundRectangleWithBorder(vh, background.rect, color, color, cornerRadius, borderWidth, borderColor); }