GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(bar): create component view models from within `BarViewModel`
Lars Bergereb7d9ee9ba32
diff --git a/GlazeWM.Bar/BarViewModel.cs b/GlazeWM.Bar/BarViewModel.csindex 992b9f9c..18fb62ea 100644--- a/GlazeWM.Bar/BarViewModel.cs+++ b/GlazeWM.Bar/BarViewModel.cs@@ -5,6 +5,7 @@ using System.Linq;using System.Reactive.Linq;using System.Windows.Threading;using GlazeWM.Bar.Common;+using GlazeWM.Bar.Components;using GlazeWM.Domain.Containers.Events;using GlazeWM.Domain.Monitors;using GlazeWM.Domain.UserConfigs;@@ -32,9 +33,15 @@ namespace GlazeWM.Barpublic string BorderWidth => ShorthandToXamlProperty(_barConfig.BorderWidth);public string Padding => ShorthandToXamlProperty(_barConfig.Padding);public double Opacity => _barConfig.Opacity;- public List<BarComponentConfig> ComponentsLeft => _barConfig.ComponentsLeft;- public List<BarComponentConfig> ComponentsCenter => _barConfig.ComponentsCenter;- public List<BarComponentConfig> ComponentsRight => _barConfig.ComponentsRight;++ public List<ComponentViewModel> ComponentsLeft =>+ CreateComponentViewModels(_barConfig.ComponentsLeft);++ public List<ComponentViewModel> ComponentsCenter =>+ CreateComponentViewModels(_barConfig.ComponentsCenter);++ public List<ComponentViewModel> ComponentsRight =>+ CreateComponentViewModels(_barConfig.ComponentsRight);public BarViewModel(){@@ -51,6 +58,21 @@ namespace GlazeWM.Bar});}+ private List<ComponentViewModel> CreateComponentViewModels(List<BarComponentConfig> componentConfigs)+ {+ return componentConfigs.Select(config =>+ {+ ComponentViewModel viewModel = config.Type switch+ {+ "workspaces" => new WorkspacesComponentViewModel(),+ "clock" => new ClockComponentViewModel(),+ _ => throw new ArgumentException(),+ };++ return viewModel;+ }).ToList();+ }+/// <summary>/// Convert shorthand properties from user config (ie. `Padding`, `Margin`, and `BorderWidth`)/// to be compatible with their equivalent XAML properties (ie. `Padding`, `Margin`, and