mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Change badge position logic
This commit is contained in:
parent
02b53732c2
commit
5d39501707
3 changed files with 68 additions and 3 deletions
32
Flow.Launcher/Converters/BadgePositionConverter.cs
Normal file
32
Flow.Launcher/Converters/BadgePositionConverter.cs
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
27
Flow.Launcher/Converters/SizeRatioConverter.cs
Normal file
27
Flow.Launcher/Converters/SizeRatioConverter.cs
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,8 @@
|
|||
<!-- IsSynchronizedWithCurrentItem: http://stackoverflow.com/a/7833798/2833083 -->
|
||||
|
||||
<ListBox.Resources>
|
||||
<converter:SizeRatioConverter x:Key="SizeRatioConverter" />
|
||||
<converter:BadgePositionConverter x:Key="BadgePositionConverter" />
|
||||
<converter:IconRadiusConverter x:Key="IconRadiusConverter" />
|
||||
<converter:DiameterToCenterPointConverter x:Key="DiameterToCenterPointConverter" />
|
||||
</ListBox.Resources>
|
||||
|
|
@ -136,11 +138,15 @@
|
|||
|
||||
<Image
|
||||
x:Name="BadgeIcon"
|
||||
Width="{Binding ElementName=ImageIcon, Path=ActualWidth}"
|
||||
Height="{Binding ElementName=ImageIcon, Path=ActualHeight}"
|
||||
Width="{Binding ElementName=ImageIcon, Path=ActualWidth, Converter={StaticResource SizeRatioConverter}, ConverterParameter=0.6}"
|
||||
Height="{Binding ElementName=ImageIcon, Path=ActualWidth, Converter={StaticResource SizeRatioConverter}, ConverterParameter=0.6}"
|
||||
RenderOptions.BitmapScalingMode="HighQuality"
|
||||
Source="{Binding BadgeImage, TargetNullValue={x:Null}}"
|
||||
Visibility="{Binding ShowBadge}" />
|
||||
Visibility="{Binding ShowBadge}">
|
||||
<Image.RenderTransform>
|
||||
<TranslateTransform X="{Binding ElementName=ImageIcon, Path=ActualWidth, Converter={StaticResource BadgePositionConverter}, ConverterParameter=1}" Y="{Binding ElementName=ImageIcon, Path=ActualWidth, Converter={StaticResource BadgePositionConverter}, ConverterParameter=2}" />
|
||||
</Image.RenderTransform>
|
||||
</Image>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue