Skip to content

Commit

Permalink
up 调整样式
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Oct 18, 2024
1 parent 4e1cdfc commit 720d927
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
HorizontalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Name}" />
Text="{Binding Name}"
TextAlignment="Center" />
<local:CircularProgressBar
Width="{Binding Width}"
Height="{Binding Height}"
Expand All @@ -29,7 +30,8 @@
HorizontalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Text}" />
Text="{Binding Text}"
TextAlignment="Center" />
</StackPanel>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,22 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang

public override void Render(DrawingContext context)
{
double dx = 0;
double dy = 0;
var size = Math.Min(Bounds.Width, Bounds.Height);
if (Bounds.Width > Bounds.Height)
{
dx = (Bounds.Width - Bounds.Height) / 2;
}
else if (Bounds.Height > Bounds.Width)
{
dy = (Bounds.Height - Bounds.Width) / 2;
}
var radius = size / 2;
var center = new Point(size / 2, size / 2);
var center = new Point(dx + size / 2, dy + size / 2);

// Draw background circle
context.FillRectangle(BackgroundColor, new Rect(0, 0, size, size), (float)size);
context.FillRectangle(BackgroundColor, new Rect(dx, dy, size, size), (float)size);

// Draw foreground arc
var angle = 360 * (Value / 100);
var startAngle = -90;
var endAngle = startAngle + angle;
Expand All @@ -83,5 +91,5 @@ public override void Render(DrawingContext context)
context.DrawGeometry(ForegroundColor, new Pen(), pathGeometry);
}

private double DegreesToRadians(double degrees) => degrees * Math.PI / 180;
private static double DegreesToRadians(double degrees) => degrees * Math.PI / 180;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
HorizontalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Name}" />
Text="{Binding Name}"
TextAlignment="Center" />
<Panel>
<local:Circular1ProgressBar
Width="{Binding Width}"
Expand All @@ -30,7 +31,8 @@
VerticalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Text}" />
Text="{Binding Text}"
TextAlignment="Center" />
</Panel>
</StackPanel>
</Border>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,33 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang

public override void Render(DrawingContext context)
{
base.Render(context);
double dx = 0;
double dy = 0;
if (Bounds.Width > Bounds.Height)
{
dx = (Bounds.Width - Bounds.Height) / 2;
}
else if (Bounds.Height > Bounds.Width)
{
dy = (Bounds.Height - Bounds.Width) / 2;
}

// ¶¨ÒåÔ²»·µÄ²ÎÊý
double centerX = Bounds.Width / 2;
double centerY = Bounds.Height / 2;
double radius = Math.Min(Bounds.Width, Bounds.Height) / 2 - 5;
double centerX = dx + Bounds.Width / 2;
double centerY = dy + Bounds.Height / 2;
double size = Math.Min(Bounds.Width, Bounds.Height);
double radius = size / 2 - size / 10;

var pen = new Pen(ForegroundColor, 5);
var pen1 = new Pen(BackgroundColor, 10);

context.DrawGeometry(null, pen1, Convert(centerX, centerY, 100, radius));

context.DrawGeometry(null, pen, Convert(centerX, centerY, Value, radius));
}

private double DegreesToRadians(double degrees) => degrees * Math.PI / 180;

public Geometry Convert(double centerX, double centerY, double value, double radius)
public static Geometry Convert(double centerX, double centerY, double value, double radius)
{
double PIch2 = 2 * Math.PI;
double PIch2 = Math.Tau;

double angle = (double)value / 100 * PIch2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
HorizontalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Name}" />
Text="{Binding Name}"
TextAlignment="Center" />
<Panel Margin="0,0,0,-10">
<svg:SvgControl
Width="{Binding Width}"
Expand All @@ -36,7 +37,8 @@
HorizontalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Text}" />
Text="{Binding Text}"
TextAlignment="Center" />
</StackPanel>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
"MonitorInstanceSetting.Text42": "最小值",
"MonitorInstanceSetting.Text43": "圆形表盘2",
"MonitorInstanceSetting.Text44": "指针表盘1",
"MonitorInstanceSetting.Text45": "没有找到传感器",
"MonitorInstanceSetting.Text45": "没有找到传感器"
}

0 comments on commit 720d927

Please sign in to comment.