Skip to content

Commit

Permalink
Fix decimal points and percentage sign % for height and width textb…
Browse files Browse the repository at this point in the history
…oxes
  • Loading branch information
Ruben2776 committed Jan 27, 2025
1 parent 0a63ee1 commit d88b273
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/PicView.Avalonia/Resizing/AspectRatioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public static void SetAspectRatioForTextBox(TextBox widthTextBox, TextBox height
var percentage = isWidth ? widthTextBox.Text.GetPercentage() : heightTextBox.Text.GetPercentage();
if (percentage > 0)
{
var newWidth = vm.PixelWidth * (percentage / 100);
var newHeight = vm.PixelHeight * (percentage / 100);
var newWidth = Convert.ToUInt32(vm.PixelWidth * (percentage / 100));
var newHeight = Convert.ToUInt32(vm.PixelHeight * (percentage / 100));

widthTextBox.Text = newWidth.ToString("# ", CultureInfo.CurrentCulture);
heightTextBox.Text = newHeight.ToString("# ", CultureInfo.CurrentCulture);
Expand Down Expand Up @@ -58,12 +58,12 @@ public static void SetAspectRatioForTextBox(TextBox widthTextBox, TextBox height

if (isWidth)
{
var newHeight = Math.Round(width / aspectRatio);
var newHeight = Convert.ToUInt32(Math.Round(width / aspectRatio));
heightTextBox.Text = newHeight.ToString(CultureInfo.CurrentCulture);
}
else
{
var newWidth = Math.Round(height * aspectRatio);
var newWidth = Convert.ToUInt32(Math.Round(height * aspectRatio));
widthTextBox.Text = newWidth.ToString(CultureInfo.CurrentCulture);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/PicView.Avalonia/Views/ExifView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ private void AdjustAspectRatio(TextBox sender)
{
return;
}
var aspectRatio = (double)vm.PixelWidth / vm.PixelHeight;
AspectRatioHelper.SetAspectRatioForTextBox(PixelWidthTextBox, PixelHeightTextBox, sender == PixelWidthTextBox,
aspectRatio, DataContext as MainViewModel);

if (!int.TryParse(PixelWidthTextBox.Text, out var width) || !int.TryParse(PixelHeightTextBox.Text, out var height))
{
return;
Expand All @@ -140,11 +144,7 @@ private void AdjustAspectRatio(TextBox sender)
SizeMpTextBox.Text = printSizes.SizeMp;

var gcd = ImageTitleFormatter.GCD(width, height);
var aspectRatio = (double)vm.PixelWidth / vm.PixelHeight;
AspectRatioTextBox.Text = AspectRatioHelper.GetFormattedAspectRatio(gcd, vm.PixelWidth, vm.PixelHeight);

AspectRatioHelper.SetAspectRatioForTextBox(PixelWidthTextBox, PixelHeightTextBox, sender == PixelWidthTextBox,
aspectRatio, DataContext as MainViewModel);
}

private static async Task DoResize(MainViewModel vm, bool isWidth, object width, object height)
Expand Down

0 comments on commit d88b273

Please sign in to comment.