Skip to content

Commit

Permalink
feat: add resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitism committed Jun 23, 2023
1 parent 009498f commit a61a7f9
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 17 deletions.
20 changes: 10 additions & 10 deletions demo/Ursa.Demo/Pages/LoadingDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
mc:Ignorable="d">
<Grid RowDefinitions="Auto, Auto, *">
<ToggleSwitch Name="s" Content="Loading" />
<u:LoadingIcon Grid.Row="1" />
<Panel
<StackPanel Grid.Row="1" Orientation="Horizontal">
<u:LoadingIcon Classes="Small" />
<u:LoadingIcon />
<u:LoadingIcon Classes="Large" />
</StackPanel>
<u:LoadingContainer
Grid.Row="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<u:Banner
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Hello Ursa!" />
<u:Loading Content="Loading..." IsLoading="{Binding #s.IsChecked}" />
</Panel>
IsLoading="{Binding #s.IsChecked}"
LoadingMessage="Loading...">
<Calendar />
</u:LoadingContainer>
</Grid>
</UserControl>
54 changes: 48 additions & 6 deletions src/Ursa.Themes.Semi/Controls/Loading.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
<!-- Add Resources Here -->
<converters:BrushToColorConverter x:Key="BrushToColorConverter" />
<ControlTheme x:Key="{x:Type u:LoadingIcon}" TargetType="u:LoadingIcon">
<Setter Property="Foreground" Value="{DynamicResource SemiBlue6}" />
<Setter Property="Foreground" Value="{DynamicResource LoadingIconForeground}" />
<Setter Property="Template">
<ControlTemplate TargetType="u:LoadingIcon">
<Arc
Name="PART_Arc"
Width="20"
Height="20"
StartAngle="0"
Expand All @@ -21,7 +22,8 @@
<ConicGradientBrush Angle="70">
<GradientStops>
<GradientStop Offset="0" Color="{Binding Foreground, Converter={StaticResource BrushToColorConverter}, RelativeSource={RelativeSource TemplatedParent}}" />
<GradientStop Offset="0.8" Color="Transparent" />
<GradientStop Offset="0.2" Color="{Binding Foreground, Converter={StaticResource BrushToColorConverter}, RelativeSource={RelativeSource TemplatedParent}}" />
<GradientStop Offset="0.6" Color="Transparent" />
</GradientStops>
</ConicGradientBrush>
</Arc.Stroke>
Expand All @@ -42,12 +44,20 @@
</Arc>
</ControlTemplate>
</Setter>
<Style Selector="^.Small /template/ Arc#PART_Arc">
<Setter Property="Arc.Width" Value="14" />
<Setter Property="Arc.Height" Value="14" />
<Setter Property="Arc.StrokeThickness" Value="2" />
</Style>
<Style Selector="^.Large /template/ Arc#PART_Arc">
<Setter Property="Arc.Width" Value="32" />
<Setter Property="Arc.Height" Value="32" />
<Setter Property="Arc.StrokeThickness" Value="5" />
</Style>
</ControlTheme>

<ControlTheme x:Key="{x:Type u:Loading}" TargetType="u:Loading">
<Setter Property="Background">
<SolidColorBrush Opacity="0.13" Color="#2E3238" />
</Setter>
<Setter Property="Background" Value="{DynamicResource LoadingMaskBackground}" />
<Setter Property="Indicator">
<Template>
<u:LoadingIcon />
Expand All @@ -69,10 +79,42 @@
Name="PART_ContentPresenter"
Grid.Row="1"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
ContentTemplate="{TemplateBinding ContentTemplate}"
IsVisible="{TemplateBinding Content,
Converter={x:Static ObjectConverters.IsNotNull}}" />
</Grid>
</Panel>
</ControlTemplate>
</Setter>
</ControlTheme>

<ControlTheme x:Key="{x:Type u:LoadingContainer}" TargetType="u:LoadingContainer">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Indicator">
<Template>
<u:LoadingIcon />
</Template>
</Setter>
<Setter Property="Template">
<ControlTemplate TargetType="u:LoadingContainer">
<Panel>
<ContentPresenter
Name="PART_ContentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
<u:Loading
Content="{TemplateBinding LoadingMessage}"
ContentTemplate="{TemplateBinding LoadingMessageTemplate}"
Indicator="{TemplateBinding Indicator}"
IsLoading="{TemplateBinding IsLoading}" />
</Panel>
</ControlTemplate>
</Setter>
<Style Selector="^:loading /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Effect" Value="blur(5)" />
</Style>
</ControlTheme>
</ResourceDictionary>
3 changes: 2 additions & 1 deletion src/Ursa.Themes.Semi/Converters/BrushToColorConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media;

Expand All @@ -12,7 +13,7 @@ public class BrushToColorConverter: IValueConverter
{
return b.Color;
}
return null;
return Colors.Transparent;
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
Expand Down
5 changes: 5 additions & 0 deletions src/Ursa.Themes.Semi/Themes/Dark/Loading.axaml
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">
<!-- Add Resources Here -->
<SolidColorBrush x:Key="LoadingIconForeground" Color="#54A9FF" />
<SolidColorBrush x:Key="LoadingMaskBackground" Opacity="0.12" Color="White" />
</ResourceDictionary>
1 change: 1 addition & 0 deletions src/Ursa.Themes.Semi/Themes/Dark/_index.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<MergeResourceInclude Source="Banner.axaml" />
<MergeResourceInclude Source="Divider.axaml" />
<MergeResourceInclude Source="IPv4Box.axaml" />
<MergeResourceInclude Source="Loading.axaml" />
<MergeResourceInclude Source="NavigationMenu.axaml" />
<MergeResourceInclude Source="Pagination.axaml" />
<MergeResourceInclude Source="Timeline.axaml" />
Expand Down
5 changes: 5 additions & 0 deletions src/Ursa.Themes.Semi/Themes/Light/Loading.axaml
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">
<!-- Add Resources Here -->
<SolidColorBrush x:Key="LoadingIconForeground" Color="#0077FA" />
<SolidColorBrush x:Key="LoadingMaskBackground" Opacity="0.05" Color="#2E3238" />
</ResourceDictionary>
1 change: 1 addition & 0 deletions src/Ursa.Themes.Semi/Themes/Light/_index.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<MergeResourceInclude Source="Banner.axaml" />
<MergeResourceInclude Source="Divider.axaml" />
<MergeResourceInclude Source="IPv4Box.axaml" />
<MergeResourceInclude Source="Loading.axaml" />
<MergeResourceInclude Source="NavigationMenu.axaml" />
<MergeResourceInclude Source="Pagination.axaml" />
<MergeResourceInclude Source="Timeline.axaml" />
Expand Down
59 changes: 59 additions & 0 deletions src/Ursa/Controls/Loading/LoadingContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Templates;

namespace Ursa.Controls;

[PseudoClasses(PC_Loading)]
public class LoadingContainer: ContentControl
{
public const string PC_Loading = ":loading";

public static readonly StyledProperty<object?> IndicatorProperty = AvaloniaProperty.Register<LoadingContainer, object?>(
nameof(Indicator));

public object? Indicator
{
get => GetValue(IndicatorProperty);
set => SetValue(IndicatorProperty, value);
}

public static readonly StyledProperty<object?> LoadingMessageProperty = AvaloniaProperty.Register<LoadingContainer, object?>(
nameof(LoadingMessage));

public object? LoadingMessage
{
get => GetValue(LoadingMessageProperty);
set => SetValue(LoadingMessageProperty, value);
}

public static readonly StyledProperty<IDataTemplate> LoadingMessageTemplateProperty = AvaloniaProperty.Register<LoadingContainer, IDataTemplate>(
nameof(LoadingMessageTemplate));

public IDataTemplate LoadingMessageTemplate
{
get => GetValue(LoadingMessageTemplateProperty);
set => SetValue(LoadingMessageTemplateProperty, value);
}

public static readonly StyledProperty<bool> IsLoadingProperty = AvaloniaProperty.Register<LoadingContainer, bool>(
nameof(IsLoading));

public bool IsLoading
{
get => GetValue(IsLoadingProperty);
set => SetValue(IsLoadingProperty, value);
}

static LoadingContainer()
{
IsLoadingProperty.Changed.AddClassHandler<LoadingContainer>((x, e) => x.OnIsLoadingChanged(e));
}

private void OnIsLoadingChanged(AvaloniaPropertyChangedEventArgs args)
{
bool newValue = args.GetNewValue<bool>();
PseudoClasses.Set(PC_Loading, newValue);
}
}

0 comments on commit a61a7f9

Please sign in to comment.