Skip to content

Commit

Permalink
Add a sliding (in and out) oanimation to the Filters Pane
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Sep 15, 2024
1 parent 45cd6b6 commit f651e8d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/UniGetUI/SoftwarePages/AbstractPackagesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,14 @@
BorderThickness="0" Name="SidePanel" SizeChanged="SidepanelWidth_SizeChanged"
HorizontalScrollMode="Disabled"
CornerRadius="8">
<animations:Explicit.Animations>
<animations:AnimationSet x:Name="OutAnimation_FiltersPane">
<animations:OpacityAnimation From="1" To="0" Duration="0:0:0.15" EasingMode="EaseOut"/>
</animations:AnimationSet>
<animations:AnimationSet x:Name="InAnimation_FiltersPane">
<animations:OpacityAnimation From="0" To="1" Duration="0:0:0.15" EasingMode="EaseIn"/>
</animations:AnimationSet>
</animations:Explicit.Animations>
<Grid RowSpacing="8" Name="SidePanelGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand Down
54 changes: 47 additions & 7 deletions src/UniGetUI/SoftwarePages/AbstractPackagesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ protected IPackage? SelectedItem
protected readonly string NoPackages_SubtitleText_Base;
protected readonly string NoMatches_BackgroundText;

private bool PaneIsAnimated = false;

protected Func<int, int, string> FoundPackages_SubtitleText_Base = (a, b) => CoreTools.Translate("{0} packages were found, {1} of which match the specified filters.", a, b);

protected string NoPackages_SubtitleText
Expand Down Expand Up @@ -272,11 +274,11 @@ protected AbstractPackagesPage(PackagesPageData data)

if (Settings.Get($"HideToggleFilters{PAGE_NAME}Page"))
{
HideFilteringPane();
HideFilteringPane(skipAnimation: true);
}
else
{
ShowFilteringPane();
ShowFilteringPane(skipAnimation: true);
}

QueryBlock.PlaceholderText = CoreTools.Translate("Search for packages");
Expand Down Expand Up @@ -703,6 +705,10 @@ protected async void ShowInstallationOptionsForPackage(IPackage? package)

private void SidepanelWidth_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (PaneIsAnimated)
return;


if (e.NewSize.Width == ((int)(e.NewSize.Width / 10)) || e.NewSize.Width == 25)
{
return;
Expand Down Expand Up @@ -826,30 +832,64 @@ private void ToggleFiltersButton_Click(object sender, RoutedEventArgs e)
}
}

private void HideFilteringPane()
private async void HideFilteringPane(bool skipAnimation = false)
{
if (PaneIsAnimated) return;

PaneIsAnimated = true;
ToggleFiltersButton.IsChecked = false;

if (!skipAnimation)
{
OutAnimation_FiltersPane.Start();
double width = BodyGrid.ColumnDefinitions[0].Width.Value;
while (width > 0)
{
BodyGrid.ColumnDefinitions[0].Width = new GridLength(width);
await Task.Delay(10);
width -= 40;
}
}

FiltersResizer.Visibility = SidePanel.Visibility = Visibility.Collapsed;
BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
BodyGrid.ColumnSpacing = 0;
PaneIsAnimated = false;
}

private void ShowFilteringPane()
private async void ShowFilteringPane(bool skipAnimation = false)
{
if (PaneIsAnimated) return;

PaneIsAnimated = true;
ToggleFiltersButton.IsChecked = true;
FiltersResizer.Visibility = SidePanel.Visibility = Visibility.Visible;
BodyGrid.ColumnSpacing = 12;
int width = 250;
InAnimation_FiltersPane.Start();

int final_width = 250;
try
{
width = int.Parse(Settings.GetValue(SIDEPANEL_WIDTH_SETTING_NAME));
final_width = int.Parse(Settings.GetValue(SIDEPANEL_WIDTH_SETTING_NAME));
}
catch
{
Settings.SetValue(SIDEPANEL_WIDTH_SETTING_NAME, "250");
}

BodyGrid.ColumnDefinitions.ElementAt(0).Width = new GridLength(width);
if (!skipAnimation)
{
double width = 0;
while (width < final_width)
{
BodyGrid.ColumnDefinitions[0].Width = new GridLength(width);
await Task.Delay(10);
width += 40;
}
}

BodyGrid.ColumnDefinitions[0].Width = new GridLength(final_width);
PaneIsAnimated = false;
}
}
}

0 comments on commit f651e8d

Please sign in to comment.