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 2c7938a commit 4e1cdfc
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
<ItemGroup>
<None Remove="Resource\Lang\en-us.json" />
<None Remove="Resource\Lang\zh-cn.json" />
<None Remove="Resource\svg1.svg" />
<None Remove="Resource\svg1_1.svg" />
</ItemGroup>

<ItemGroup>
<AvaloniaResource Include="Resource\svg1.svg" />
<AvaloniaResource Include="Resource\svg1_1.svg" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -90,7 +97,7 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<None Update="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
HorizontalAlignment="Right"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Value, StringFormat={}{0:0.00} %}" />
Text="{Binding Text}" />
</Panel>
<ProgressBar
Height="{Binding Height}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
HorizontalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Value, StringFormat={}{0:0.00} %}" />
Text="{Binding Text}" />
</StackPanel>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
VerticalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Value, StringFormat={}{0:0.00} %}" />
Text="{Binding Text}" />
</Panel>
</StackPanel>
</Border>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<UserControl
x:Class="ColorDesktop.MonitorPlugin.Controls.ProgressBar5Control"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ColorDesktop.MonitorPlugin.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:svg="clr-namespace:ColorDesktop.CoreLib.View.Svg;assembly=ColorDesktop.CoreLib"
xmlns:vm="clr-namespace:ColorDesktop.MonitorPlugin.Models"
d:DesignHeight="450"
d:DesignWidth="800"
x:DataType="vm:ProgressBar5Model"
mc:Ignorable="d">
<Border Background="{Binding BackColor}" CornerRadius="5">
<StackPanel Margin="{Binding BorderSize}">
<TextBlock
HorizontalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Name}" />
<Panel Margin="0,0,0,-10">
<svg:SvgControl
Width="{Binding Width}"
Height="{Binding Height}"
Path="/Resource/svg1.svg"
Stroke="{Binding BackColor1}" />
<svg:SvgControl
Width="{Binding Width}"
Height="{Binding Height}"
Fill="{Binding BarColor}"
Path="/Resource/svg1_1.svg"
RenderTransform="{Binding Pointer1}"
Stroke="{Binding BarColor}" />
</Panel>
<TextBlock
HorizontalAlignment="Center"
FontSize="{Binding FontSize}"
Foreground="{Binding TextColor}"
Text="{Binding Text}" />
</StackPanel>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;

namespace ColorDesktop.MonitorPlugin.Controls;

public partial class ProgressBar5Control : UserControl
{
public ProgressBar5Control()
{
InitializeComponent();
}
}
23 changes: 11 additions & 12 deletions src/Plugins/ColorDesktop.MonitorPlugin/Models/ProgressBar3Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ public partial class ProgressBar3Model : ObservableObject, IUpdate
[ObservableProperty]
private Thickness _borderSize;

[ObservableProperty]
private double _min;
[ObservableProperty]
private double _max;
[ObservableProperty]
private double _value;

[ObservableProperty]
private string _name;

[ObservableProperty]
private string _text;

[ObservableProperty]
private double _progress;

Expand All @@ -60,8 +59,8 @@ public void Reload(MonitorItemModel model)
Height = item.Height <= 0 ? double.NaN : item.Height;
BorderSize = new(item.BorderSize);

Min = item.Min;
Max = item.Max;
_min = item.Min;
_max = item.Max;
Name = item.Name;
}

Expand All @@ -70,16 +69,16 @@ public void Update(MonitorItemModel model)
switch (model.ValueType)
{
case ValueType.Now:
Value = model.Value;
Progress = (model.Value - Min) / (Max - Min) * 100;
Progress = (model.Value - _min) / (_max - _min) * 100;
Text = model.Format;
break;
case ValueType.Max:
Value = model.MaxValue;
Progress = (model.MaxValue - Min) / (Max - Min) * 100;
Progress = (model.MaxValue - _min) / (_max - _min) * 100;
Text = model.FormatMax;
break;
case ValueType.Min:
Value = model.MinValue;
Progress = (model.MinValue - Min) / (Max - Min) * 100;
Progress = (model.MinValue - _min) / (_max - _min) * 100;
Text = model.FormatMin;
break;
}
}
Expand Down
97 changes: 97 additions & 0 deletions src/Plugins/ColorDesktop.MonitorPlugin/Models/ProgressBar5Model.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;

namespace ColorDesktop.MonitorPlugin.Models;

public partial class ProgressBar5Model : ObservableObject, IUpdate
{
[ObservableProperty]
private IBrush _backColor;
[ObservableProperty]
private IBrush _backColor1;
[ObservableProperty]
private IBrush _textColor;
[ObservableProperty]
private IBrush _barColor;
[ObservableProperty]
private int _fontSize;
[ObservableProperty]
private double _width;
[ObservableProperty]
private double _height;
[ObservableProperty]
private Thickness _borderSize;

private double _min;
private double _max;

[ObservableProperty]
private string _name;

[ObservableProperty]
private string _text;

[ObservableProperty]
private RotateTransform _pointer1 = new();

public ProgressBar5Model(MonitorItemModel model)
{
Reload(model);
}

public void Reload(MonitorItemModel model)
{
var item = model.Obj;
FontSize = item.FontSize;
BackColor = Brush.Parse(item.Color1 ?? "#FFFFFF");
TextColor = Brush.Parse(item.Color2 ?? "#FFFFFF");
BarColor = Brush.Parse(item.Color3 ?? "#FFFFFF");
BackColor1 = Brush.Parse(item.Color4 ?? "#FFFFFF");
Width = item.Width <= 0 ? double.NaN : item.Width;
Height = item.Height <= 0 ? double.NaN : item.Height;
BorderSize = new(item.BorderSize);

_min = item.Min;
_max = item.Max;
Name = item.Name;
}

public void Update(MonitorItemModel model)
{
switch (model.ValueType)
{
case ValueType.Now:
var angle = (model.Value - _min) / (_max - _min) * 270;
if (Pointer1.Angle != angle)
{
Pointer1.Angle = angle;
}
Text = model.Format;
break;
case ValueType.Max:
angle = (model.MaxValue - _min) / (_max - _min) * 270;
if (Pointer1.Angle != angle)
{
Pointer1.Angle = angle;
}
Text = model.FormatMax;
break;
case ValueType.Min:
angle = (model.MinValue - _min) / (_max - _min) * 270;
if (Pointer1.Angle != angle)
{
Pointer1.Angle = angle;
}
Text = model.FormatMin;
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public partial class ProgressBarModel : ObservableObject, IUpdate
[ObservableProperty]
private string _name;

[ObservableProperty]
private string _text;

public ProgressBarModel(MonitorItemModel model)
{
Reload(model);
Expand Down Expand Up @@ -66,12 +69,15 @@ public void Update(MonitorItemModel model)
{
case ValueType.Now:
Value = model.Value;
Text = model.Format;
break;
case ValueType.Max:
Value = model.MaxValue;
Text = model.FormatMax;
break;
case ValueType.Min:
Value = model.MinValue;
Text = model.FormatMin;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ColorDesktop.MonitorPlugin;

public enum MonitorDisplayType
{
Text, ProgressBar1, ProgressBar2, ProgressBar3, ProgressBar4
Text, ProgressBar1, ProgressBar2, ProgressBar3, ProgressBar4, ProgressBar5
}

public enum PanelType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void Update()
LangApi.GetLang("MonitorInstanceSetting.Text33"),
LangApi.GetLang("MonitorInstanceSetting.Text34"),
LangApi.GetLang("MonitorInstanceSetting.Text40"),
LangApi.GetLang("MonitorInstanceSetting.Text43")
LangApi.GetLang("MonitorInstanceSetting.Text43"),
LangApi.GetLang("MonitorInstanceSetting.Text44")
];

public string[] ValueTypeName { get; init; } =
Expand Down Expand Up @@ -566,9 +567,10 @@ private void DisplaySetting(MonitorDisplayType value)
case MonitorDisplayType.ProgressBar2:
case MonitorDisplayType.ProgressBar3:
case MonitorDisplayType.ProgressBar4:
case MonitorDisplayType.ProgressBar5:
DisplaySize = true;
DisplayFontSize = true;
DisplayFmt = false;
DisplayFmt = true;
DisplayColor = true;
DisplayBorder = true;
DisplayBarColor = true;
Expand Down
15 changes: 14 additions & 1 deletion src/Plugins/ColorDesktop.MonitorPlugin/MonitorItemControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="clr-namespace:ColorDesktop.Api;assembly=ColorDesktop.Api"
xmlns:local="clr-namespace:ColorDesktop.MonitorPlugin"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
x:DataType="local:MonitorItemModel"
mc:Ignorable="d">
<Decorator Name="View1" Margin="{Binding Margin}" />
<Panel>
<Decorator
Name="View1"
Margin="{Binding Margin}"
IsVisible="{Binding HaveSensor}" />
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Black"
Foreground="White"
IsVisible="{Binding !HaveSensor}"
Text="{lang:Localize MonitorInstanceSetting.Text45}" />
</Panel>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,13 @@ private void InitView()
DataContext = new ProgressBar3Model(model)
};
}
else if (model.MonitorDisplay == MonitorDisplayType.ProgressBar5
&& View1.Child is not ProgressBar5Control)
{
View1.Child = new ProgressBar5Control()
{
DataContext = new ProgressBar5Model(model)
};
}
}
}
18 changes: 6 additions & 12 deletions src/Plugins/ColorDesktop.MonitorPlugin/MonitorItemModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ namespace ColorDesktop.MonitorPlugin;

public partial class MonitorItemModel : ObservableObject
{
[ObservableProperty]
private float _value = float.NaN;
[ObservableProperty]
private float _minValue = float.NaN;
[ObservableProperty]
private float _maxValue = float.NaN;
public float Value = float.NaN;
public float MinValue = float.NaN;
public float MaxValue = float.NaN;

[ObservableProperty]
private string _format;
[ObservableProperty]
private string _formatMin;
[ObservableProperty]
private string _formatMax;
public string Format;
public string FormatMin;
public string FormatMax;

[ObservableProperty]
private Thickness _margin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@
"MonitorInstanceSetting.Text41": "最大值",
"MonitorInstanceSetting.Text42": "最小值",
"MonitorInstanceSetting.Text43": "圆形表盘2",
"MonitorInstanceSetting.Text44": "指针表盘1",
"MonitorInstanceSetting.Text45": "没有找到传感器",
}
Loading

0 comments on commit 4e1cdfc

Please sign in to comment.