From 5d39501707df1cfbf2b4b33e847e875e5698c61f Mon Sep 17 00:00:00 2001 From: DB p Date: Sat, 12 Apr 2025 17:55:38 +0900 Subject: [PATCH] Change badge position logic --- .../Converters/BadgePositionConverter.cs | 32 +++++++++++++++++++ .../Converters/SizeRatioConverter.cs | 27 ++++++++++++++++ Flow.Launcher/ResultListBox.xaml | 12 +++++-- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 Flow.Launcher/Converters/BadgePositionConverter.cs create mode 100644 Flow.Launcher/Converters/SizeRatioConverter.cs diff --git a/Flow.Launcher/Converters/BadgePositionConverter.cs b/Flow.Launcher/Converters/BadgePositionConverter.cs new file mode 100644 index 000000000..66a7446f2 --- /dev/null +++ b/Flow.Launcher/Converters/BadgePositionConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace Flow.Launcher.Converters; + +public class BadgePositionConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is double actualWidth && parameter is string param) + { + double offset = actualWidth / 2 - 8; + + if (param == "1") // X-Offset + { + return offset + 2; + } + else if (param == "2") // Y-Offset + { + return offset + 2; + } + } + + return 0.0; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } +} diff --git a/Flow.Launcher/Converters/SizeRatioConverter.cs b/Flow.Launcher/Converters/SizeRatioConverter.cs new file mode 100644 index 000000000..e61eeaf9b --- /dev/null +++ b/Flow.Launcher/Converters/SizeRatioConverter.cs @@ -0,0 +1,27 @@ +using System.Windows.Data; +using System; +using System.Globalization; +using System.Windows; + +namespace Flow.Launcher.Converters; + +public class SizeRatioConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is double size && parameter is string ratioString) + { + if (double.TryParse(ratioString, NumberStyles.Any, CultureInfo.InvariantCulture, out double ratio)) + { + return size * ratio; + } + } + + return 0.0; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotSupportedException(); + } +} diff --git a/Flow.Launcher/ResultListBox.xaml b/Flow.Launcher/ResultListBox.xaml index 8231027f4..4141d9e2f 100644 --- a/Flow.Launcher/ResultListBox.xaml +++ b/Flow.Launcher/ResultListBox.xaml @@ -32,6 +32,8 @@ + + @@ -136,11 +138,15 @@ + Visibility="{Binding ShowBadge}"> + + + +