GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add bar component for displaying text (#128)
Agustin Ardizzone85a407f45d81
diff --git a/GlazeWM.Bar/BarViewModel.cs b/GlazeWM.Bar/BarViewModel.csindex 32e3b6ab..bbdafcd7 100644--- a/GlazeWM.Bar/BarViewModel.cs+++ b/GlazeWM.Bar/BarViewModel.cs@@ -44,6 +44,7 @@ namespace GlazeWM.Bar{WorkspacesComponentConfig wcc => new WorkspacesComponentViewModel(this, wcc),ClockComponentConfig ccc => new ClockComponentViewModel(this, ccc),+ TextComponentConfig tcc => new TextComponentViewModel(this, tcc),_ => throw new ArgumentOutOfRangeException(nameof(config)),});}diff --git a/GlazeWM.Bar/Components/ComponentPortal.xaml b/GlazeWM.Bar/Components/ComponentPortal.xamlindex 6db89c5a..b3a3290b 100644--- a/GlazeWM.Bar/Components/ComponentPortal.xaml+++ b/GlazeWM.Bar/Components/ComponentPortal.xaml@@ -21,6 +21,9 @@<DataTemplate DataType="{x:Type components:ClockComponentViewModel}"><components:ClockComponent /></DataTemplate>+ <DataTemplate DataType="{x:Type components:TextComponentViewModel}">+ <components:TextComponent />+ </DataTemplate></ContentPresenter.Resources></ContentPresenter></Grid>diff --git a/GlazeWM.Bar/Components/TextComponent.xaml b/GlazeWM.Bar/Components/TextComponent.xamlnew file mode 100644index 00000000..231357c5--- /dev/null+++ b/GlazeWM.Bar/Components/TextComponent.xaml@@ -0,0 +1,16 @@+<UserControl+ x:Class="GlazeWM.Bar.Components.TextComponent"+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"+ xmlns:local="clr-namespace:GlazeWM.Bar.Components"+ mc:Ignorable="d">+ <TextBlock+ VerticalAlignment="Center"+ Foreground="{Binding Foreground}"+ FontFamily="{Binding FontFamily}"+ FontWeight="{Binding FontWeight}"+ FontSize="{Binding FontSize}"+ Text="{Binding Text}" />+</UserControl>diff --git a/GlazeWM.Bar/Components/TextComponent.xaml.cs b/GlazeWM.Bar/Components/TextComponent.xaml.csnew file mode 100644index 00000000..07a4b93e--- /dev/null+++ b/GlazeWM.Bar/Components/TextComponent.xaml.cs@@ -0,0 +1,15 @@+using System.Windows.Controls;++namespace GlazeWM.Bar.Components+{+ /// <summary>+ /// Interaction logic for TextComponent.xaml+ /// </summary>+ public partial class TextComponent : UserControl+ {+ public TextComponent()+ {+ InitializeComponent();+ }+ }+}diff --git a/GlazeWM.Bar/Components/TextComponentViewModel.cs b/GlazeWM.Bar/Components/TextComponentViewModel.csnew file mode 100644index 00000000..fec1dd17--- /dev/null+++ b/GlazeWM.Bar/Components/TextComponentViewModel.cs@@ -0,0 +1,22 @@+using System;+using System.Globalization;+using System.Reactive.Linq;+using GlazeWM.Domain.UserConfigs;++namespace GlazeWM.Bar.Components+{+ public class TextComponentViewModel : ComponentViewModel+ {+ private TextComponentConfig _config => _componentConfig as TextComponentConfig;+ private string _text => _config.Text;++ /// <summary>+ /// Shows text from the user's config.+ /// </summary>+ public string Text => _text;++ public TextComponentViewModel(BarViewModel parentViewModel, TextComponentConfig config) : base(parentViewModel, config)+ {+ }+ }+}diff --git a/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs b/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.csindex f9c59222..77151762 100644--- a/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs+++ b/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs@@ -25,6 +25,11 @@ namespace GlazeWM.Domain.UserConfigsjsonObject.RootElement.ToString(),options),+ "text" =>+ JsonSerializer.Deserialize<TextComponentConfig>(+ jsonObject.RootElement.ToString(),+ options+ ),_ => throw new ArgumentException($"Invalid component type '{typeDiscriminator}'."),};}diff --git a/GlazeWM.Domain/UserConfigs/TextComponentConfig.cs b/GlazeWM.Domain/UserConfigs/TextComponentConfig.csnew file mode 100644index 00000000..0370e58a--- /dev/null+++ b/GlazeWM.Domain/UserConfigs/TextComponentConfig.cs@@ -0,0 +1,10 @@+namespace GlazeWM.Domain.UserConfigs+{+ public class TextComponentConfig : BarComponentConfig+ {+ /// <summary>+ /// Text to print.+ /// </summary>+ public string Text { get; set; } = "Hello world!";+ }+}