增加UISlider扩展组件

This commit is contained in:
monitor1394
2024-12-25 10:06:53 +08:00
parent 5d24580725
commit 074c1a3992
3 changed files with 90 additions and 2 deletions

View File

@@ -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);
}
/// <summary>
/// 属性变更时更新textAnchor,minAnchor,maxAnchor,pivot
/// </summary>

View File

@@ -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;

View File

@@ -11,7 +11,7 @@ namespace XCharts.Runtime
/// </summary>
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);
}