Skip to content

Commit 21e64cb

Browse files
committed
#89 side by side improvements
1 parent 6afab31 commit 21e64cb

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed

src/PicView.Avalonia.Win32/Views/WinMainWindow.axaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ private void Control_OnSizeChanged(object? sender, SizeChangedEventArgs e)
7979
return;
8080
}
8181
var wm = (MainViewModel)DataContext;
82-
WindowHelper.SetSize(wm);
82+
//WindowHelper.SetSize(wm);
8383
}
8484
}

src/PicView.Avalonia/Navigation/ImageIterator.cs

+50-9
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,7 @@ public async Task IterateToIndex(int index)
515515
{
516516
if (preloadValue.IsLoading)
517517
{
518-
if (index == CurrentIndex)
519-
{
520-
LoadingPreview(index);
521-
}
518+
TryShowPreview(preloadValue);
522519
}
523520

524521
while (preloadValue.IsLoading)
@@ -536,11 +533,7 @@ public async Task IterateToIndex(int index)
536533
}
537534
else
538535
{
539-
if (index == CurrentIndex)
540-
{
541-
LoadingPreview(index);
542-
}
543-
536+
TryShowPreview(preloadValue);
544537
preloadValue = await PreLoader.GetAsync(CurrentIndex, ImagePaths);
545538
}
546539

@@ -556,6 +549,14 @@ public async Task IterateToIndex(int index)
556549
if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
557550
{
558551
var nextPreloadValue = await GetNextPreLoadValueAsync();
552+
lock (_lock)
553+
{
554+
if (CurrentIndex != index)
555+
{
556+
// Skip loading if user went to next value
557+
return;
558+
}
559+
}
559560
_vm.SecondaryImageSource = nextPreloadValue.ImageModel.Image;
560561
await UpdateSource(index, preloadValue, nextPreloadValue);
561562
}
@@ -594,6 +595,32 @@ public async Task IterateToIndex(int index)
594595
{
595596
_vm.IsLoading = false;
596597
}
598+
599+
return;
600+
601+
void TryShowPreview(PreLoader.PreLoadValue preloadValue)
602+
{
603+
if (preloadValue is null)
604+
return;
605+
606+
if (!preloadValue.IsLoading)
607+
return;
608+
609+
if (index != CurrentIndex)
610+
return;
611+
612+
if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
613+
{
614+
SetTitleHelper.SetLoadingTitle(_vm);
615+
_vm.IsLoading = true;
616+
_vm.ImageSource = null;
617+
_vm.SecondaryImageSource = null;
618+
}
619+
else
620+
{
621+
LoadingPreview(index);
622+
}
623+
}
597624
}
598625

599626
private static Timer? _timer;
@@ -642,8 +669,22 @@ private async Task UpdateSource(int index, PreLoader.PreLoadValue? preLoadValue,
642669
preLoadValue.ImageModel = await ImageHelper.GetImageModelAsync(fileInfo).ConfigureAwait(false);
643670
}
644671

672+
if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
673+
{
674+
nextPreloadValue ??= await GetNextPreLoadValueAsync();
675+
if (nextPreloadValue.ImageModel?.Image is null)
676+
{
677+
var fileInfo = nextPreloadValue.ImageModel?.FileInfo ?? new FileInfo(ImagePaths[GetIteration(index, IsReversed ? NavigateTo.Previous : NavigateTo.Next, true)]);
678+
nextPreloadValue.ImageModel = await ImageHelper.GetImageModelAsync(fileInfo).ConfigureAwait(false);
679+
}
680+
}
681+
645682
_vm.IsLoading = false;
646683
ExifHandling.SetImageModel(preLoadValue.ImageModel, _vm);
684+
if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
685+
{
686+
_vm.SecondaryImageSource = nextPreloadValue.ImageModel.Image;
687+
}
647688
_vm.ImageSource = preLoadValue.ImageModel.Image;
648689
if (preLoadValue.ImageModel.ImageType is ImageType.AnimatedGif or ImageType.AnimatedWebp)
649690
{

src/PicView.Core/Calculations/ImageSizeCalculationHelper.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,24 @@ public static ImageSize GetImageSize(double width,
183183
// Combined width of both images
184184
var combinedWidth = xWidth1 + xWidth2;
185185

186-
// Available width (monitor width minus 2 for constraint)
187-
var availableWidth = monitorWidth - 2;
186+
var widthPadding = SettingsHelper.Settings.ImageScaling.StretchImage ? 4 : padding;
187+
var availableWidth = monitorWidth - widthPadding;
188188

189189
// If combined width exceeds available width, scale both images down proportionally
190190
if (combinedWidth > availableWidth)
191191
{
192192
var scaleFactor = availableWidth / combinedWidth;
193+
xWidth1 *= scaleFactor;
193194
xWidth2 *= scaleFactor;
194-
xHeight *= scaleFactor; // Adjust the height accordingly
195+
xHeight *= scaleFactor;
196+
197+
combinedWidth = xWidth1 + xWidth2;
195198
}
196199

197-
// Calculate title max width for the first image (this can be adapted for the second image too)
198200
var titleMaxWidth = GetTitleMaxWidth(rotationAngle, combinedWidth, xHeight, monitorMinWidth, monitorMinHeight, interfaceSize, containerWidth);
199201

200-
// Return the size of the first image (adjust if needed to return both images' sizes)
201-
return new ImageSize(combinedWidth, xHeight, xWidth2, titleMaxWidth, 0, firstSize.AspectRatio);
202+
var margin = firstSize.Height > secondSize.Height ? firstSize.Margin : secondSize.Margin;
203+
return new ImageSize(combinedWidth, xHeight, xWidth2, titleMaxWidth, margin, firstSize.AspectRatio);
202204
}
203205

204206

0 commit comments

Comments
 (0)