Skip to content

Commit

Permalink
Fix other listviews
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Aug 29, 2024
1 parent cbfe3da commit 3d9ff7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
22 changes: 14 additions & 8 deletions NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ public WinFormsListView(ListViewBehavior<T> behavior)
EtoPlatform.Current.AttachDpiDependency(_viewEtoControl, scale =>
{
_dpiScale = scale;
// Reset internal size based on new scale
ImageSize = ImageSize;
if (_behavior.ScaleImageSize)
{
// Reset internal size based on new scale
ImageSize = ImageSize;
}
});
}

Expand All @@ -90,6 +93,8 @@ public WinFormsListView(ListViewBehavior<T> behavior)
private void CustomRenderItem(object? sender, DrawListViewItemEventArgs e)
{
var image = ImageList.Get(e.Item);
int imageSizeW = _behavior.ScaleImageSize ? (int) Math.Round(_imageSize.Width * _dpiScale) : _imageSize.Width;
int imageSizeH = _behavior.ScaleImageSize ? (int) Math.Round(_imageSize.Height * _dpiScale) : _imageSize.Height;
if (_behavior.ShowPageNumbers)
{
int tp = (int) Math.Round(PageNumberTextPadding * _dpiScale);
Expand All @@ -102,8 +107,8 @@ private void CustomRenderItem(object? sender, DrawListViewItemEventArgs e)
SizeF textSize = TextRenderer.MeasureText(label, _view.Font);
int textOffset = (int) (textSize.Height + tp);

float scaleHeight = (ImageSize.Height * _dpiScale - textOffset) / image.Height;
float scaleWidth = ImageSize.Width * _dpiScale / image.Width;
float scaleHeight = (float) (imageSizeH - textOffset) / image.Height;
float scaleWidth = (float) imageSizeW / image.Width;

float scale = Math.Min(scaleWidth, scaleHeight);
int height = (int) Math.Round(image.Height * scale);
Expand Down Expand Up @@ -156,12 +161,12 @@ private void CustomRenderItem(object? sender, DrawListViewItemEventArgs e)
int width, height;
if (image.Width > image.Height)
{
width = (int) Math.Round(ImageSize.Width * _dpiScale);
width = imageSizeW;
height = (int) Math.Round(width * (image.Height / (double) image.Width));
}
else
{
height = (int) Math.Round(ImageSize.Height * _dpiScale);
height = imageSizeH;
width = (int) Math.Round(height * (image.Width / (double) image.Height));
}
var x = e.Bounds.Left + (e.Bounds.Width - width) / 2;
Expand All @@ -188,8 +193,9 @@ public Eto.Drawing.Size ImageSize
set
{
_imageSize = value;
WinFormsHacks.SetImageSize(_view.LargeImageList!,
new Size((int) Math.Round(_imageSize.Width * _dpiScale), (int) Math.Round(_imageSize.Height * _dpiScale)));
int w = _behavior.ScaleImageSize ? (int) Math.Round(_imageSize.Width * _dpiScale) : _imageSize.Width;
int h = _behavior.ScaleImageSize ? (int) Math.Round(_imageSize.Height * _dpiScale) : _imageSize.Height;
WinFormsHacks.SetImageSize(_view.LargeImageList!, new Size(w, h));
}
}

Expand Down
1 change: 1 addition & 0 deletions NAPS2.Lib/EtoForms/Widgets/ImageListViewBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public ImageListViewBehavior(UiThumbnailProvider thumbnailProvider,
ShowLabels = false;
ScrollOnDrag = true;
UseHandCursor = true;
ScaleImageSize = true;
}

public override bool ShowPageNumbers => _config.Get(c => c.ShowPageNumbers);
Expand Down
2 changes: 2 additions & 0 deletions NAPS2.Lib/EtoForms/Widgets/ListViewBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ protected ListViewBehavior(ColorScheme colorScheme)

public bool ShowLabels { get; protected set; }

public bool ScaleImageSize { get; protected set; }

public virtual bool ShowPageNumbers => false;

public bool ScrollOnDrag { get; protected set; }
Expand Down

0 comments on commit 3d9ff7c

Please sign in to comment.