Skip to content

Commit 3eca74f

Browse files
authored
Merge pull request #1556 from onesounds/AddTimeFormat
[Dev] Improve Clock/Date
2 parents 16cc489 + 0bb53e1 commit 3eca74f

12 files changed

+262
-124
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
5+
namespace Flow.Launcher.Converters
6+
{
7+
public class DateTimeFormatToNowConverter : IValueConverter
8+
{
9+
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
return value is not string format ? null : DateTime.Now.ToString(format);
13+
}
14+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
}
19+
}

Flow.Launcher/MainWindow.xaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,16 @@
231231
<StackPanel x:Name="ClockPanel"
232232
IsHitTestVisible="False"
233233
Style="{DynamicResource ClockPanel}">
234-
<TextBlock Style="{DynamicResource DateBox}"
235-
Text="{Binding DateText}"
236-
Visibility="{Binding Settings.UseDate, Converter={StaticResource BooleanToVisibilityConverter}}" />
237-
<TextBlock Style="{DynamicResource ClockBox}"
234+
<TextBlock
235+
x:Name="ClockBox"
236+
Style="{DynamicResource ClockBox}"
238237
Text="{Binding ClockText}"
239238
Visibility="{Binding Settings.UseClock, Converter={StaticResource BooleanToVisibilityConverter}}" />
239+
<TextBlock
240+
x:Name="DateBox"
241+
Style="{DynamicResource DateBox}"
242+
Text="{Binding DateText}"
243+
Visibility="{Binding Settings.UseDate, Converter={StaticResource BooleanToVisibilityConverter}}" />
240244
</StackPanel>
241245

242246
<Canvas Style="{DynamicResource SearchIconPosition}">

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
using ModernWpf.Controls;
3131
using System.Drawing;
3232
using System.Windows.Forms.Design.Behavior;
33+
using System.Security.Cryptography;
34+
using System.Runtime.CompilerServices;
35+
using Microsoft.VisualBasic.Devices;
36+
using Microsoft.FSharp.Data.UnitSystems.SI.UnitNames;
3337

3438
namespace Flow.Launcher
3539
{
@@ -105,7 +109,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
105109
// since the default main window visibility is visible
106110
// so we need set focus during startup
107111
QueryTextBox.Focus();
108-
109112
_viewModel.PropertyChanged += (o, e) =>
110113
{
111114
switch (e.PropertyName)
@@ -243,7 +246,9 @@ private void InitializeNotifyIcon()
243246
Icon = Properties.Resources.app,
244247
Visible = !_settings.HideNotifyIcon
245248
};
249+
246250
contextMenu = new ContextMenu();
251+
247252
var openIcon = new FontIcon { Glyph = "\ue71e" };
248253
var open = new MenuItem
249254
{
@@ -280,9 +285,11 @@ private void InitializeNotifyIcon()
280285
positionreset.Click += (o, e) => PositionReset();
281286
settings.Click += (o, e) => App.API.OpenSettingDialog();
282287
exit.Click += (o, e) => Close();
283-
contextMenu.Items.Add(open);
288+
284289
gamemode.ToolTip = InternationalizationManager.Instance.GetTranslation("GameModeToolTip");
285290
positionreset.ToolTip = InternationalizationManager.Instance.GetTranslation("PositionResetToolTip");
291+
292+
contextMenu.Items.Add(open);
286293
contextMenu.Items.Add(gamemode);
287294
contextMenu.Items.Add(positionreset);
288295
contextMenu.Items.Add(settings);
@@ -359,45 +366,91 @@ public void WindowAnimator()
359366

360367
_animating = true;
361368
UpdatePosition();
362-
Storyboard sb = new Storyboard();
369+
370+
Storyboard windowsb = new Storyboard();
371+
Storyboard clocksb = new Storyboard();
363372
Storyboard iconsb = new Storyboard();
364-
CircleEase easing = new CircleEase(); // or whatever easing class you want
373+
CircleEase easing = new CircleEase();
365374
easing.EasingMode = EasingMode.EaseInOut;
366-
var da = new DoubleAnimation
375+
376+
var WindowOpacity = new DoubleAnimation
367377
{
368378
From = 0,
369379
To = 1,
370380
Duration = TimeSpan.FromSeconds(0.25),
371381
FillBehavior = FillBehavior.Stop
372382
};
373383

374-
var da2 = new DoubleAnimation
384+
var WindowMotion = new DoubleAnimation
375385
{
376386
From = Top + 10,
377387
To = Top,
378388
Duration = TimeSpan.FromSeconds(0.25),
379389
FillBehavior = FillBehavior.Stop
380390
};
381-
var da3 = new DoubleAnimation
382-
{
391+
var IconMotion = new DoubleAnimation
392+
{
383393
From = 12,
384394
To = 0,
385395
EasingFunction = easing,
386396
Duration = TimeSpan.FromSeconds(0.36),
387397
FillBehavior = FillBehavior.Stop
388-
};
389-
Storyboard.SetTarget(da, this);
390-
Storyboard.SetTargetProperty(da, new PropertyPath(Window.OpacityProperty));
391-
Storyboard.SetTargetProperty(da2, new PropertyPath(Window.TopProperty));
392-
Storyboard.SetTargetProperty(da3, new PropertyPath(TopProperty));
393-
sb.Children.Add(da);
394-
sb.Children.Add(da2);
395-
iconsb.Children.Add(da3);
396-
sb.Completed += (_, _) => _animating = false;
398+
};
399+
400+
var ClockOpacity = new DoubleAnimation
401+
{
402+
From = 0,
403+
To = 1,
404+
EasingFunction = easing,
405+
Duration = TimeSpan.FromSeconds(0.36),
406+
FillBehavior = FillBehavior.Stop
407+
};
408+
double TargetIconOpacity = SearchIcon.Opacity; // Animation Target Opacity from Style
409+
var IconOpacity = new DoubleAnimation
410+
{
411+
From = 0,
412+
To = TargetIconOpacity,
413+
EasingFunction = easing,
414+
Duration = TimeSpan.FromSeconds(0.36),
415+
FillBehavior = FillBehavior.Stop
416+
};
417+
418+
double right = ClockPanel.Margin.Right;
419+
var thicknessAnimation = new ThicknessAnimation
420+
{
421+
From = new Thickness(0, 12, right, 0),
422+
To = new Thickness(0, 0, right, 0),
423+
EasingFunction = easing,
424+
Duration = TimeSpan.FromSeconds(0.36),
425+
FillBehavior = FillBehavior.Stop
426+
};
427+
428+
Storyboard.SetTargetProperty(ClockOpacity, new PropertyPath(OpacityProperty));
429+
Storyboard.SetTargetName(thicknessAnimation, "ClockPanel");
430+
Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath(MarginProperty));
431+
Storyboard.SetTarget(WindowOpacity, this);
432+
Storyboard.SetTargetProperty(WindowOpacity, new PropertyPath(Window.OpacityProperty));
433+
Storyboard.SetTargetProperty(WindowMotion, new PropertyPath(Window.TopProperty));
434+
Storyboard.SetTargetProperty(IconMotion, new PropertyPath(TopProperty));
435+
Storyboard.SetTargetProperty(IconOpacity, new PropertyPath(OpacityProperty));
436+
437+
clocksb.Children.Add(thicknessAnimation);
438+
clocksb.Children.Add(ClockOpacity);
439+
windowsb.Children.Add(WindowOpacity);
440+
windowsb.Children.Add(WindowMotion);
441+
iconsb.Children.Add(IconMotion);
442+
iconsb.Children.Add(IconOpacity);
443+
444+
windowsb.Completed += (_, _) => _animating = false;
397445
_settings.WindowLeft = Left;
398446
_settings.WindowTop = Top;
447+
448+
if (QueryTextBox.Text.Length == 0)
449+
{
450+
clocksb.Begin(ClockPanel);
451+
}
399452
iconsb.Begin(SearchIcon);
400-
sb.Begin(FlowMainWindow);
453+
windowsb.Begin(FlowMainWindow);
401454
}
402455

403456
private void OnMouseDown(object sender, MouseButtonEventArgs e)

Flow.Launcher/SettingWindow.xaml

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
</Window.CommandBindings>
4040

4141
<Window.Resources>
42+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
4243
<converters:BorderClipConverter x:Key="BorderClipConverter" />
4344
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
4445
<converters:TextConverter x:Key="TextConverter" />
@@ -1815,13 +1816,25 @@
18151816
</Grid.RowDefinitions>
18161817
<Border Grid.Row="0">
18171818
<TextBox
1819+
x:Name="QueryTextBox"
18181820
IsReadOnly="True"
18191821
Style="{DynamicResource QueryBoxStyle}"
18201822
Text="{DynamicResource hiThere}" />
18211823
</Border>
1822-
<StackPanel x:Name="ClockPanel" Style="{DynamicResource ClockPanel}">
1823-
<TextBlock x:Name="DateBox" Style="{DynamicResource DateBox}" />
1824-
<TextBlock x:Name="ClockBox" Style="{DynamicResource ClockBox}" />
1824+
<StackPanel
1825+
x:Name="ClockPanel"
1826+
IsHitTestVisible="False"
1827+
Style="{DynamicResource ClockPanel}">
1828+
<TextBlock
1829+
x:Name="ClockBox"
1830+
Style="{DynamicResource ClockBox}"
1831+
Text="{Binding ClockText}"
1832+
Visibility="{Binding Settings.UseClock, Converter={StaticResource BooleanToVisibilityConverter}}" />
1833+
<TextBlock
1834+
x:Name="DateBox"
1835+
Style="{DynamicResource DateBox}"
1836+
Text="{Binding DateText}"
1837+
Visibility="{Binding Settings.UseDate, Converter={StaticResource BooleanToVisibilityConverter}}" />
18251838
</StackPanel>
18261839
<Canvas Style="{DynamicResource SearchIconPosition}">
18271840
<Path
@@ -2162,6 +2175,12 @@
21622175
Grid.Row="0"
21632176
Grid.Column="2"
21642177
Orientation="Horizontal">
2178+
<TextBlock
2179+
Margin="0,0,10,0"
2180+
VerticalAlignment="Center"
2181+
FontSize="14"
2182+
Foreground="{DynamicResource Color04B}"
2183+
Text="{Binding ClockText}" />
21652184
<ComboBox
21662185
x:Name="TimeFormat"
21672186
Grid.Column="2"
@@ -2170,14 +2189,12 @@
21702189
VerticalAlignment="Center"
21712190
FontSize="14"
21722191
ItemsSource="{Binding TimeFormatList}"
2173-
SelectedValue="{Binding Settings.TimeFormat}"
2174-
SelectionChanged="PreviewClockAndDate" />
2192+
SelectedItem="{Binding TimeFormat}" />
21752193
<ui:ToggleSwitch
21762194
IsOn="{Binding UseClock, Mode=TwoWay}"
21772195
OffContent="{DynamicResource disable}"
21782196
OnContent="{DynamicResource enable}"
2179-
Style="{DynamicResource SideToggleSwitch}"
2180-
Toggled="PreviewClockAndDate" />
2197+
Style="{DynamicResource SideToggleSwitch}" />
21812198
</StackPanel>
21822199
<TextBlock Style="{StaticResource Glyph}">
21832200
&#xec92;
@@ -2200,6 +2217,12 @@
22002217
Grid.Row="0"
22012218
Grid.Column="2"
22022219
Orientation="Horizontal">
2220+
<TextBlock
2221+
Margin="0,0,10,0"
2222+
VerticalAlignment="Center"
2223+
FontSize="14"
2224+
Foreground="{DynamicResource Color04B}"
2225+
Text="{Binding DateText}" />
22032226
<ComboBox
22042227
x:Name="DateFormat"
22052228
Grid.Column="2"
@@ -2208,14 +2231,12 @@
22082231
VerticalAlignment="Center"
22092232
FontSize="14"
22102233
ItemsSource="{Binding DateFormatList}"
2211-
SelectedValue="{Binding Settings.DateFormat}"
2212-
SelectionChanged="PreviewClockAndDate" />
2234+
SelectedItem="{Binding DateFormat}" />
22132235
<ui:ToggleSwitch
22142236
IsOn="{Binding UseDate, Mode=TwoWay}"
22152237
OffContent="{DynamicResource disable}"
22162238
OnContent="{DynamicResource enable}"
2217-
Style="{DynamicResource SideToggleSwitch}"
2218-
Toggled="PreviewClockAndDate" />
2239+
Style="{DynamicResource SideToggleSwitch}" />
22192240
</StackPanel>
22202241
<TextBlock Style="{StaticResource Glyph}">
22212242
&#xe787;

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@
1010
using ModernWpf;
1111
using ModernWpf.Controls;
1212
using System;
13-
using System.Drawing.Printing;
1413
using System.IO;
1514
using System.Windows;
16-
using System.Windows.Controls.Primitives;
1715
using System.Windows.Data;
1816
using System.Windows.Forms;
1917
using System.Windows.Input;
2018
using System.Windows.Interop;
2119
using System.Windows.Media;
2220
using System.Windows.Navigation;
23-
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
2421
using Button = System.Windows.Controls.Button;
2522
using Control = System.Windows.Controls.Control;
2623
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
@@ -44,6 +41,7 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
4441
API = api;
4542
InitializePosition();
4643
InitializeComponent();
44+
4745
}
4846

4947
#region General
@@ -64,7 +62,6 @@ private void OnLoaded(object sender, RoutedEventArgs e)
6462
pluginStoreView.Filter = PluginStoreFilter;
6563

6664
InitializePosition();
67-
ClockDisplay();
6865
}
6966

7067
private void OnSelectPythonDirectoryClick(object sender, RoutedEventArgs e)
@@ -514,34 +511,6 @@ private void PluginStore_OnKeyDown(object sender, KeyEventArgs e)
514511
}
515512
}
516513

517-
private void PreviewClockAndDate(object sender, RoutedEventArgs e)
518-
{
519-
ClockDisplay();
520-
}
521-
522-
public void ClockDisplay()
523-
{
524-
if (settings.UseClock)
525-
{
526-
ClockBox.Visibility = Visibility.Visible;
527-
ClockBox.Text = DateTime.Now.ToString(settings.TimeFormat);
528-
}
529-
else
530-
{
531-
ClockBox.Visibility = Visibility.Collapsed;
532-
}
533-
534-
if (settings.UseDate)
535-
{
536-
DateBox.Visibility = Visibility.Visible;
537-
DateBox.Text = DateTime.Now.ToString(settings.DateFormat);
538-
}
539-
else
540-
{
541-
DateBox.Visibility = Visibility.Collapsed;
542-
}
543-
}
544-
545514
public void InitializePosition()
546515
{
547516
if (settings.SettingWindowTop >= 0 && settings.SettingWindowLeft >= 0)
@@ -556,6 +525,7 @@ public void InitializePosition()
556525
}
557526
WindowState = settings.SettingWindowState;
558527
}
528+
559529
public double WindowLeft()
560530
{
561531
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);

0 commit comments

Comments
 (0)