Skip to content

Commit 9d04745

Browse files
committed
Refactored to describe via discrete speed settings
Can now select either Slow, Medium or Fast, or a user-defined Custom speed for the animation. Additionally, the speed is hidden when animations are disabled.
1 parent bb7023a commit 9d04745

File tree

5 files changed

+119
-53
lines changed

5 files changed

+119
-53
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public string Theme
5353
public string ResultFontStretch { get; set; }
5454
public bool UseGlyphIcons { get; set; } = true;
5555
public bool UseAnimation { get; set; } = true;
56-
public int AnimationLength { get; set; } = 360;
5756
public bool UseSound { get; set; } = true;
5857
public bool UseClock { get; set; } = true;
5958
public bool UseDate { get; set; } = false;
@@ -255,6 +254,10 @@ public bool HideNotifyIcon
255254
[JsonConverter(typeof(JsonStringEnumConverter))]
256255
public LastQueryMode LastQueryMode { get; set; } = LastQueryMode.Selected;
257256

257+
[JsonConverter(typeof(JsonStringEnumConverter))]
258+
public AnimationSpeeds AnimationSpeed { get; set; } = AnimationSpeeds.Medium;
259+
public int CustomAnimationLength { get; set; } = 360;
260+
258261

259262
// This needs to be loaded last by staying at the bottom
260263
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();
@@ -291,4 +294,12 @@ public enum SearchWindowAligns
291294
RightTop,
292295
Custom
293296
}
297+
298+
public enum AnimationSpeeds
299+
{
300+
Slow,
301+
Medium,
302+
Fast,
303+
Custom
304+
}
294305
}

Flow.Launcher/Languages/en.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,12 @@
157157
<system:String x:Key="SoundEffectTip">Play a small sound when the search window opens</system:String>
158158
<system:String x:Key="Animation">Animation</system:String>
159159
<system:String x:Key="AnimationTip">Use Animation in UI</system:String>
160-
<system:String x:Key="animationLength">Animation Length (ms)</system:String>
161-
<system:String x:Key="animationLengthToolTip">The length of the UI animation in milliseconds</system:String>
160+
<system:String x:Key="AnimationSpeed">Animation Speed</system:String>
161+
<system:String x:Key="AnimationSpeedTip">The speed of the UI animation</system:String>
162+
<system:String x:Key="AnimationSpeedSlow">Slow</system:String>
163+
<system:String x:Key="AnimationSpeedMedium">Medium</system:String>
164+
<system:String x:Key="AnimationSpeedFast">Fast</system:String>
165+
<system:String x:Key="AnimationSpeedCustom">Custom</system:String>
162166
<system:String x:Key="Clock">Clock</system:String>
163167
<system:String x:Key="Date">Date</system:String>
164168

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using ModernWpf.Controls;
2525
using Key = System.Windows.Input.Key;
2626
using System.Media;
27+
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
2728

2829
namespace Flow.Launcher
2930
{
@@ -379,27 +380,35 @@ public void WindowAnimator()
379380
CircleEase easing = new CircleEase();
380381
easing.EasingMode = EasingMode.EaseInOut;
381382

383+
var animationLength = _settings.AnimationSpeed switch
384+
{
385+
AnimationSpeeds.Slow => 560,
386+
AnimationSpeeds.Medium => 360,
387+
AnimationSpeeds.Fast => 160,
388+
_ => _settings.CustomAnimationLength
389+
};
390+
382391
var WindowOpacity = new DoubleAnimation
383392
{
384393
From = 0,
385394
To = 1,
386-
Duration = TimeSpan.FromMilliseconds(_settings.AnimationLength * 2 / 3),
395+
Duration = TimeSpan.FromMilliseconds(animationLength * 2 / 3),
387396
FillBehavior = FillBehavior.Stop
388397
};
389398

390399
var WindowMotion = new DoubleAnimation
391400
{
392401
From = Top + 10,
393402
To = Top,
394-
Duration = TimeSpan.FromMilliseconds(_settings.AnimationLength * 2 / 3),
403+
Duration = TimeSpan.FromMilliseconds(animationLength * 2 / 3),
395404
FillBehavior = FillBehavior.Stop
396405
};
397406
var IconMotion = new DoubleAnimation
398407
{
399408
From = 12,
400409
To = 0,
401410
EasingFunction = easing,
402-
Duration = TimeSpan.FromMilliseconds(_settings.AnimationLength),
411+
Duration = TimeSpan.FromMilliseconds(animationLength),
403412
FillBehavior = FillBehavior.Stop
404413
};
405414

@@ -408,7 +417,7 @@ public void WindowAnimator()
408417
From = 0,
409418
To = 1,
410419
EasingFunction = easing,
411-
Duration = TimeSpan.FromMilliseconds(_settings.AnimationLength),
420+
Duration = TimeSpan.FromMilliseconds(animationLength),
412421
FillBehavior = FillBehavior.Stop
413422
};
414423
double TargetIconOpacity = SearchIcon.Opacity; // Animation Target Opacity from Style
@@ -417,7 +426,7 @@ public void WindowAnimator()
417426
From = 0,
418427
To = TargetIconOpacity,
419428
EasingFunction = easing,
420-
Duration = TimeSpan.FromMilliseconds(_settings.AnimationLength),
429+
Duration = TimeSpan.FromMilliseconds(animationLength),
421430
FillBehavior = FillBehavior.Stop
422431
};
423432

@@ -427,7 +436,7 @@ public void WindowAnimator()
427436
From = new Thickness(0, 12, right, 0),
428437
To = new Thickness(0, 0, right, 0),
429438
EasingFunction = easing,
430-
Duration = TimeSpan.FromMilliseconds(_settings.AnimationLength),
439+
Duration = TimeSpan.FromMilliseconds(animationLength),
431440
FillBehavior = FillBehavior.Stop
432441
};
433442

Flow.Launcher/SettingWindow.xaml

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,7 @@
24032403
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource AnimationTip}" />
24042404
</StackPanel>
24052405
<ui:ToggleSwitch
2406+
x:Name="Animation"
24062407
Grid.Row="0"
24072408
Grid.Column="2"
24082409
IsOn="{Binding UseAnimation, Mode=TwoWay}"
@@ -2414,66 +2415,86 @@
24142415
</TextBlock>
24152416
</ItemsControl>
24162417
</Border>
2417-
<Border
2418-
Margin="0"
2419-
BorderThickness="0"
2420-
Style="{DynamicResource SettingGroupBox}">
2418+
<Separator
2419+
Width="Auto"
2420+
BorderThickness="1"
2421+
Style="{StaticResource SettingSeparatorStyle}" />
2422+
<Border Margin="0" BorderThickness="0">
2423+
<Border.Style>
2424+
<Style BasedOn="{StaticResource SettingGroupBox}" TargetType="Border">
2425+
<Setter Property="Visibility" Value="Collapsed" />
2426+
<Style.Triggers>
2427+
<DataTrigger Binding="{Binding ElementName=Animation, Path=IsOn}" Value="True">
2428+
<Setter Property="Visibility" Value="Visible" />
2429+
</DataTrigger>
2430+
</Style.Triggers>
2431+
</Style>
2432+
</Border.Style>
2433+
24212434
<ItemsControl Style="{StaticResource SettingGrid}">
24222435
<StackPanel Style="{StaticResource TextPanel}">
2423-
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource animationLength}" />
2424-
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource animationLengthToolTip}" />
2436+
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource AnimationSpeed}" />
2437+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource AnimationSpeedTip}" />
24252438
</StackPanel>
24262439
<StackPanel Grid.Column="2" Orientation="Horizontal">
2427-
<TextBlock
2428-
Width="Auto"
2429-
Margin="0,0,8,2"
2430-
VerticalAlignment="Center"
2431-
Foreground="{DynamicResource Color05B}"
2432-
Text="{Binding ElementName=AnimationLengthValue, Path=Value, UpdateSourceTrigger=PropertyChanged}"
2433-
TextAlignment="Right" />
2434-
<Slider
2435-
Name="AnimationLengthValue"
2436-
Width="250"
2440+
<ComboBox
2441+
x:Name="AnimationSpeed"
2442+
MinWidth="160"
24372443
Margin="0,0,18,0"
24382444
VerticalAlignment="Center"
2439-
IsMoveToPointEnabled="True"
2440-
IsSnapToTickEnabled="True"
2441-
Maximum="2000"
2442-
Minimum="100"
2443-
TickFrequency="10"
2444-
Value="{Binding AnimationLength, Mode=TwoWay}" />
2445+
DisplayMemberPath="Display"
2446+
FontSize="14"
2447+
ItemsSource="{Binding AnimationSpeeds}"
2448+
SelectedValue="{Binding Settings.AnimationSpeed}"
2449+
SelectedValuePath="Value">
2450+
</ComboBox>
2451+
<StackPanel Margin="0,0,18,0" Orientation="Horizontal">
2452+
<StackPanel.Style>
2453+
<Style TargetType="StackPanel">
2454+
<Setter Property="Visibility" Value="Collapsed" />
2455+
<Style.Triggers>
2456+
<DataTrigger Binding="{Binding ElementName=AnimationSpeed, Path=SelectedValue}" Value="{x:Static userSettings:AnimationSpeeds.Custom}">
2457+
<Setter Property="Visibility" Value="Visible" />
2458+
</DataTrigger>
2459+
</Style.Triggers>
2460+
</Style>
2461+
</StackPanel.Style>
2462+
<TextBox
2463+
Height="35"
2464+
MinWidth="80"
2465+
Text="{Binding Settings.CustomAnimationLength}"
2466+
TextWrapping="NoWrap" />
2467+
</StackPanel>
24452468
</StackPanel>
24462469
<TextBlock Style="{StaticResource Glyph}">
24472470
&#xe916;
24482471
</TextBlock>
24492472
</ItemsControl>
24502473
</Border>
2451-
<Separator
2452-
Width="Auto"
2453-
BorderThickness="1"
2454-
Style="{StaticResource SettingSeparatorStyle}" />
2455-
<Border
2456-
Margin="0"
2457-
BorderThickness="0"
2458-
Style="{DynamicResource SettingGroupBox}">
2459-
<ItemsControl Style="{StaticResource SettingGrid}">
2460-
<StackPanel Style="{StaticResource TextPanel}">
2461-
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource SoundEffect}" />
2462-
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource SoundEffectTip}" />
2463-
</StackPanel>
2464-
<ui:ToggleSwitch
2474+
</StackPanel>
2475+
</Border>
2476+
2477+
2478+
<Border
2479+
Margin="0"
2480+
BorderThickness="0"
2481+
Style="{DynamicResource SettingGroupBox}">
2482+
<ItemsControl Style="{StaticResource SettingGrid}">
2483+
<StackPanel Style="{StaticResource TextPanel}">
2484+
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource SoundEffect}" />
2485+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource SoundEffectTip}" />
2486+
</StackPanel>
2487+
<ui:ToggleSwitch
24652488
Grid.Row="0"
24662489
Grid.Column="2"
24672490
IsOn="{Binding UseSound, Mode=TwoWay}"
24682491
OffContent="{DynamicResource disable}"
24692492
OnContent="{DynamicResource enable}"
24702493
Style="{DynamicResource SideToggleSwitch}" />
2471-
<TextBlock Style="{StaticResource Glyph}">
2494+
<TextBlock Style="{StaticResource Glyph}">
24722495
&#xe994;
2473-
</TextBlock>
2474-
</ItemsControl>
2475-
</Border>
2476-
</StackPanel>
2496+
</TextBlock>
2497+
</ItemsControl>
24772498
</Border>
24782499

24792500
<Border Margin="0,12,0,12" Style="{DynamicResource SettingGroupBox}">

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,31 @@ public bool UseAnimation
598598
set => Settings.UseAnimation = value;
599599
}
600600

601-
public int AnimationLength
601+
public class AnimationSpeed
602602
{
603-
get => Settings.AnimationLength;
604-
set => Settings.AnimationLength = value;
603+
public string Display { get; set; }
604+
public AnimationSpeeds Value { get; set; }
605+
}
606+
607+
public List<AnimationSpeed> AnimationSpeeds
608+
{
609+
get
610+
{
611+
List<AnimationSpeed> speeds = new List<AnimationSpeed>();
612+
var enums = (AnimationSpeeds[])Enum.GetValues(typeof(AnimationSpeeds));
613+
foreach (var e in enums)
614+
{
615+
var key = $"AnimationSpeed{e}";
616+
var display = _translater.GetTranslation(key);
617+
var m = new AnimationSpeed
618+
{
619+
Display = display,
620+
Value = e,
621+
};
622+
speeds.Add(m);
623+
}
624+
return speeds;
625+
}
605626
}
606627

607628
public bool UseSound

0 commit comments

Comments
 (0)