Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ProgressRing #558

Merged
merged 6 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions samples/FAControlsGallery/Assets/FAControlsGroups.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@
"WinUINamespace": null,
"WinUIDocsLink": null,
"WinUIGuidelinesLink": null
},
{
"Header": "ProgressRing",
"Description": "Shows the app's progress on a task, or that the app is performing ongoing work that does block user interaction",
"IconResourceKey": "ProgressRingIcon",
"PageKey": "ProgressRing",
"SearchKeywords": [
"ProgressRing",
"Progress"
],
"Namespace": "FluentAvalonia.UI.Controls.ProgressRing",
"WinUINamespace": "Microsoft.UI.Xaml.Controls.ProgressRing",
"WinUIDocsLink": null,
"WinUIGuidelinesLink": null
}
]
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions samples/FAControlsGallery/FAControlsGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,4 @@
<ItemGroup>
<ProjectReference Include="..\..\src\FluentAvalonia\FluentAvalonia.csproj" />
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Pages\FAControlsPages\RangeSliderPage.axaml" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:ctrls="using:FAControlsGallery.Controls"
xmlns:pg="using:FAControlsGallery.Pages"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="650"
x:Class="FAControlsGallery.Pages.ProgressRingPage">
<StackPanel Spacing="8">

<ctrls:ControlExample Header="An indeterminate progress ring">

<!-- This is set to False so it doesn't run in designer. Changed to true in code-->
<ui:ProgressRing Width="80" Height="80"
Name="IndetRing"
IsIndeterminate="True" />

<ctrls:ControlExample.Options>
<StackPanel Spacing="8">
<TextBlock Text="BackgroundColor" />
<ColorPicker Color="Transparent"
Name="CPIndet"
ColorChanged="ColorPicker_ColorChanged"/>
</StackPanel>
</ctrls:ControlExample.Options>

<ctrls:ControlExample.XamlSource>
<x:String xml:space="preserve">
&lt;ui:ProgressRing /&gt;
</x:String>
</ctrls:ControlExample.XamlSource>
</ctrls:ControlExample>

<ctrls:ControlExample Header="An determinate progress ring">

<ui:ProgressRing Width="80" Height="80"
Value="25"
Name="DetRing"
IsIndeterminate="False" />

<ctrls:ControlExample.Options>
<StackPanel Spacing="8">
<ui:NumberBox Width="150" Name="Slider"
Minimum="0" Maximum="100"
SpinButtonPlacementMode="Inline"
Value="{Binding #DetRing.Value, Mode=TwoWay}"
Header="Value"/>
<TextBlock Text="BackgroundColor" />
<ColorPicker Color="Transparent"
Name="CP1"
ColorChanged="ColorPicker_ColorChanged"/>
</StackPanel>
</ctrls:ControlExample.Options>

<ctrls:ControlExample.XamlSource>
<x:String xml:space="preserve">
&lt;ui:ProgressRing IsIndeterminate="False"/&gt;
</x:String>
</ctrls:ControlExample.XamlSource>
</ctrls:ControlExample>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media.Immutable;

namespace FAControlsGallery.Pages;

public partial class ProgressRingPage : ControlsPageBase
{
public ProgressRingPage()
{
InitializeComponent();
}

protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
IndetRing.IsIndeterminate = true;
}

protected override void OnUnloaded(RoutedEventArgs e)
{
base.OnUnloaded(e);
IndetRing.IsIndeterminate = false;
}

private void ColorPicker_ColorChanged(object sender, ColorChangedEventArgs e)
{
if (sender == CPIndet)
{
IndetRing.Background = new ImmutableSolidColorBrush(e.NewColor);
}
else if (sender == CP1)
{
DetRing.Background = new ImmutableSolidColorBrush(e.NewColor);
}
}
}
1 change: 1 addition & 0 deletions samples/FAControlsGallery/Styling/Resources.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<ui:ImageIconSource x:Key="InfoBadgeIcon" Source="avares://FAControlsGallery/Assets/Icons/InfoBadgeIcon.png" />
<ui:ImageIconSource x:Key="SettingsExpanderIcon" Source="avares://FAControlsGallery/Assets/Icons/SettingsExpanderIcon.png" />
<ui:ImageIconSource x:Key="RangeSliderIcon" Source="avares://FAControlsGallery/Assets/Icons/RangeSliderIcon.png" />
<ui:ImageIconSource x:Key="ProgressRingIcon" Source="avares://FAControlsGallery/Assets/Icons/ProgressRingIcon.png" />

<ui:ImageIconSource x:Key="SourceCodeIcon">
<ui:ImageIconSource.Source>
Expand Down
3 changes: 2 additions & 1 deletion samples/FAControlsGallery/ViewModels/MainViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ private Control ResolvePage(PageBaseViewModel pbvm)
{ "InfoBar", () => new InfoBarPage() },
{ "InfoBadge", () => new InfoBadgePage() },
{ "SettingsExpander", () => new SettingsExpanderPage() },
{ "RangeSlider", () => new RangeSliderPage() }
{ "RangeSlider", () => new RangeSliderPage() },
{ "ProgressRing", () => new ProgressRingPage() }
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/FluentAvalonia/Styling/ControlThemes/Controls.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
<MergeResourceInclude Source="/Styling/ControlThemes/FAControls/AppWindowStyles.axaml" />

<MergeResourceInclude Source="/Styling/ControlThemes/FAControls/RangeSliderStyles.axaml" />

<MergeResourceInclude Source="/Styling/ControlThemes/FAControls/ProgressRingStyles.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Styles.Resources>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:uip="using:FluentAvalonia.UI.Controls.Primitives">

<ControlTheme TargetType="ui:ProgressRing"
x:Key="{x:Type ui:ProgressRing}">
<Setter Property="Foreground" Value="{DynamicResource AccentFillColorDefaultBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlFillColorTransparentBrush}" />
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="MinHeight" Value="16" />
<Setter Property="MinWidth" Value="16" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Width" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="Maximum" Value="100" />
<Setter Property="Template">
<ControlTemplate>
<Panel Background="Transparent">
<uip:ProgressRingAnimatedVisual Name="AnimatedVisual" />
</Panel>
</ControlTemplate>
</Setter>
</ControlTheme>

</ResourceDictionary>
88 changes: 88 additions & 0 deletions src/FluentAvalonia/UI/Controls/ProgressRing/ProgressRing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
using FluentAvalonia.UI.Controls.Primitives;

namespace FluentAvalonia.UI.Controls;

[TemplatePart(_tpAnimatedVisual, typeof(ProgressRingAnimatedVisual))]
public class ProgressRing : RangeBase
{
/// <summary>
/// Defines the <see cref="IsActive"/> property
/// </summary>
public static readonly StyledProperty<bool> IsActiveProperty =
AvaloniaProperty.Register<ProgressRing, bool>(nameof(IsActive), true);

/// <summary>
/// Defines the <see cref="IsIndeterminate"/> property
/// </summary>
public static readonly StyledProperty<bool> IsIndeterminateProperty =
ProgressBar.IsIndeterminateProperty.AddOwner<ProgressRing>(
new StyledPropertyMetadata<bool>(defaultValue: true));

/// <summary>
/// Gets or sets a value that indicates whether the ProgressRing is showing progress
/// </summary>
public bool IsActive
{
get => GetValue(IsActiveProperty);
set => SetValue(IsActiveProperty, value);
}

/// <summary>
/// Gets or sets a value that indicates whether the progress ring reports generic progress
/// with a repeating pattern or reports progress based on the Value property.
/// </summary>
public bool IsIndeterminate
{
get => GetValue(IsIndeterminateProperty);
set => SetValue(IsIndeterminateProperty, value);
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_animatedVisualSource = e.NameScope.Get<ProgressRingAnimatedVisual>(_tpAnimatedVisual);
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);

if (change.Property == ValueProperty)
{
_animatedVisualSource?.SetValue(change.GetNewValue<double>());
}
else if (change.Property == MinimumProperty)
{
_animatedVisualSource?.SetMinimum(change.GetNewValue<double>());
}
else if (change.Property == MaximumProperty)
{
_animatedVisualSource?.SetMaximum(change.GetNewValue<double>());
}
else if (change.Property == IsIndeterminateProperty)
{
_animatedVisualSource?.SetIndeterminate(change.GetNewValue<bool>());
}
else if (change.Property == IsActiveProperty)
{
_animatedVisualSource?.SetActive(change.GetNewValue<bool>());
}
else if (change.Property == ForegroundProperty)
{
_animatedVisualSource?.SetForeground((IBrush)change.NewValue);
}
else if (change.Property == BackgroundProperty)
{
_animatedVisualSource?.SetBackground((IBrush)change.NewValue);
}
}

private ProgressRingAnimatedVisual _animatedVisualSource;

private const string _tpAnimatedVisual = "AnimatedVisual";
}
Loading