Skip to content

Commit

Permalink
chore: add avalonia Label demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Dec 15, 2024
1 parent 528f3ea commit c78e854
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
<AssemblyName>HandyControlDemo</AssemblyName>
<RootNamespace>HandyControlDemo</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Remove="Data\DemoInfo.json" />
<None Remove="Resources\Img\cloud.png" />
<None Remove="Resources\Img\icon.ico" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Data\DemoInfo.json" />
<AvaloniaResource Include="Resources\Img\cloud.png" />
<AvaloniaResource Include="Resources\Img\icon.ico" />
</ItemGroup>

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

<ItemGroup>
<AvaloniaResource Include="Resources\Img\cloud.png" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Data\DemoInfo.json" />
</ItemGroup>

<ItemGroup>
<Compile Update="Lang.Designer.cs">
<DesignTime>True</DesignTime>
Expand All @@ -53,9 +49,4 @@
<LastGenOutput>Lang.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<None Remove="Resources\Themes\Basic\Geometries.xaml" />
<AvaloniaXaml Include="Resources\Themes\Basic\Geometries.xaml" />
</ItemGroup>
</Project>

This file was deleted.

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

<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<Styles.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<MergeResourceInclude Source="Basic/Basic.axaml" />
<MergeResourceInclude Source="/Resources/Themes/Basic/Brushes.axaml" />
<MergeResourceInclude Source="/Resources/Themes/Basic/Geometries.axaml" />
<MergeResourceInclude Source="/Resources/Themes/Basic/Converters.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Styles.Resources>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Globalization;
using System.Text;
using Avalonia.Data.Converters;

namespace HandyControlDemo.Tools.Converter;

public class StringRepeatConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not string strValue)
{
return string.Empty;
}

var builder = new StringBuilder();
int num;

switch (parameter)
{
case string numStr:
{
if (!int.TryParse(numStr, out num))
{
return strValue;
}

break;
}
case int intValue:
num = intValue;
break;
default:
return strValue;
}

for (int i = 0; i < num; i++)
{
builder.Append(strValue);
}

return builder.ToString();
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
x:Class="HandyControlDemo.UserControl.LabelDemo">
<hc:UniformSpacingPanel Margin="32"
Spacing="32"
ChildWrapping="Wrap">
<hc:UniformSpacingPanel Spacing="5"
Orientation="Vertical">
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelDanger}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelInfo}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelPrimary}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelSuccess}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelWarning}" />
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="5"
Orientation="Vertical">
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelDefault.Small}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelDanger.Small}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelInfo.Small}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelPrimary.Small}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelSuccess.Small}" />
<Label Content="TitleTitleTitleTitleTitleTitleTitleTitleTitleTitle"
Theme="{StaticResource LabelWarning.Small}" />
</hc:UniformSpacingPanel>
</hc:UniformSpacingPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace HandyControlDemo.UserControl;

public partial class LabelDemo : Avalonia.Controls.UserControl
{
public LabelDemo()
{
InitializeComponent();
}
}
54 changes: 54 additions & 0 deletions src/Avalonia/HandyControl_Avalonia/Themes/Styles/Label.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,92 @@
BasedOn="{StaticResource LabelDefault}"
TargetType="Label" />

<ControlTheme x:Key="LabelDefault.Small"
BasedOn="{StaticResource LabelDefault}"
TargetType="Label">
<Setter Property="Height"
Value="20" />
<Setter Property="Padding"
Value="6,0" />
</ControlTheme>

<ControlTheme x:Key="LabelPrimary"
BasedOn="{StaticResource LabelBaseStyle}"
TargetType="Label">
<Setter Property="Background"
Value="{DynamicResource PrimaryBrush}" />
</ControlTheme>

<ControlTheme x:Key="LabelPrimary.Small"
BasedOn="{StaticResource LabelPrimary}"
TargetType="Label">
<Setter Property="Height"
Value="20" />
<Setter Property="Padding"
Value="6,0" />
</ControlTheme>

<ControlTheme x:Key="LabelSuccess"
BasedOn="{StaticResource LabelBaseStyle}"
TargetType="Label">
<Setter Property="Background"
Value="{DynamicResource SuccessBrush}" />
</ControlTheme>

<ControlTheme x:Key="LabelSuccess.Small"
BasedOn="{StaticResource LabelSuccess}"
TargetType="Label">
<Setter Property="Height"
Value="20" />
<Setter Property="Padding"
Value="6,0" />
</ControlTheme>

<ControlTheme x:Key="LabelInfo"
BasedOn="{StaticResource LabelBaseStyle}"
TargetType="Label">
<Setter Property="Background"
Value="{DynamicResource InfoBrush}" />
</ControlTheme>

<ControlTheme x:Key="LabelInfo.Small"
BasedOn="{StaticResource LabelInfo}"
TargetType="Label">
<Setter Property="Height"
Value="20" />
<Setter Property="Padding"
Value="6,0" />
</ControlTheme>

<ControlTheme x:Key="LabelWarning"
BasedOn="{StaticResource LabelBaseStyle}"
TargetType="Label">
<Setter Property="Background"
Value="{DynamicResource WarningBrush}" />
</ControlTheme>

<ControlTheme x:Key="LabelWarning.Small"
BasedOn="{StaticResource LabelWarning}"
TargetType="Label">
<Setter Property="Height"
Value="20" />
<Setter Property="Padding"
Value="6,0" />
</ControlTheme>

<ControlTheme x:Key="LabelDanger"
BasedOn="{StaticResource LabelBaseStyle}"
TargetType="Label">
<Setter Property="Background"
Value="{DynamicResource DangerBrush}" />
</ControlTheme>

<ControlTheme x:Key="LabelDanger.Small"
BasedOn="{StaticResource LabelDanger}"
TargetType="Label">
<Setter Property="Height"
Value="20" />
<Setter Property="Padding"
Value="6,0" />
</ControlTheme>
</ResourceDictionary>

0 comments on commit c78e854

Please sign in to comment.