Skip to content

Commit

Permalink
#89 side by side improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Sep 6, 2024
1 parent 6afab31 commit 21e64cb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/PicView.Avalonia.Win32/Views/WinMainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ private void Control_OnSizeChanged(object? sender, SizeChangedEventArgs e)
return;
}
var wm = (MainViewModel)DataContext;
WindowHelper.SetSize(wm);
//WindowHelper.SetSize(wm);
}
}
59 changes: 50 additions & 9 deletions src/PicView.Avalonia/Navigation/ImageIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,7 @@ public async Task IterateToIndex(int index)
{
if (preloadValue.IsLoading)
{
if (index == CurrentIndex)
{
LoadingPreview(index);
}
TryShowPreview(preloadValue);
}

while (preloadValue.IsLoading)
Expand All @@ -536,11 +533,7 @@ public async Task IterateToIndex(int index)
}
else
{
if (index == CurrentIndex)
{
LoadingPreview(index);
}

TryShowPreview(preloadValue);
preloadValue = await PreLoader.GetAsync(CurrentIndex, ImagePaths);
}

Expand All @@ -556,6 +549,14 @@ public async Task IterateToIndex(int index)
if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
{
var nextPreloadValue = await GetNextPreLoadValueAsync();
lock (_lock)
{
if (CurrentIndex != index)
{
// Skip loading if user went to next value
return;
}
}
_vm.SecondaryImageSource = nextPreloadValue.ImageModel.Image;
await UpdateSource(index, preloadValue, nextPreloadValue);
}
Expand Down Expand Up @@ -594,6 +595,32 @@ public async Task IterateToIndex(int index)
{
_vm.IsLoading = false;
}

return;

void TryShowPreview(PreLoader.PreLoadValue preloadValue)
{
if (preloadValue is null)
return;

if (!preloadValue.IsLoading)
return;

if (index != CurrentIndex)
return;

if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
{
SetTitleHelper.SetLoadingTitle(_vm);
_vm.IsLoading = true;
_vm.ImageSource = null;
_vm.SecondaryImageSource = null;
}
else
{
LoadingPreview(index);
}
}
}

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

if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
{
nextPreloadValue ??= await GetNextPreLoadValueAsync();
if (nextPreloadValue.ImageModel?.Image is null)
{
var fileInfo = nextPreloadValue.ImageModel?.FileInfo ?? new FileInfo(ImagePaths[GetIteration(index, IsReversed ? NavigateTo.Previous : NavigateTo.Next, true)]);
nextPreloadValue.ImageModel = await ImageHelper.GetImageModelAsync(fileInfo).ConfigureAwait(false);
}
}

_vm.IsLoading = false;
ExifHandling.SetImageModel(preLoadValue.ImageModel, _vm);
if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
{
_vm.SecondaryImageSource = nextPreloadValue.ImageModel.Image;
}
_vm.ImageSource = preLoadValue.ImageModel.Image;
if (preLoadValue.ImageModel.ImageType is ImageType.AnimatedGif or ImageType.AnimatedWebp)
{
Expand Down
14 changes: 8 additions & 6 deletions src/PicView.Core/Calculations/ImageSizeCalculationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,24 @@ public static ImageSize GetImageSize(double width,
// Combined width of both images
var combinedWidth = xWidth1 + xWidth2;

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

// If combined width exceeds available width, scale both images down proportionally
if (combinedWidth > availableWidth)
{
var scaleFactor = availableWidth / combinedWidth;
xWidth1 *= scaleFactor;
xWidth2 *= scaleFactor;
xHeight *= scaleFactor; // Adjust the height accordingly
xHeight *= scaleFactor;

combinedWidth = xWidth1 + xWidth2;
}

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

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


Expand Down

0 comments on commit 21e64cb

Please sign in to comment.