Skip to content

Commit 06e9149

Browse files
authored
Merge pull request #2199 from AlexDavies8/dev
Added Animation Length slider
2 parents a7fc5b3 + 4360c77 commit 06e9149

File tree

5 files changed

+127
-18
lines changed

5 files changed

+127
-18
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ public bool HideNotifyIcon
254254
[JsonConverter(typeof(JsonStringEnumConverter))]
255255
public LastQueryMode LastQueryMode { get; set; } = LastQueryMode.Selected;
256256

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

258262
// This needs to be loaded last by staying at the bottom
259263
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();
@@ -290,4 +294,12 @@ public enum SearchWindowAligns
290294
RightTop,
291295
Custom
292296
}
297+
298+
public enum AnimationSpeeds
299+
{
300+
Slow,
301+
Medium,
302+
Fast,
303+
Custom
304+
}
293305
}

Flow.Launcher/Languages/en.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +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="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>
160166
<system:String x:Key="Clock">Clock</system:String>
161167
<system:String x:Key="Date">Date</system:String>
162168

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.FromSeconds(0.25),
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.FromSeconds(0.25),
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.FromSeconds(0.36),
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.FromSeconds(0.36),
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.FromSeconds(0.36),
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.FromSeconds(0.36),
439+
Duration = TimeSpan.FromMilliseconds(animationLength),
431440
FillBehavior = FillBehavior.Stop
432441
};
433442

Flow.Launcher/SettingWindow.xaml

Lines changed: 67 additions & 12 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}"
@@ -2418,28 +2419,82 @@
24182419
Width="Auto"
24192420
BorderThickness="1"
24202421
Style="{StaticResource SettingSeparatorStyle}" />
2421-
<Border
2422-
Margin="0"
2423-
BorderThickness="0"
2424-
Style="{DynamicResource SettingGroupBox}">
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+
24252434
<ItemsControl Style="{StaticResource SettingGrid}">
24262435
<StackPanel Style="{StaticResource TextPanel}">
2427-
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource SoundEffect}" />
2428-
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource SoundEffectTip}" />
2436+
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource AnimationSpeed}" />
2437+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource AnimationSpeedTip}" />
24292438
</StackPanel>
2430-
<ui:ToggleSwitch
2439+
<StackPanel Grid.Column="2" Orientation="Horizontal">
2440+
<ComboBox
2441+
x:Name="AnimationSpeed"
2442+
MinWidth="160"
2443+
Margin="0,0,18,0"
2444+
VerticalAlignment="Center"
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>
2468+
</StackPanel>
2469+
<TextBlock Style="{StaticResource Glyph}">
2470+
&#xe916;
2471+
</TextBlock>
2472+
</ItemsControl>
2473+
</Border>
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
24312488
Grid.Row="0"
24322489
Grid.Column="2"
24332490
IsOn="{Binding UseSound, Mode=TwoWay}"
24342491
OffContent="{DynamicResource disable}"
24352492
OnContent="{DynamicResource enable}"
24362493
Style="{DynamicResource SideToggleSwitch}" />
2437-
<TextBlock Style="{StaticResource Glyph}">
2494+
<TextBlock Style="{StaticResource Glyph}">
24382495
&#xe994;
2439-
</TextBlock>
2440-
</ItemsControl>
2441-
</Border>
2442-
</StackPanel>
2496+
</TextBlock>
2497+
</ItemsControl>
24432498
</Border>
24442499

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

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,33 @@ public bool UseAnimation
598598
set => Settings.UseAnimation = value;
599599
}
600600

601+
public class AnimationSpeed
602+
{
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+
}
626+
}
627+
601628
public bool UseSound
602629
{
603630
get => Settings.UseSound;

0 commit comments

Comments
 (0)