Skip to content

Commit

Permalink
Use high-dpi versions of more icons
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Sep 2, 2024
1 parent e258df0 commit 802656c
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 55 deletions.
12 changes: 9 additions & 3 deletions NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsEtoPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,16 @@ public override void SetImageSize(ButtonMenuItem menuItem, int size)
handler.ImageSize = size;
}

public override void SetImageSize(ButtonToolItem menuItem, int size)
public override void SetImageSize(ToolItem menuItem, int size)
{
var handler = (ButtonToolItemHandler) menuItem.Handler;
handler.ImageSize = size;
if (menuItem.Handler is ButtonToolItemHandler buttonHandler)
{
buttonHandler.ImageSize = size;
}
if (menuItem.Handler is DropDownToolItemHandler dropDownHandler)
{
dropDownHandler.ImageSize = size;
}
}

public override void ConfigureZoomButton(Button button, string icon)
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.Lib/EtoForms/EtoPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public virtual void SetImageSize(ButtonMenuItem menuItem, int size)
{
}

public virtual void SetImageSize(ButtonToolItem toolItem, int size)
public virtual void SetImageSize(ToolItem toolItem, int size)
{
}
}
12 changes: 8 additions & 4 deletions NAPS2.Lib/EtoForms/Layout/C.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,18 @@ public static LayoutElement None()
return new SkipLayoutElement();
}

public static Button IconButton(Image icon, Action onClick)
public static Button IconButton(string iconName, Action onClick)
{
var button = new Button
{
Image = icon,
ImagePosition = ButtonImagePosition.Overlay,
MinimumSize = new Size(icon.Width + 30, 0)
ImagePosition = ButtonImagePosition.Overlay
};
EtoPlatform.Current.AttachDpiDependency(button, scale =>
{
var icon = EtoPlatform.Current.IconProvider.GetIcon(iconName, scale)!;
button.Image = icon;
button.MinimumSize = new Size(icon.Width + 30, 0);
});
button.Click += (_, _) => onClick();
return button;
}
Expand Down
4 changes: 2 additions & 2 deletions NAPS2.Lib/EtoForms/Ui/BatchPromptForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class BatchPromptForm : EtoDialogBase
{
private readonly Button _scanButton;

public BatchPromptForm(Naps2Config config, IIconProvider iconProvider) : base(config)
public BatchPromptForm(Naps2Config config) : base(config)
{
var scanNextCommand = new ActionCommand(() =>
{
Expand All @@ -16,7 +16,7 @@ public BatchPromptForm(Naps2Config config, IIconProvider iconProvider) : base(co
})
{
Text = UiStrings.Scan,
Image = iconProvider.GetIcon("control_play_blue_small")
IconName = "control_play_blue_small"
};
_scanButton = C.Button(scanNextCommand, ButtonImagePosition.Left);
DefaultButton = _scanButton;
Expand Down
4 changes: 2 additions & 2 deletions NAPS2.Lib/EtoForms/Ui/BlackWhiteForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Eto.Drawing;
using NAPS2.EtoForms.Widgets;

namespace NAPS2.EtoForms.Ui;
Expand All @@ -14,7 +13,8 @@ public BlackWhiteForm(Naps2Config config, UiImageList imageList, ThumbnailContro
IconName = "contrast_high_small";
Title = UiStrings.BlackAndWhite;

_thresholdSlider.Icon = iconProvider.GetIcon("contrast_high_small");
EtoPlatform.Current.AttachDpiDependency(this,
scale => _thresholdSlider.Icon = iconProvider.GetIcon("contrast_high_small", scale));
Sliders = [_thresholdSlider];
// BlackWhiteTransform is not commutative with scaling
CanScaleWorkingImage = false;
Expand Down
8 changes: 5 additions & 3 deletions NAPS2.Lib/EtoForms/Ui/BrightContForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Eto.Drawing;
using NAPS2.EtoForms.Widgets;

namespace NAPS2.EtoForms.Ui;
Expand All @@ -15,8 +14,11 @@ public BrightContForm(Naps2Config config, UiImageList imageList, ThumbnailContro
IconName = "contrast_with_sun_small";
Title = UiStrings.BrightnessContrast;

_brightnessSlider.Icon = iconProvider.GetIcon("weather_sun_small");
_contrastSlider.Icon = iconProvider.GetIcon("contrast_small");
EtoPlatform.Current.AttachDpiDependency(this, scale =>
{
_brightnessSlider.Icon = iconProvider.GetIcon("weather_sun_small", scale);
_contrastSlider.Icon = iconProvider.GetIcon("contrast_small", scale);
});
Sliders = [_brightnessSlider, _contrastSlider];
}

Expand Down
4 changes: 2 additions & 2 deletions NAPS2.Lib/EtoForms/Ui/ChooseDeviceForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ protected override void BuildLayout()
L.Row(
[
..driverElements,
C.IconButton(_iconProvider.GetIcon("large_tiles_small")!, () => SetListView(false))
C.IconButton("large_tiles_small", () => SetListView(false))
.Visible(_textListVis).Width(40),
C.IconButton(_iconProvider.GetIcon("text_align_justify_small")!, () => SetListView(true))
C.IconButton("text_align_justify_small", () => SetListView(true))
.Visible(!_textListVis).Width(40)
]
),
Expand Down
24 changes: 11 additions & 13 deletions NAPS2.Lib/EtoForms/Ui/CombineForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace NAPS2.EtoForms.Ui;

public class CombineForm : ImageFormBase
{
private readonly IIconProvider _iconProvider;
private readonly ScanningContext _scanningContext;

private readonly LayoutVisibility _horizontalOrientationVis = new(false);
Expand All @@ -16,13 +15,12 @@ public class CombineForm : ImageFormBase
private double _vOffset = 0.5;

public CombineForm(Naps2Config config, UiImageList imageList, ThumbnailController thumbnailController,
IIconProvider iconProvider, ScanningContext scanningContext) :
ScanningContext scanningContext) :
base(config, imageList, thumbnailController)
{
Title = UiStrings.Combine;
IconName = "combine_small";

_iconProvider = iconProvider;
_scanningContext = scanningContext;
}

Expand All @@ -38,25 +36,25 @@ protected override LayoutElement CreateControls()
C.Filler(),
L.Row(
L.Row(
C.IconButton(_iconProvider.GetIcon("shape_align_left_small")!, () => SetHOffset(0)),
C.IconButton(_iconProvider.GetIcon("shape_align_center_small")!, () => SetHOffset(0.5)),
C.IconButton(_iconProvider.GetIcon("shape_align_right_small")!, () => SetHOffset(1.0))
C.IconButton("shape_align_left_small", () => SetHOffset(0)),
C.IconButton("shape_align_center_small", () => SetHOffset(0.5)),
C.IconButton("shape_align_right_small", () => SetHOffset(1.0))
).Visible(_alignVis),
C.IconButton(_iconProvider.GetIcon("combine_hor_small")!,
C.IconButton("combine_hor_small",
() => SetOrientation(CombineOrientation.Horizontal))
.Padding(left: 20),
C.IconButton(_iconProvider.GetIcon("switch_ver_small")!, SwapImages)
C.IconButton("switch_ver_small", SwapImages)
).Visible(!_horizontalOrientationVis),
L.Row(
L.Row(
C.IconButton(_iconProvider.GetIcon("shape_align_top_small")!, () => SetVOffset(0)),
C.IconButton(_iconProvider.GetIcon("shape_align_middle_small")!, () => SetVOffset(0.5)),
C.IconButton(_iconProvider.GetIcon("shape_align_bottom_small")!, () => SetVOffset(1.0))
C.IconButton("shape_align_top_small", () => SetVOffset(0)),
C.IconButton("shape_align_middle_small", () => SetVOffset(0.5)),
C.IconButton("shape_align_bottom_small", () => SetVOffset(1.0))
).Visible(_alignVis),
C.IconButton(_iconProvider.GetIcon("combine_ver_small")!,
C.IconButton("combine_ver_small",
() => SetOrientation(CombineOrientation.Vertical))
.Padding(left: 20),
C.IconButton(_iconProvider.GetIcon("switch_hor_small")!, SwapImages)
C.IconButton("switch_hor_small", SwapImages)
).Visible(_horizontalOrientationVis),
C.Filler()
);
Expand Down
8 changes: 5 additions & 3 deletions NAPS2.Lib/EtoForms/Ui/HueSatForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Eto.Drawing;
using NAPS2.EtoForms.Widgets;

namespace NAPS2.EtoForms.Ui;
Expand All @@ -15,8 +14,11 @@ public HueSatForm(Naps2Config config, UiImageList imageList, ThumbnailController
IconName = "color_management_small";
Title = UiStrings.HueSaturation;

_hueSlider.Icon = iconProvider.GetIcon("color_wheel_small");
_saturationSlider.Icon = iconProvider.GetIcon("color_gradient_small");
EtoPlatform.Current.AttachDpiDependency(this, scale =>
{
_hueSlider.Icon = iconProvider.GetIcon("color_wheel_small", scale);
_saturationSlider.Icon = iconProvider.GetIcon("color_gradient_small", scale);
});
Sliders = [_hueSlider, _saturationSlider];
}

Expand Down
17 changes: 9 additions & 8 deletions NAPS2.Lib/EtoForms/Ui/PreviewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ protected virtual void CreateToolbar()
MakeToolButton(ZoomOutCommand),
_zoomPercentButton,
new SeparatorToolItem(),
new DropDownToolItem
WithToolItemIcon(new DropDownToolItem
{
Image = _iconProvider.GetIcon("arrow_rotate_anticlockwise_small"),
ToolTip = UiStrings.Rotate,
Items =
{
Expand All @@ -220,7 +219,7 @@ protected virtual void CreateToolbar()
Commands.Deskew,
Commands.CustomRotate
}
},
}, "arrow_rotate_anticlockwise_small"),
MakeToolButton(Commands.Crop),
MakeToolButton(Commands.BrightCont),
MakeToolButton(Commands.HueSat),
Expand All @@ -247,19 +246,21 @@ protected virtual void CreateToolbar()
}
}

private ToolItem MakeToolButton(ActionCommand command, string? iconName = null)
{
var toolItem = new ButtonToolItem
private ToolItem MakeToolButton(ActionCommand command, string? iconName = null) =>
WithToolItemIcon(new ButtonToolItem
{
Command = command,
Text = null,
ToolTip = command.Text
};
}, iconName ?? command.IconName!);

private ToolItem WithToolItemIcon(ToolItem toolItem, string iconName)
{
EtoPlatform.Current.AttachDpiDependency(this,
scale =>
{
EtoPlatform.Current.SetImageSize(toolItem, (int) (16 * scale));
toolItem.Image = EtoPlatform.Current.IconProvider.GetIcon(iconName ?? command.IconName!, scale);
toolItem.Image = EtoPlatform.Current.IconProvider.GetIcon(iconName, scale);
});
return toolItem;
}
Expand Down
3 changes: 2 additions & 1 deletion NAPS2.Lib/EtoForms/Ui/RotateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public RotateForm(Naps2Config config, UiImageList imageList, ThumbnailController
Title = UiStrings.Rotate;
IconName = "arrow_rotate_anticlockwise_small";

_angleSlider.Icon = iconProvider.GetIcon("arrow_rotate_anticlockwise_small");
EtoPlatform.Current.AttachDpiDependency(this,
scale => _angleSlider.Icon = iconProvider.GetIcon("arrow_rotate_anticlockwise_small", scale));
Sliders = [_angleSlider];
Overlay.MouseDown += Overlay_MouseDown;
Overlay.MouseMove += Overlay_MouseMove;
Expand Down
3 changes: 2 additions & 1 deletion NAPS2.Lib/EtoForms/Ui/SharpenForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public SharpenForm(Naps2Config config, UiImageList imageList, ThumbnailControlle
IconName = "sharpen_small";
Title = UiStrings.Sharpen;

_sharpenSlider.Icon = iconProvider.GetIcon("sharpen_small");
EtoPlatform.Current.AttachDpiDependency(this,
scale => _sharpenSlider.Icon = iconProvider.GetIcon("sharpen_small", scale));
Sliders = [_sharpenSlider];
}

Expand Down
9 changes: 3 additions & 6 deletions NAPS2.Lib/EtoForms/Ui/SplitForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,16 @@ public class SplitForm : UnaryImageFormBase
private bool _dragging;
private SplitOrientation _orientation;

public SplitForm(Naps2Config config, UiImageList imageList, ThumbnailController thumbnailController,
IIconProvider iconProvider, ColorScheme colorScheme) :
public SplitForm(Naps2Config config, UiImageList imageList, ThumbnailController thumbnailController, ColorScheme colorScheme) :
base(config, imageList, thumbnailController)
{
Title = UiStrings.Split;
IconName = "split_small";

_colorScheme = colorScheme;

_vSplit = C.IconButton(iconProvider.GetIcon("split_ver_small")!,
() => SetOrientation(SplitOrientation.Vertical));
_hSplit = C.IconButton(iconProvider.GetIcon("split_hor_small")!,
() => SetOrientation(SplitOrientation.Horizontal));
_vSplit = C.IconButton("split_ver_small", () => SetOrientation(SplitOrientation.Vertical));
_hSplit = C.IconButton("split_hor_small", () => SetOrientation(SplitOrientation.Horizontal));
Overlay.MouseDown += Overlay_MouseDown;
Overlay.MouseMove += Overlay_MouseMove;
Overlay.MouseUp += Overlay_MouseUp;
Expand Down
20 changes: 14 additions & 6 deletions NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class SliderWithTextBox

private readonly Constraints _constraints;
private readonly Slider _slider = new();
private readonly ImageView _imageView = new();
private readonly LayoutVisibility? _imageVis = new(false);
private readonly TextBox _textBox;

private int _valueCache;
Expand Down Expand Up @@ -78,7 +80,15 @@ public bool Enabled
}
}

public Image? Icon { get; set; }
public Image? Icon
{
get => _imageView.Image;
set
{
_imageView.Image = value;
_imageVis.IsVisible = value != null;

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Dereference of a possibly null reference.

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Dereference of a possibly null reference.

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04)

Dereference of a possibly null reference.

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04)

Dereference of a possibly null reference.

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04)

Dereference of a possibly null reference.

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (macos-14)

Dereference of a possibly null reference.

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (macos-14)

Dereference of a possibly null reference.

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (macos-14)

Dereference of a possibly null reference.

Check warning on line 89 in NAPS2.Lib/EtoForms/Widgets/SliderWithTextBox.cs

View workflow job for this annotation

GitHub Actions / build (macos-14)

Dereference of a possibly null reference.
}
}

public static implicit operator LayoutElement(SliderWithTextBox control)
{
Expand All @@ -90,11 +100,9 @@ public static implicit operator LayoutElement(SliderWithTextBox control)
public LayoutRow AsControl()
{
return L.Row(
Icon != null
? new ImageView { Image = Icon }
.Align(EtoPlatform.Current.IsWinForms ? LayoutAlignment.Leading : LayoutAlignment.Center)
.Padding(top: 2, bottom: 2)
: C.None(),
_imageView
.Align(EtoPlatform.Current.IsWinForms ? LayoutAlignment.Leading : LayoutAlignment.Center)
.Padding(top: 2, bottom: 2).Visible(_imageVis),
_slider.Scale(),
_textBox.Width(EtoPlatform.Current.IsGtk ? 50 : 40)
.Align(EtoPlatform.Current.IsWinForms ? LayoutAlignment.Leading : LayoutAlignment.Center)
Expand Down

0 comments on commit 802656c

Please sign in to comment.