Skip to content

Commit

Permalink
feat: add image bar component (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
HolbyFPV authored Aug 5, 2023
1 parent e24f556 commit 19da717
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions GlazeWM.Bar/BarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private List<ComponentViewModel> CreateComponentViewModels(
WorkspacesComponentConfig wcc => new WorkspacesComponentViewModel(this, wcc),
WindowTitleComponentConfig wtcc => new WindowTitleComponentViewModel(this, wtcc),
VolumeComponentConfig vcc => new VolumeComponentViewModel(this, vcc),
ImageComponentConfig bscc => new ImageComponentViewModel(this, bscc),
SystemTrayComponentConfig stcc => new SystemTrayComponentViewModel(this, stcc),
CpuComponentConfig cpupc => new CpuComponentViewModel(this, cpupc),
GpuComponentConfig gpupc => new GpuComponentViewModel(this, gpupc),
Expand Down
4 changes: 4 additions & 0 deletions GlazeWM.Bar/Components/ComponentPortal.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
Padding="{Binding Padding}"
Background="{Binding Background}" />
</DataTemplate>
<DataTemplate DataType="{x:Type components:ImageComponentViewModel}">
<components:ImageComponent
Padding="{Binding Padding}"
Background="{Binding Background}" />
<DataTemplate DataType="{x:Type components:CpuComponentViewModel}">
<components:CpuComponent
Padding="{Binding Padding}"
Expand Down
10 changes: 10 additions & 0 deletions GlazeWM.Bar/Components/ImageComponent.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<UserControl
x:Class="GlazeWM.Bar.Components.ImageComponent"
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">
<Image Source="{Binding Source}" />
</UserControl>
15 changes: 15 additions & 0 deletions GlazeWM.Bar/Components/ImageComponent.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows.Controls;

namespace GlazeWM.Bar.Components
{
/// <summary>
/// Interaction logic for ImageComponent.xaml
/// </summary>
public partial class ImageComponent : UserControl
{
public ImageComponent()
{
InitializeComponent();
}
}
}
17 changes: 17 additions & 0 deletions GlazeWM.Bar/Components/ImageComponentViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using GlazeWM.Domain.UserConfigs;

namespace GlazeWM.Bar.Components
{
public class ImageComponentViewModel : ComponentViewModel
{
private ImageComponentConfig _config => _componentConfig as ImageComponentConfig;

public string Source => _config.Source;

public ImageComponentViewModel(
BarViewModel parentViewModel,
ImageComponentConfig config) : base(parentViewModel, config)
{
}
}
}
5 changes: 5 additions & 0 deletions GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public override BarComponentConfig Read(
jsonObject.RootElement.ToString(),
options
),
"image" =>
JsonSerializer.Deserialize<ImageComponentConfig>(
jsonObject.RootElement.ToString(),
options
),
"weather" =>
JsonSerializer.Deserialize<WeatherComponentConfig>(
jsonObject.RootElement.ToString(),
Expand Down
10 changes: 10 additions & 0 deletions GlazeWM.Domain/UserConfigs/ImageComponentConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace GlazeWM.Domain.UserConfigs
{
public class ImageComponentConfig : BarComponentConfig
{
/// <summary>
/// Path to image
/// </summary>
public string Source { get; set; }
}
}

0 comments on commit 19da717

Please sign in to comment.