Skip to content

Commit

Permalink
Add percentage suggestion - batch resize #165
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Dec 3, 2024
1 parent e385c21 commit 5e422b3
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 8 deletions.
90 changes: 90 additions & 0 deletions src/PicView.Avalonia/Converters/IndexToPercentageSizeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Globalization;
using Avalonia.Data;
using Avalonia.Data.Converters;

namespace PicView.Avalonia.Converters;

public class IndexToPercentageSizeConverter: IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (!int.TryParse(value?.ToString(), out var index) || !int.TryParse(parameter?.ToString(), out var parameterIndex))
{
return BindingOperations.DoNothing;
}

switch (index)
{
case 1:
return 30;

case 2 when parameterIndex is 1:
return 30;
case 2:
return 50;

case 3 when parameterIndex is 1:
return 70;
case 3 when parameterIndex is 2:
return 50;
case 3:
return 30;

case 4 when parameterIndex is 1:
return 70;
case 4 when parameterIndex is 2:
return 50;
case 4 when parameterIndex is 3:
return 30;
case 4:
return 15;

case 5 when parameterIndex is 1:
return 80;
case 5 when parameterIndex is 2:
return 70;
case 5 when parameterIndex is 3:
return 50;
case 5when parameterIndex is 4:
return 30;
case 5:
return 15;


case 6 when parameterIndex is 1:
return 80;
case 6 when parameterIndex is 2:
return 70;
case 6 when parameterIndex is 3:
return 60;
case 6 when parameterIndex is 4:
return 50;
case 6 when parameterIndex is 5:
return 40;
case 6:
return 30;

case 7 when parameterIndex is 1:
return 85;
case 7 when parameterIndex is 2:
return 75;
case 7 when parameterIndex is 3:
return 65;
case 7 when parameterIndex is 4:
return 50;
case 7 when parameterIndex is 5:
return 40;
case 7 when parameterIndex is 6:
return 30;
case 7:
return 20;
default:
return BindingOperations.DoNothing;
}
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return BindingOperations.DoNothing;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Globalization;
using Avalonia.Data;
using Avalonia.Data.Converters;
using PicView.Core.Localization;

namespace PicView.Avalonia.Converters;

Expand All @@ -16,7 +17,7 @@ public object Convert(object? value, Type targetType, object? parameter, Culture
switch (index)
{
case 1:
return "/small";
return TranslationHelper.Translation.Thumbnail ?? "Thumb";

case 2 when parameterIndex is 1:
return "/medium";
Expand Down
15 changes: 8 additions & 7 deletions src/PicView.Avalonia/Views/BatchResizeView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<UserControl.Resources>
<converters:IndexBiggerThanBooleanConverter x:Key="IndexBiggerThanBooleanConverter" />
<converters:IndexToStringSizeConverter x:Key="IndexToStringSizeConverter" />
<converters:IndexToPercentageSizeConverter x:Key="IndexToPercentageSizeConverter" />
</UserControl.Resources>
<StackPanel>

Expand Down Expand Up @@ -487,7 +488,7 @@

<customControls:FuncTextBox
Classes="hover TStyle"
Text="80"
Text="{Binding SelectedIndex, ElementName=ThumbnailsComboBox, ConverterParameter=1, Converter={StaticResource IndexToPercentageSizeConverter}}"
Width="200"
x:Name="Thumb1ValueBox" />

Expand Down Expand Up @@ -552,7 +553,7 @@

<customControls:FuncTextBox
Classes="hover TStyle"
Text="80"
Text="{Binding SelectedIndex, ElementName=ThumbnailsComboBox, ConverterParameter=2, Converter={StaticResource IndexToPercentageSizeConverter}}"
Width="200"
x:Name="Thumb2ValueBox" />

Expand Down Expand Up @@ -617,7 +618,7 @@

<customControls:FuncTextBox
Classes="hover TStyle"
Text="80"
Text="{Binding SelectedIndex, ElementName=ThumbnailsComboBox, ConverterParameter=3, Converter={StaticResource IndexToPercentageSizeConverter}}"
Width="200"
x:Name="Thumb3ValueBox" />

Expand Down Expand Up @@ -682,7 +683,7 @@

<customControls:FuncTextBox
Classes="hover TStyle"
Text="80"
Text="{Binding SelectedIndex, ElementName=ThumbnailsComboBox, ConverterParameter=4, Converter={StaticResource IndexToPercentageSizeConverter}}"
Width="200"
x:Name="Thumb4ValueBox" />

Expand Down Expand Up @@ -746,7 +747,7 @@

<customControls:FuncTextBox
Classes="hover TStyle"
Text="80"
Text="{Binding SelectedIndex, ElementName=ThumbnailsComboBox, ConverterParameter=5, Converter={StaticResource IndexToPercentageSizeConverter}}"
Width="200"
x:Name="Thumb5ValueBox" />

Expand Down Expand Up @@ -810,7 +811,7 @@

<customControls:FuncTextBox
Classes="hover TStyle"
Text="80"
Text="{Binding SelectedIndex, ElementName=ThumbnailsComboBox, ConverterParameter=6, Converter={StaticResource IndexToPercentageSizeConverter}}"
Width="200"
x:Name="Thumb6ValueBox" />

Expand Down Expand Up @@ -875,7 +876,7 @@

<customControls:FuncTextBox
Classes="hover TStyle"
Text="80"
Text="{Binding SelectedIndex, ElementName=ThumbnailsComboBox, ConverterParameter=7, Converter={StaticResource IndexToPercentageSizeConverter}}"
Width="200"
x:Name="Thumb7ValueBox" />

Expand Down

0 comments on commit 5e422b3

Please sign in to comment.