Skip to content

Commit

Permalink
image resizer and settings percentage unit (#8674)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed Dec 21, 2020
1 parent 34ff670 commit 11bdbaa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
37 changes: 36 additions & 1 deletion src/modules/imageresizer/tests/Models/ResizeSizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using ImageResizer.Properties;
using ImageResizer.Test;
using Xunit;
using Xunit.Extensions;

namespace ImageResizer.Models
{
Expand Down Expand Up @@ -269,5 +268,41 @@ public void ConvertToPixelsWorksWhenPixels()

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);
}
}
}
12 changes: 10 additions & 2 deletions src/modules/imageresizer/ui/Models/ResizeSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public virtual string Name
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")]
Expand Down Expand Up @@ -112,7 +120,7 @@ private static string ReplaceTokens(string text)

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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -70,7 +70,7 @@ public int ExtraBoxOpacity
{
get
{
if (Unit == 2)
if (Unit == 2 && Fit != 2)
{
return 0;
}
Expand All @@ -85,7 +85,7 @@ public bool EnableEtraBoxes
{
get
{
if (Unit == 2)
if (Unit == 2 && Fit != 2)
{
return false;
}
Expand Down Expand Up @@ -128,6 +128,8 @@ public int Fit
{
_fit = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ExtraBoxOpacity));
OnPropertyChanged(nameof(EnableEtraBoxes));
}
}
}
Expand Down

0 comments on commit 11bdbaa

Please sign in to comment.