Skip to content

Commit

Permalink
Gallery updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Oct 12, 2024
1 parent c3cd28e commit 95e659f
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 82 deletions.
29 changes: 24 additions & 5 deletions src/PicView.Avalonia/Gallery/GalleryFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,31 @@ public static void Clear()
return;
void ClearItems()
{
var mainView = UIHelper.GetMainView;
try
{
var mainView = UIHelper.GetMainView;

var galleryListBox = mainView.GalleryView.GalleryListBox;
if (galleryListBox == null)
return;
galleryListBox.Items.Clear();
var galleryListBox = mainView.GalleryView.GalleryListBox;
if (galleryListBox == null)
return;
for (var i = 0; i < galleryListBox.ItemCount; i++)
{
if (galleryListBox.Items[i] is not GalleryItem galleryItem)
continue;
if (galleryItem.GalleryImage.Source is IDisposable galleryImage)
{
galleryImage.Dispose();
}
galleryListBox.Items.Remove(galleryItem);
}
galleryListBox.Items.Clear();
}
catch (Exception e)
{
#if DEBUG
Console.WriteLine(e);
#endif
}
}
}
}
15 changes: 4 additions & 11 deletions src/PicView.Avalonia/Gallery/GalleryLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
}
catch (OperationCanceledException)
{
await Dispatcher.UIThread.InvokeAsync(() =>
{
galleryListBox?.Items.Clear();
});
await Dispatcher.UIThread.InvokeAsync(GalleryFunctions.Clear);
}
catch (Exception e)
{
Expand Down Expand Up @@ -206,7 +203,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
if (vm.ImageIterator is null)
{
ct.ThrowIfCancellationRequested();
galleryListBox?.Items.Clear();
GalleryFunctions.Clear();
if (GalleryFunctions.IsBottomGalleryOpen)
{
mainView.GalleryView.GalleryMode = GalleryMode.BottomToClosed;
Expand All @@ -233,9 +230,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
{
try
{
var mainView = UIHelper.GetMainView;
var galleryListBox = mainView.GalleryView.GalleryListBox;
galleryListBox?.Items.Clear();
GalleryFunctions.Clear();
}
catch (Exception e)
{
Expand All @@ -260,9 +255,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
{
try
{
var mainView = UIHelper.GetMainView;
var galleryListBox = mainView.GalleryView.GalleryListBox;
galleryListBox?.Items.Clear();
GalleryFunctions.Clear();
}
catch (Exception e)
{
Expand Down
18 changes: 2 additions & 16 deletions src/PicView.Avalonia/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,8 @@ public double GetGalleryItemWidth
private double _getGalleryItemHeight;
public double GetGalleryItemHeight
{
get
{
return GalleryFunctions.IsFullGalleryOpen ? GetFullGalleryItemHeight : GetBottomGalleryItemHeight;
}
set
{
this.RaiseAndSetIfChanged(ref _getGalleryItemHeight, value);
if (GalleryFunctions.IsBottomGalleryOpen && !GalleryFunctions.IsFullGalleryOpen)
{
GetBottomGalleryItemHeight = value;
}
else
{
GetFullGalleryItemHeight = value;
}
}
get => _getGalleryItemHeight;
set => this.RaiseAndSetIfChanged(ref _getGalleryItemHeight, value);
}

private double _getFullGalleryItemHeight = SettingsHelper.Settings.Gallery.ExpandedGalleryItemSize;
Expand Down
14 changes: 5 additions & 9 deletions src/PicView.Avalonia/Views/GalleryView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
<ContextMenu Opened="MenuBase_OnOpened">
<MenuItem Header="{CompiledBinding Stretch, Mode=OneWay}">
<MenuItem.Icon>
<Path
Data="{StaticResource ImageGeometry}"
Fill="{DynamicResource MainTextColor}"
<Image
Height="12"
Stretch="Fill"
Source="{StaticResource Image}"
Width="12" />
</MenuItem.Icon>
<MenuItem
Expand Down Expand Up @@ -79,11 +77,9 @@
PointerPressed="Flyout_OnPointerPressed"
StaysOpenOnClick="True">
<MenuItem.Icon>
<Path
Data="{StaticResource ImageGeometry}"
Fill="{DynamicResource MainTextColor}"
<Image
Height="12"
Stretch="Fill"
Source="{StaticResource Image}"
Width="12" />
</MenuItem.Icon>
<FlyoutBase.AttachedFlyout>
Expand All @@ -100,7 +96,7 @@
</FlyoutBase.AttachedFlyout>
</MenuItem>
<Separator />
<MenuItem Command="{CompiledBinding CloseGalleryCommand}" Header="{CompiledBinding Close, Mode=OneWay}">
<MenuItem Command="{CompiledBinding CloseGalleryCommand}" Header="{CompiledBinding HideBottomGallery, Mode=OneWay}">
<MenuItem.Icon>
<Path
Data="{StaticResource CloseGeometry}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
Minimum="{CompiledBinding MinBottomGalleryItemHeight}"
TickFrequency="1"
TickPlacement="BottomRight"
Value="{CompiledBinding GetBottomGalleryItemHeight}"
Value="{CompiledBinding GetBottomGalleryItemHeight,
Mode=OneWay}"
ValueChanged="BottomGallery_OnValueChanged"
Width="300" />
</UserControl>
18 changes: 7 additions & 11 deletions src/PicView.Avalonia/Views/UC/BottomGalleryItemSizeSlider.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using PicView.Avalonia.Gallery;
using PicView.Avalonia.UI;
Expand All @@ -17,8 +15,7 @@ public BottomGalleryItemSizeSlider()
}
private void BottomGallery_OnValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
{
if (DataContext is not MainViewModel vm ||
Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
if (DataContext is not MainViewModel vm )
{
return;
}
Expand All @@ -27,18 +24,17 @@ private void BottomGallery_OnValueChanged(object? sender, RangeBaseValueChangedE
{
return;
}
SettingsHelper.Settings.Gallery.BottomGalleryItemSize = e.NewValue;
if (GalleryFunctions.IsBottomGalleryOpen && !GalleryFunctions.IsFullGalleryOpen)
vm.GetBottomGalleryItemHeight = e.NewValue;

if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown && !GalleryFunctions.IsFullGalleryOpen)
{
vm.GetGalleryItemHeight = e.NewValue;
var mainView = desktop.MainWindow.GetControl<MainView>("MainView");
var gallery = mainView.GalleryView;
gallery.Height = vm.GalleryHeight;
UIHelper.GetGalleryView.Height = vm.GalleryHeight;
WindowHelper.SetSize(vm);
}

// Binding to height depends on timing of the update. Maybe find a cleaner mvvm solution one day
// Maybe save this on close or some other way
_ = SettingsHelper.SaveSettingsAsync();
SettingsHelper.Settings.Gallery.BottomGalleryItemSize = e.NewValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
TickFrequency="1"
TickPlacement="BottomRight"
Value="{CompiledBinding GetFullGalleryItemHeight,
Mode=TwoWay}"
Mode=OneWay}"
ValueChanged="FullGallery_OnValueChanged"
Width="300" />
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ private void FullGallery_OnValueChanged(object? sender, RangeBaseValueChangedEve
{
return;
}

vm.GetFullGalleryItemHeight = e.NewValue;
if (GalleryFunctions.IsFullGalleryOpen)
{
vm.GetGalleryItemHeight = vm.GetFullGalleryItemHeight;
WindowHelper.SetSize(vm);
}
// Binding to height depends on timing of the update. Maybe find a cleaner mvvm solution one day

// Maybe save this on close or some other way
SettingsHelper.Settings.Gallery.ExpandedGalleryItemSize = e.NewValue;
}
Expand Down
87 changes: 87 additions & 0 deletions src/PicView.Avalonia/Views/UC/GalleryItem.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns="https://github.com/avaloniaui"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:PicView.Avalonia.Views.UC"
xmlns:viewModels="clr-namespace:PicView.Avalonia.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Border
Expand Down Expand Up @@ -212,6 +213,92 @@
Width="12" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="{CompiledBinding Stretch, Mode=OneWay}">
<MenuItem.Icon>
<Image
Height="12"
Source="{StaticResource Image}"
Width="12" />
</MenuItem.Icon>
<MenuItem
Command="{CompiledBinding GalleryItemStretchCommand}"
CommandParameter="Uniform"
Header="{CompiledBinding Uniform,
Mode=OneWay}"
IsChecked="{CompiledBinding IsUniformMenuChecked}"
ToggleType="Radio" />
<MenuItem
Command="{CompiledBinding GalleryItemStretchCommand}"
CommandParameter="UniformToFill"
Header="{CompiledBinding UniformToFill,
Mode=OneWay}"
IsChecked="{CompiledBinding IsUniformToFillMenuChecked}"
ToggleType="Radio" />
<MenuItem
Command="{CompiledBinding GalleryItemStretchCommand}"
CommandParameter="Fill"
Header="{CompiledBinding Fill,
Mode=OneWay}"
IsChecked="{CompiledBinding IsFillMenuChecked}"
ToggleType="Radio" />
<MenuItem
Command="{CompiledBinding GalleryItemStretchCommand}"
CommandParameter="None"
Header="{CompiledBinding None,
Mode=OneWay}"
IsChecked="{CompiledBinding IsNoneMenuChecked}"
ToggleType="Radio" />
<MenuItem
Command="{CompiledBinding GalleryItemStretchCommand}"
CommandParameter="Square"
Header="{CompiledBinding Square,
Mode=OneWay}"
IsChecked="{CompiledBinding IsSquareMenuChecked}"
ToggleType="Radio" />
<MenuItem
Command="{CompiledBinding GalleryItemStretchCommand}"
CommandParameter="FillSquare"
Header="{CompiledBinding FillSquare,
Mode=OneWay}"
IsChecked="{CompiledBinding IsFillSquareMenuChecked}"
ToggleType="Radio" />
</MenuItem>
<MenuItem
Header="{CompiledBinding ExpandedGalleryItemSize,
Mode=OneWay}"
PointerPressed="Flyout_OnPointerPressed"
StaysOpenOnClick="True">
<MenuItem.Icon>
<Image
Height="12"
Source="{StaticResource Image}"
Width="12" />
</MenuItem.Icon>
<FlyoutBase.AttachedFlyout>
<Flyout>
<Border
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="2"
CornerRadius="4"
Padding="10,3">
<uc:GalleryItemSizeSlider x:Name="GalleryItemSizeSlider" />
</Border>
</Flyout>
</FlyoutBase.AttachedFlyout>
</MenuItem>
<Separator />
<MenuItem Command="{CompiledBinding CloseGalleryCommand}" Header="{CompiledBinding HideBottomGallery, Mode=OneWay}">
<MenuItem.Icon>
<Path
Data="{StaticResource CloseGeometry}"
Fill="{DynamicResource MainTextColor}"
Height="12"
Stretch="Fill"
Width="12" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Border.ContextMenu>
</Border>
Expand Down
13 changes: 13 additions & 0 deletions src/PicView.Avalonia/Views/UC/GalleryItem.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Media;
using Exception = System.Exception;

Expand Down Expand Up @@ -36,5 +38,16 @@ public GalleryItem()
ImageBorder.BorderBrush = Brushes.Transparent;
};
}

private void Flyout_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (sender is not Control ctl)
{
return;
}

FlyoutBase.ShowAttachedFlyout(ctl);
GalleryItemSizeSlider.SetMaxAndMin();
}
}
}
2 changes: 1 addition & 1 deletion src/PicView.Avalonia/Views/UC/GalleryItemSizeSlider.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
TickFrequency="1"
TickPlacement="BottomRight"
Value="{CompiledBinding GetGalleryItemHeight,
Mode=TwoWay}"
Mode=OneWay}"
ValueChanged="RangeBase_OnValueChanged"
Width="270"
x:Name="CustomSlider" />
Expand Down
Loading

0 comments on commit 95e659f

Please sign in to comment.