handling percentage unit (#8567)

This commit is contained in:
Davide Giacometti
2020-12-15 20:21:27 +01:00
committed by GitHub
parent 764c01befb
commit 8007c0af3f
2 changed files with 12 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) Brice Lambson // Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license. // The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/ // See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
@@ -52,14 +52,7 @@ namespace ImageResizer.Models
public ResizeFit Fit public ResizeFit Fit
{ {
get => _fit; get => _fit;
set set => Set(ref _fit, value);
{
Set(ref _fit, value);
if (!Equals(_fit, value))
{
UpdateShowHeight();
}
}
} }
[JsonProperty(PropertyName = "width")] [JsonProperty(PropertyName = "width")]
@@ -77,7 +70,10 @@ namespace ImageResizer.Models
} }
public bool ShowHeight public bool ShowHeight
=> _showHeight; {
get => _showHeight;
set => Set(ref _showHeight, value);
}
public bool HasAuto public bool HasAuto
=> Width == 0 || Height == 0; => Width == 0 || Height == 0;
@@ -88,8 +84,9 @@ namespace ImageResizer.Models
get => _unit; get => _unit;
set set
{ {
var previousUnit = _unit;
Set(ref _unit, value); Set(ref _unit, value);
if (!Equals(_unit, value)) if (!Equals(previousUnit, value))
{ {
UpdateShowHeight(); UpdateShowHeight();
} }
@@ -114,9 +111,9 @@ namespace ImageResizer.Models
: text; : text;
private void UpdateShowHeight() private void UpdateShowHeight()
=> Set( {
ref _showHeight, ShowHeight = Unit != ResizeUnit.Percent;
Fit == ResizeFit.Stretch || Unit != ResizeUnit.Percent); }
private double ConvertToPixels(double value, ResizeUnit unit, int originalValue, double dpi) private double ConvertToPixels(double value, ResizeUnit unit, int originalValue, double dpi)
{ {

View File

@@ -11,6 +11,7 @@
Name="_this" Name="_this"
ResizeMode="NoResize" ResizeMode="NoResize"
SizeToContent="WidthAndHeight" SizeToContent="WidthAndHeight"
MinWidth="485"
Title="{x:Static p:Resources.ImageResizer}" Title="{x:Static p:Resources.ImageResizer}"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
ui:WindowHelper.UseModernWindowStyle="True" ui:WindowHelper.UseModernWindowStyle="True"