Skip to content

Commit c78e854

Browse files
committed
chore: add avalonia Label demo.
1 parent 528f3ea commit c78e854

File tree

9 files changed

+164
-22
lines changed

9 files changed

+164
-22
lines changed

src/Avalonia/HandyControlDemo_Avalonia/HandyControlDemo_Avalonia.csproj

+4-13
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
<AssemblyName>HandyControlDemo</AssemblyName>
1212
<RootNamespace>HandyControlDemo</RootNamespace>
1313
</PropertyGroup>
14+
1415
<ItemGroup>
1516
<None Remove="Data\DemoInfo.json" />
1617
<None Remove="Resources\Img\cloud.png" />
1718
<None Remove="Resources\Img\icon.ico" />
1819
</ItemGroup>
20+
1921
<ItemGroup>
22+
<EmbeddedResource Include="Data\DemoInfo.json" />
23+
<AvaloniaResource Include="Resources\Img\cloud.png" />
2024
<AvaloniaResource Include="Resources\Img\icon.ico" />
2125
</ItemGroup>
2226

@@ -31,14 +35,6 @@
3135
<ProjectReference Include="..\HandyControl_Avalonia\HandyControl_Avalonia.csproj" />
3236
</ItemGroup>
3337

34-
<ItemGroup>
35-
<AvaloniaResource Include="Resources\Img\cloud.png" />
36-
</ItemGroup>
37-
38-
<ItemGroup>
39-
<EmbeddedResource Include="Data\DemoInfo.json" />
40-
</ItemGroup>
41-
4238
<ItemGroup>
4339
<Compile Update="Lang.Designer.cs">
4440
<DesignTime>True</DesignTime>
@@ -53,9 +49,4 @@
5349
<LastGenOutput>Lang.Designer.cs</LastGenOutput>
5450
</EmbeddedResource>
5551
</ItemGroup>
56-
57-
<ItemGroup>
58-
<None Remove="Resources\Themes\Basic\Geometries.xaml" />
59-
<AvaloniaXaml Include="Resources\Themes\Basic\Geometries.xaml" />
60-
</ItemGroup>
6152
</Project>

src/Avalonia/HandyControlDemo_Avalonia/Resources/Themes/Basic/Basic.axaml

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:converter="clr-namespace:HandyControlDemo.Tools.Converter">
4+
<converter:StringRepeatConverter x:Key="StringRepeatConverter" />
5+
</ResourceDictionary>

src/Avalonia/HandyControlDemo_Avalonia/Resources/Themes/Basic/Geometries.xaml src/Avalonia/HandyControlDemo_Avalonia/Resources/Themes/Basic/Geometries.axaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ResourceDictionary xmlns="https://github.com/avaloniaui"
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
33

44
<Geometry x:Key="NewGeometry">M512 0h1216a512 512 0 1 1 0 1024H512A512 512 0 1 1 512 0zM420.16 311.04V768h74.88V433.92h2.56l228.48 334.08h72.96V311.04h-75.52v329.6h-2.56l-225.92-329.6h-74.88z m468.48 0V768h340.48v-64h-265.6V565.76h239.36v-64h-239.36V375.04h254.72v-64h-329.6z m369.28 0l131.2 456.96h80l89.6-343.68h2.56l88.96 343.68h79.36l131.84-456.96h-84.48l-85.76 347.52h-2.56l-90.24-347.52h-77.44l-90.24 347.52h-2.56l-85.76-347.52h-84.48z</Geometry>

src/Avalonia/HandyControlDemo_Avalonia/Resources/Themes/Theme.axaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<Styles.Resources>
44
<ResourceDictionary>
55
<ResourceDictionary.MergedDictionaries>
6-
<MergeResourceInclude Source="Basic/Basic.axaml" />
6+
<MergeResourceInclude Source="/Resources/Themes/Basic/Brushes.axaml" />
7+
<MergeResourceInclude Source="/Resources/Themes/Basic/Geometries.axaml" />
8+
<MergeResourceInclude Source="/Resources/Themes/Basic/Converters.axaml" />
79
</ResourceDictionary.MergedDictionaries>
810
</ResourceDictionary>
911
</Styles.Resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Text;
4+
using Avalonia.Data.Converters;
5+
6+
namespace HandyControlDemo.Tools.Converter;
7+
8+
public class StringRepeatConverter : IValueConverter
9+
{
10+
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
11+
{
12+
if (value is not string strValue)
13+
{
14+
return string.Empty;
15+
}
16+
17+
var builder = new StringBuilder();
18+
int num;
19+
20+
switch (parameter)
21+
{
22+
case string numStr:
23+
{
24+
if (!int.TryParse(numStr, out num))
25+
{
26+
return strValue;
27+
}
28+
29+
break;
30+
}
31+
case int intValue:
32+
num = intValue;
33+
break;
34+
default:
35+
return strValue;
36+
}
37+
38+
for (int i = 0; i < num; i++)
39+
{
40+
builder.Append(strValue);
41+
}
42+
43+
return builder.ToString();
44+
}
45+
46+
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
47+
{
48+
throw new NotSupportedException();
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:hc="https://handyorg.github.io/handycontrol"
4+
x:Class="HandyControlDemo.UserControl.LabelDemo">
5+
<hc:UniformSpacingPanel Margin="32"
6+
Spacing="32"
7+
ChildWrapping="Wrap">
8+
<hc:UniformSpacingPanel Spacing="5"
9+
Orientation="Vertical">
10+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle" />
11+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
12+
Theme="{StaticResource LabelDanger}" />
13+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
14+
Theme="{StaticResource LabelInfo}" />
15+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
16+
Theme="{StaticResource LabelPrimary}" />
17+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
18+
Theme="{StaticResource LabelSuccess}" />
19+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
20+
Theme="{StaticResource LabelWarning}" />
21+
</hc:UniformSpacingPanel>
22+
<hc:UniformSpacingPanel Spacing="5"
23+
Orientation="Vertical">
24+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
25+
Theme="{StaticResource LabelDefault.Small}" />
26+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
27+
Theme="{StaticResource LabelDanger.Small}" />
28+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
29+
Theme="{StaticResource LabelInfo.Small}" />
30+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
31+
Theme="{StaticResource LabelPrimary.Small}" />
32+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
33+
Theme="{StaticResource LabelSuccess.Small}" />
34+
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
35+
Theme="{StaticResource LabelWarning.Small}" />
36+
</hc:UniformSpacingPanel>
37+
</hc:UniformSpacingPanel>
38+
</UserControl>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace HandyControlDemo.UserControl;
2+
3+
public partial class LabelDemo : Avalonia.Controls.UserControl
4+
{
5+
public LabelDemo()
6+
{
7+
InitializeComponent();
8+
}
9+
}

src/Avalonia/HandyControl_Avalonia/Themes/Styles/Label.axaml

+54
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,92 @@
5757
BasedOn="{StaticResource LabelDefault}"
5858
TargetType="Label" />
5959

60+
<ControlTheme x:Key="LabelDefault.Small"
61+
BasedOn="{StaticResource LabelDefault}"
62+
TargetType="Label">
63+
<Setter Property="Height"
64+
Value="20" />
65+
<Setter Property="Padding"
66+
Value="6,0" />
67+
</ControlTheme>
68+
6069
<ControlTheme x:Key="LabelPrimary"
6170
BasedOn="{StaticResource LabelBaseStyle}"
6271
TargetType="Label">
6372
<Setter Property="Background"
6473
Value="{DynamicResource PrimaryBrush}" />
6574
</ControlTheme>
6675

76+
<ControlTheme x:Key="LabelPrimary.Small"
77+
BasedOn="{StaticResource LabelPrimary}"
78+
TargetType="Label">
79+
<Setter Property="Height"
80+
Value="20" />
81+
<Setter Property="Padding"
82+
Value="6,0" />
83+
</ControlTheme>
84+
6785
<ControlTheme x:Key="LabelSuccess"
6886
BasedOn="{StaticResource LabelBaseStyle}"
6987
TargetType="Label">
7088
<Setter Property="Background"
7189
Value="{DynamicResource SuccessBrush}" />
7290
</ControlTheme>
7391

92+
<ControlTheme x:Key="LabelSuccess.Small"
93+
BasedOn="{StaticResource LabelSuccess}"
94+
TargetType="Label">
95+
<Setter Property="Height"
96+
Value="20" />
97+
<Setter Property="Padding"
98+
Value="6,0" />
99+
</ControlTheme>
100+
74101
<ControlTheme x:Key="LabelInfo"
75102
BasedOn="{StaticResource LabelBaseStyle}"
76103
TargetType="Label">
77104
<Setter Property="Background"
78105
Value="{DynamicResource InfoBrush}" />
79106
</ControlTheme>
80107

108+
<ControlTheme x:Key="LabelInfo.Small"
109+
BasedOn="{StaticResource LabelInfo}"
110+
TargetType="Label">
111+
<Setter Property="Height"
112+
Value="20" />
113+
<Setter Property="Padding"
114+
Value="6,0" />
115+
</ControlTheme>
116+
81117
<ControlTheme x:Key="LabelWarning"
82118
BasedOn="{StaticResource LabelBaseStyle}"
83119
TargetType="Label">
84120
<Setter Property="Background"
85121
Value="{DynamicResource WarningBrush}" />
86122
</ControlTheme>
87123

124+
<ControlTheme x:Key="LabelWarning.Small"
125+
BasedOn="{StaticResource LabelWarning}"
126+
TargetType="Label">
127+
<Setter Property="Height"
128+
Value="20" />
129+
<Setter Property="Padding"
130+
Value="6,0" />
131+
</ControlTheme>
132+
88133
<ControlTheme x:Key="LabelDanger"
89134
BasedOn="{StaticResource LabelBaseStyle}"
90135
TargetType="Label">
91136
<Setter Property="Background"
92137
Value="{DynamicResource DangerBrush}" />
93138
</ControlTheme>
139+
140+
<ControlTheme x:Key="LabelDanger.Small"
141+
BasedOn="{StaticResource LabelDanger}"
142+
TargetType="Label">
143+
<Setter Property="Height"
144+
Value="20" />
145+
<Setter Property="Padding"
146+
Value="6,0" />
147+
</ControlTheme>
94148
</ResourceDictionary>

0 commit comments

Comments
 (0)