Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(bar): implement view and view model for clock component

Lars Bergere714175f57ef
diff --git a/GlazeWM.Bar/Components/ClockComponent.xaml b/GlazeWM.Bar/Components/ClockComponent.xaml
index 9ab99e41..474ac713 100644
--- a/GlazeWM.Bar/Components/ClockComponent.xaml
+++ b/GlazeWM.Bar/Components/ClockComponent.xaml
@@ -6,9 +6,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GlazeWM.Bar.Components"
mc:Ignorable="d">
- <Button
- Name="Fill"
- Width="50"
- Content="{Binding Type}"
- Background="Red" />
+ <TextBlock
+ Name="StatusBarLabel"
+ Foreground="#FFE0E0E0"
+ Text="{Binding FormattedTime}" />
</UserControl>
diff --git a/GlazeWM.Bar/Components/ClockComponentViewModel.cs b/GlazeWM.Bar/Components/ClockComponentViewModel.cs
index ab283a85..5ea83acd 100644
--- a/GlazeWM.Bar/Components/ClockComponentViewModel.cs
+++ b/GlazeWM.Bar/Components/ClockComponentViewModel.cs
@@ -1,9 +1,19 @@
+using System;
+using System.Reactive.Linq;
+
namespace GlazeWM.Bar.Components
{
public class ClockComponentViewModel : ComponentViewModel
{
+ public string FormattedTime =>
+ $"{DateTime.Now.ToShortTimeString()} {DateTime.Now.ToShortDateString()}";
+
public ClockComponentViewModel(BarViewModel parentViewModel) : base(parentViewModel)
{
+ var updateInterval = TimeSpan.FromSeconds(1);
+
+ Observable.Interval(updateInterval)
+ .Subscribe(_ => OnPropertyChanged(nameof(FormattedTime)));
}
}
}