image resizer and settings percentage unit (#8674)

This commit is contained in:
Davide Giacometti
2020-12-21 15:55:50 +01:00
committed by GitHub
parent 34ff670e5b
commit 11bdbaa07f
3 changed files with 51 additions and 6 deletions

View File

@@ -7,7 +7,6 @@ using System.ComponentModel;
using ImageResizer.Properties;
using ImageResizer.Test;
using Xunit;
using Xunit.Extensions;
namespace ImageResizer.Models
{
@@ -269,5 +268,41 @@ namespace ImageResizer.Models
Assert.Equal(50, result);
}
[Theory]
[InlineData(ResizeFit.Fill, ResizeUnit.Centimeter)]
[InlineData(ResizeFit.Fill, ResizeUnit.Inch)]
[InlineData(ResizeFit.Fill, ResizeUnit.Pixel)]
[InlineData(ResizeFit.Fit, ResizeUnit.Centimeter)]
[InlineData(ResizeFit.Fit, ResizeUnit.Inch)]
[InlineData(ResizeFit.Fit, ResizeUnit.Pixel)]
[InlineData(ResizeFit.Stretch, ResizeUnit.Centimeter)]
[InlineData(ResizeFit.Stretch, ResizeUnit.Inch)]
[InlineData(ResizeFit.Stretch, ResizeUnit.Percent)]
[InlineData(ResizeFit.Stretch, ResizeUnit.Pixel)]
public void HeightVisible(ResizeFit fit, ResizeUnit unit)
{
var size = new ResizeSize
{
Fit = fit,
Unit = unit,
};
Assert.True(size.ShowHeight);
}
[Theory]
[InlineData(ResizeFit.Fill, ResizeUnit.Percent)]
[InlineData(ResizeFit.Fit, ResizeUnit.Percent)]
public void HeightNotVisible(ResizeFit fit, ResizeUnit unit)
{
var size = new ResizeSize
{
Fit = fit,
Unit = unit,
};
Assert.False(size.ShowHeight);
}
}
}

View File

@@ -52,7 +52,15 @@ namespace ImageResizer.Models
public ResizeFit Fit
{
get => _fit;
set => Set(ref _fit, value);
set
{
var previousFit = _fit;
Set(ref _fit, value);
if (!Equals(previousFit, value))
{
UpdateShowHeight();
}
}
}
[JsonProperty(PropertyName = "width")]
@@ -112,7 +120,7 @@ namespace ImageResizer.Models
private void UpdateShowHeight()
{
ShowHeight = Unit != ResizeUnit.Percent;
ShowHeight = Fit == ResizeFit.Stretch || Unit != ResizeUnit.Percent;
}
private double ConvertToPixels(double value, ResizeUnit unit, int originalValue, double dpi)

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -70,7 +70,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
get
{
if (Unit == 2)
if (Unit == 2 && Fit != 2)
{
return 0;
}
@@ -85,7 +85,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
get
{
if (Unit == 2)
if (Unit == 2 && Fit != 2)
{
return false;
}
@@ -128,6 +128,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
_fit = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ExtraBoxOpacity));
OnPropertyChanged(nameof(EnableEtraBoxes));
}
}
}