Skip to content

Commit

Permalink
Add ProfilesTab
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed Sep 16, 2023
1 parent d75ce44 commit c25805f
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 0 deletions.
9 changes: 9 additions & 0 deletions SightKeeper.Avalonia/ViewModels/FakeViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Windows.Input;
using NSubstitute;

namespace SightKeeper.Avalonia.ViewModels;

public static class FakeViewModel
{
internal static ICommand CommandSubstitute { get; } = Substitute.For<ICommand>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.Common;

namespace SightKeeper.Avalonia.ViewModels.Tabs.Profiles;

public sealed class FakeProfilesViewModel : IProfilesViewModel
{
public IReadOnlyCollection<ProfileViewModel> Profiles { get; }
public ICommand CreateProfileCommand => FakeViewModel.CommandSubstitute;

public FakeProfilesViewModel()
{
DataSet dataSet = new("Dataset 1");
Game game = new("Game 1", "game1");
dataSet.Game = game;
var weights = dataSet.WeightsLibrary.CreateWeights(Array.Empty<byte>(), Array.Empty<byte>(), ModelSize.Small,
100, 0.5f, 0.4f, 0.3f, Enumerable.Empty<Asset>());
Profile profile1 = new("Profile", string.Empty, 0.5f, 2f, weights);
Profile profile2 = new("Profile with long name!", string.Empty, 0.3f, 3f, weights);
Profiles = new ProfileViewModel[]
{
new(profile1),
new(profile2)
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Windows.Input;

namespace SightKeeper.Avalonia.ViewModels.Tabs.Profiles;

public interface IProfilesViewModel
{
IReadOnlyCollection<ProfileViewModel> Profiles { get; }
ICommand CreateProfileCommand { get; }
}
17 changes: 17 additions & 0 deletions SightKeeper.Avalonia/ViewModels/Tabs/Profiles/ProfileViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.Common;

namespace SightKeeper.Avalonia.ViewModels.Tabs.Profiles;

public sealed class ProfileViewModel
{
public Profile Profile { get; }
public string Name => Profile.Name;
public string Description => Profile.Description;
public Game? Game => Profile.Weights.Library.DataSet.Game;

public ProfileViewModel(Profile profile)
{
Profile = profile;
}
}
58 changes: 58 additions & 0 deletions SightKeeper.Avalonia/Views/Tabs/ProfilesTab.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:profilesViewModels="clr-namespace:SightKeeper.Avalonia.ViewModels.Tabs.Profiles"
xmlns:icons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SightKeeper.Avalonia.Views.Tabs.ProfilesTab"
x:DataType="profilesViewModels:IProfilesViewModel">
<Design.DataContext>
<profilesViewModels:FakeProfilesViewModel/>
</Design.DataContext>
<Grid RowDefinitions="Auto *">
<StackPanel Grid.Row="0"
Orientation="Horizontal"
Margin="5">
<Button Content="{icons:MaterialIconExt Plus}"/>
</StackPanel>
<ScrollViewer Grid.Row="1">
<ItemsControl ItemsSource="{Binding Profiles}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="SlateGray"
BorderThickness="1"
CornerRadius="5"
Margin="5"
Padding="10 5 5 5"
MaxWidth="200"
MinWidth="100">
<Grid RowDefinitions="* *"
ColumnDefinitions="* Auto">
<TextBlock Grid.Row="0" Grid.Column="0"
Grid.ColumnSpan="2"
Text="{Binding Name}"
FontSize="18"
VerticalAlignment="Center"
Margin="0 0 5 0"/>
<TextBlock Grid.Row="1" Grid.Column="0"
Text="{Binding Game.Title}"
FontSize="14"
VerticalAlignment="Center"
Margin="0 0 5 0"/>
<Button Grid.Row="1" Grid.Column="1"
Content="{icons:MaterialIconExt Cog}"
Padding="5"/>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</UserControl>
17 changes: 17 additions & 0 deletions SightKeeper.Avalonia/Views/Tabs/ProfilesTab.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace SightKeeper.Avalonia.Views.Tabs;

public partial class ProfilesTab : UserControl
{
public ProfilesTab()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}

0 comments on commit c25805f

Please sign in to comment.