From 1746100be1b6d17af904019b3da86eee4c86443d Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Thu, 1 Aug 2024 13:13:15 -0700 Subject: [PATCH] Change IListView.ImageSize type to Eto.Drawing.Size --- NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs | 2 +- NAPS2.Lib.Mac/EtoForms/Mac/MacListView.cs | 9 +++++---- .../EtoForms/WinForms/WinFormsListView.cs | 14 +++++++------- NAPS2.Lib/EtoForms/Ui/DesktopForm.cs | 2 +- NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs | 2 +- NAPS2.Lib/EtoForms/Ui/ScannerSharingForm.cs | 2 +- NAPS2.Lib/EtoForms/Widgets/IListView.cs | 3 +-- .../EtoForms/Widgets/ImageListViewBehavior.cs | 4 ++-- NAPS2.Lib/EtoForms/Widgets/ListViewBehavior.cs | 2 +- .../EtoForms/Widgets/ProfileListViewBehavior.cs | 2 +- .../Widgets/SharedDevicesListViewBehavior.cs | 2 +- NAPS2.Lib/Images/ThumbnailController.cs | 6 +++--- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs b/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs index 4d30f5064..98a4caee6 100644 --- a/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs +++ b/NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs @@ -80,7 +80,7 @@ public class GtkListView : IListView where T : notnull ItemClicked?.Invoke(this, EventArgs.Empty); } - public int ImageSize { get; set; } + public Eto.Drawing.Size ImageSize { get; set; } public ScrolledWindow NativeControl => _scrolledWindow; diff --git a/NAPS2.Lib.Mac/EtoForms/Mac/MacListView.cs b/NAPS2.Lib.Mac/EtoForms/Mac/MacListView.cs index aed73b3b5..da0b097ce 100644 --- a/NAPS2.Lib.Mac/EtoForms/Mac/MacListView.cs +++ b/NAPS2.Lib.Mac/EtoForms/Mac/MacListView.cs @@ -1,3 +1,4 @@ +using Eto.Drawing; using Eto.Forms; using Eto.Mac; using Eto.Mac.Forms.Menu; @@ -71,10 +72,10 @@ public class MacListView : NSCollectionViewDelegateFlowLayout, IListView w ItemClicked?.Invoke(this, EventArgs.Empty); } - public int ImageSize + public Size ImageSize { - get => (int) ((NSCollectionViewFlowLayout) _layout).ItemSize.Width; - set => ((NSCollectionViewFlowLayout) _layout).ItemSize = new CGSize(value, value); + get => Size.Truncate(((NSCollectionViewFlowLayout) _layout).ItemSize.ToEto()); + set => ((NSCollectionViewFlowLayout) _layout).ItemSize = new CGSize(value.Width, value.Height); } public Control Control => _panel; @@ -290,7 +291,7 @@ public class MacListView : NSCollectionViewDelegateFlowLayout, IListView w { var size = _behavior.GetImage(item, ImageSize).Size; var max = (double) Math.Max(size.Width, size.Height); - return new CGSize(size.Width * ImageSize / max, size.Height * ImageSize / max); + return new CGSize(size.Width * ImageSize.Width / max, size.Height * ImageSize.Width / max); } } diff --git a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsListView.cs b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsListView.cs index d8ec599aa..ce1f933f2 100644 --- a/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsListView.cs +++ b/NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsListView.cs @@ -91,8 +91,8 @@ public class WinFormsListView : IListView where T : notnull SizeF textSize = TextRenderer.MeasureText(label, _view.Font); int textOffset = (int) (textSize.Height + PageNumberTextPadding); - float scaleHeight = (float) (ImageSize - textOffset) / image.Height; - float scaleWidth = (float) ImageSize / image.Width; + float scaleHeight = (float) (ImageSize.Height - textOffset) / image.Height; + float scaleWidth = (float) ImageSize.Width / image.Width; float scale = Math.Min(scaleWidth, scaleHeight); int height = (int) Math.Round(image.Height * scale); @@ -145,12 +145,12 @@ public class WinFormsListView : IListView where T : notnull int width, height; if (image.Width > image.Height) { - width = ImageSize; + width = ImageSize.Width; height = (int) Math.Round(width * (image.Height / (double) image.Width)); } else { - height = ImageSize; + height = ImageSize.Height; width = (int) Math.Round(height * (image.Width / (double) image.Height)); } var x = e.Bounds.Left + (e.Bounds.Width - width) / 2; @@ -171,10 +171,10 @@ public class WinFormsListView : IListView where T : notnull } } - public int ImageSize + public Eto.Drawing.Size ImageSize { - get => _view.LargeImageList!.ImageSize.Width; - set => WinFormsHacks.SetImageSize(_view.LargeImageList!, new Size(value, value)); + get => _view.LargeImageList!.ImageSize.ToEto(); + set => WinFormsHacks.SetImageSize(_view.LargeImageList!, new Size(value.Width, value.Height)); } private void OnDragEnter(object? sender, DragEventArgs e) diff --git a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs index be5e0252e..93b107f08 100644 --- a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs @@ -80,7 +80,7 @@ public abstract class DesktopForm : EtoFormBase _listView.ItemClicked += ListViewItemClicked; _listView.Drop += ListViewDrop; _listView.SelectionChanged += ListViewSelectionChanged; - _listView.ImageSize = _thumbnailController.VisibleSize; + _listView.ImageSize = new Size(_thumbnailController.VisibleSize, _thumbnailController.VisibleSize); _listView.ContextMenu = _contextMenu; // TODO: Fix Eto so that we don't need to set an item here (otherwise the first time we right click nothing happens) diff --git a/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs b/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs index f8a2cd2e2..f5bd9926f 100644 --- a/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs @@ -93,7 +93,7 @@ public class ProfilesForm : EtoDialogBase profilesKsm.Assign("Mod+V", _pasteCommand); EtoPlatform.Current.HandleKeyDown(_listView.Control, profilesKsm.Perform); - _listView.ImageSize = 48; + _listView.ImageSize = new Size(48, 48); _listView.ItemClicked += ItemClicked; _listView.SelectionChanged += SelectionChanged; _listView.Drop += Drop; diff --git a/NAPS2.Lib/EtoForms/Ui/ScannerSharingForm.cs b/NAPS2.Lib/EtoForms/Ui/ScannerSharingForm.cs index 66704066d..e5221919b 100644 --- a/NAPS2.Lib/EtoForms/Ui/ScannerSharingForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/ScannerSharingForm.cs @@ -54,7 +54,7 @@ public class ScannerSharingForm : EtoDialogBase // TODO: Enable // _shareAsService.Checked = _osServiceManager.IsRegistered; // _shareAsService.CheckedChanged += ShareAsServiceCheckedChanged; - _listView.ImageSize = 48; + _listView.ImageSize = new Size(48, 48); _listView.SelectionChanged += SelectionChanged; _addCommand.Enabled = true; diff --git a/NAPS2.Lib/EtoForms/Widgets/IListView.cs b/NAPS2.Lib/EtoForms/Widgets/IListView.cs index ff35bb34d..437a5cf89 100644 --- a/NAPS2.Lib/EtoForms/Widgets/IListView.cs +++ b/NAPS2.Lib/EtoForms/Widgets/IListView.cs @@ -8,8 +8,7 @@ public interface IListView : Util.ISelectable where T : notnull ContextMenu? ContextMenu { get; set; } - // TODO: Maybe convert this back to a Size - int ImageSize { get; set; } + Eto.Drawing.Size ImageSize { get; set; } event EventHandler SelectionChanged; diff --git a/NAPS2.Lib/EtoForms/Widgets/ImageListViewBehavior.cs b/NAPS2.Lib/EtoForms/Widgets/ImageListViewBehavior.cs index 0698c4ae3..9a4295483 100644 --- a/NAPS2.Lib/EtoForms/Widgets/ImageListViewBehavior.cs +++ b/NAPS2.Lib/EtoForms/Widgets/ImageListViewBehavior.cs @@ -24,9 +24,9 @@ public class ImageListViewBehavior : ListViewBehavior public override bool ShowPageNumbers => _config.Get(c => c.ShowPageNumbers); - public override Image GetImage(UiImage item, int imageSize) + public override Image GetImage(UiImage item, Size imageSize) { - using var thumbnail = _thumbnailProvider.GetThumbnail(item, imageSize); + using var thumbnail = _thumbnailProvider.GetThumbnail(item, imageSize.Width); return thumbnail.ToEtoImage(); } diff --git a/NAPS2.Lib/EtoForms/Widgets/ListViewBehavior.cs b/NAPS2.Lib/EtoForms/Widgets/ListViewBehavior.cs index e3b3e9758..afd6042a2 100644 --- a/NAPS2.Lib/EtoForms/Widgets/ListViewBehavior.cs +++ b/NAPS2.Lib/EtoForms/Widgets/ListViewBehavior.cs @@ -26,7 +26,7 @@ public abstract class ListViewBehavior where T : notnull public virtual string GetLabel(T item) => throw new NotSupportedException(); - public virtual Image GetImage(T item, int imageSize) => throw new NotSupportedException(); + public virtual Image GetImage(T item, Size imageSize) => throw new NotSupportedException(); public virtual bool AllowDragDrop => false; diff --git a/NAPS2.Lib/EtoForms/Widgets/ProfileListViewBehavior.cs b/NAPS2.Lib/EtoForms/Widgets/ProfileListViewBehavior.cs index 2a45e7b6f..821846863 100644 --- a/NAPS2.Lib/EtoForms/Widgets/ProfileListViewBehavior.cs +++ b/NAPS2.Lib/EtoForms/Widgets/ProfileListViewBehavior.cs @@ -20,7 +20,7 @@ public class ProfileListViewBehavior : ListViewBehavior public override string GetLabel(ScanProfile item) => item.DisplayName ?? ""; - public override Image GetImage(ScanProfile item, int imageSize) + public override Image GetImage(ScanProfile item, Size imageSize) { if (item.IsDefault && item.IsLocked) { diff --git a/NAPS2.Lib/EtoForms/Widgets/SharedDevicesListViewBehavior.cs b/NAPS2.Lib/EtoForms/Widgets/SharedDevicesListViewBehavior.cs index 65b369816..5907db588 100644 --- a/NAPS2.Lib/EtoForms/Widgets/SharedDevicesListViewBehavior.cs +++ b/NAPS2.Lib/EtoForms/Widgets/SharedDevicesListViewBehavior.cs @@ -14,5 +14,5 @@ public class SharedDevicesListViewBehavior : ListViewBehavior public override string GetLabel(SharedDevice item) => item.Name; - public override Image GetImage(SharedDevice item, int imageSize) => Icons.scanner_wireless.ToEtoImage(); + public override Image GetImage(SharedDevice item, Size imageSize) => Icons.scanner_wireless.ToEtoImage(); } \ No newline at end of file diff --git a/NAPS2.Lib/Images/ThumbnailController.cs b/NAPS2.Lib/Images/ThumbnailController.cs index aaaa1e2d3..9191467a0 100644 --- a/NAPS2.Lib/Images/ThumbnailController.cs +++ b/NAPS2.Lib/Images/ThumbnailController.cs @@ -1,4 +1,4 @@ -using NAPS2.EtoForms; +using Eto.Drawing; using NAPS2.EtoForms.Widgets; namespace NAPS2.Images; @@ -51,7 +51,7 @@ public class ThumbnailController : IDisposable { var thumbnailSize = ThumbnailSizes.Validate(value); _config.User.Set(c => c.ThumbnailSize, thumbnailSize); - if (ListView?.ImageSize == thumbnailSize) + if (ListView?.ImageSize.Width == thumbnailSize) { // Same size so no resizing needed return; @@ -76,7 +76,7 @@ public class ThumbnailController : IDisposable if (ListView != null) { // Adjust the visible thumbnail display with the new size - ListView.ImageSize = VisibleSize; + ListView.ImageSize = new Size(VisibleSize, VisibleSize); ListView.RegenerateImages(); }