Skip to content

Commit

Permalink
Fix pop-ups for light theme and glass theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Jan 2, 2025
1 parent 4428414 commit 05410db
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
52 changes: 33 additions & 19 deletions src/PicView.Avalonia/CustomControls/AnimatedPopUp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Media;
using PicView.Avalonia.Animations;
using PicView.Avalonia.UI;
using PicView.Core.Config;

namespace PicView.Avalonia.CustomControls;

[TemplatePart("PART_Overlay", typeof(Panel))]
[TemplatePart("PART_Border", typeof(Border))]
public class AnimatedPopUp : ContentControl
{
private Panel? _partOverlay;
private Border? _partBorder;

public static readonly AvaloniaProperty<bool> ClickingOutSideClosesProperty =
AvaloniaProperty.Register<CopyButton, bool>(nameof(ClickingOutSideCloses));


private Border? _partBorder;
private Panel? _partOverlay;

protected AnimatedPopUp()
{
Loaded += async delegate { await AnimatedOpening(); };
}

public bool ClickingOutSideCloses
{
get => (bool)GetValue(ClickingOutSideClosesProperty)!;
Expand All @@ -26,54 +33,61 @@ public bool ClickingOutSideCloses

protected override Type StyleKeyOverride => typeof(AnimatedPopUp);

protected AnimatedPopUp()
{
Loaded += async delegate
{
await AnimatedOpening();
};
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_partOverlay = e.NameScope.Find<Panel>("PART_Overlay");
_partBorder = e.NameScope.Find<Border>("PART_Border");

_partOverlay.Opacity = 0;
_partBorder.Opacity = 0;


if (SettingsHelper.Settings.Theme.GlassTheme)
{
if (Application.Current.TryGetResource("MenuBackgroundColor",
Application.Current.RequestedThemeVariant, out var bgColor))
{
if (bgColor is Color color)
{
_partBorder.Background = new SolidColorBrush(color);
}
}
}

// Handle click outside to close
_partOverlay.PointerPressed += async delegate
{
if (!ClickingOutSideCloses)
{
return;
}

if (!_partBorder.IsPointerOver)
{
await AnimatedClosing();
}
};
}

public async Task AnimatedOpening()
{
UIHelper.IsDialogOpen = true;
var fadeIn = AnimationsHelper.OpacityAnimation(0, 1, 0.3);
var centering = AnimationsHelper.CenteringAnimation(50, 100, 0, 0, 0.3);
await Task.WhenAll(fadeIn.RunAsync(_partOverlay), fadeIn.RunAsync(_partBorder), centering.RunAsync(_partBorder));
await Task.WhenAll(fadeIn.RunAsync(_partOverlay), fadeIn.RunAsync(_partBorder),
centering.RunAsync(_partBorder));
}

public async Task AnimatedClosing()
{
UIHelper.IsDialogOpen = false;
var fadeIn = AnimationsHelper.OpacityAnimation(1, 0, 0.3);
var centering = AnimationsHelper.CenteringAnimation(0, 0, 50, 100, 0.3);
await Task.WhenAll(fadeIn.RunAsync(_partOverlay), fadeIn.RunAsync(_partBorder), centering.RunAsync(_partBorder));
await Task.WhenAll(fadeIn.RunAsync(_partOverlay), fadeIn.RunAsync(_partBorder),
centering.RunAsync(_partBorder));
UIHelper.GetMainView.MainGrid.Children.Remove(this);
}

public void KeyDownHandler(object? sender, KeyEventArgs e)
{
RaiseEvent(e);
Expand Down
6 changes: 5 additions & 1 deletion src/PicView.Avalonia/Views/UC/PopUps/CloseDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<TextBlock
Classes="txt"
FontSize="14"
Foreground="{DynamicResource MainTextColor}"
HorizontalAlignment="Center"
Text="{CompiledBinding CloseWindowPrompt}"
VerticalAlignment="Top" />
Expand All @@ -29,7 +30,10 @@
Margin="0,0,10,0"
Padding="30,0"
x:Name="CancelButton">
<TextBlock Classes="txt" Text="{CompiledBinding Cancel}" />
<TextBlock
Classes="txt"
Foreground="{DynamicResource MainTextColor}"
Text="{CompiledBinding Cancel}" />
</Button>
<Button
Background="{DynamicResource AccentColor}"
Expand Down
7 changes: 6 additions & 1 deletion src/PicView.Avalonia/Views/UC/PopUps/DeleteDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Medium.ttf#Roboto"
FontSize="14"
Foreground="{DynamicResource MainTextColor}"
MaxWidth="200"
x:Name="PromptText" />
<TextBlock
Classes="txt"
Foreground="{DynamicResource MainTextColor}"
Margin="0,6,0,0"
MaxWidth="200"
x:Name="PromptFileName" />
Expand All @@ -34,7 +36,10 @@
Margin="0,0,10,0"
Padding="30,0"
x:Name="CancelButton">
<TextBlock Classes="txt" Text="{CompiledBinding Cancel}" />
<TextBlock
Classes="txt"
Foreground="{DynamicResource MainTextColor}"
Text="{CompiledBinding Cancel}" />
</Button>
<Button
Background="{DynamicResource AccentColor}"
Expand Down

0 comments on commit 05410db

Please sign in to comment.