Skip to content

Commit

Permalink
Implement ProfileEditor view and VM stuff for that (just without impl…
Browse files Browse the repository at this point in the history
…ementations for ProfileEditorViewModel, interface and fake only)
  • Loading branch information
Neakita committed Sep 17, 2023
1 parent 94db6c0 commit 7a8583c
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 1 deletion.
4 changes: 4 additions & 0 deletions SightKeeper.Avalonia/SightKeeper.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@
<DependentUpon>DetectorItem.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Views\Profiles\ProfilesTab.axaml.cs">
<DependentUpon>ProfilesTab.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion SightKeeper.Avalonia/SightKeeper.Avalonia.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=viewmodels_005Cannotating_005Cenvironment_005Cannotatortools/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=viewmodels_005Cannotating_005Cenvironment_005Cannotatorworkspace/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=viewmodels_005Cannotating_005Cenvironment_005Cdrawer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=views_005Cannotating_005Cdetector/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=viewmodels_005Ctabs_005Cprofiles_005Ctab/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=views_005Cannotating_005Cdetector/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=views_005Cprofiles/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.Common;

namespace SightKeeper.Avalonia.ViewModels.Tabs.Profiles.Editor;

public sealed partial class FakeProfileEditorViewModel : ViewModel, ProfileEditorViewModel
{
public IReadOnlyCollection<DataSet> AvailableDataSets { get; }
public IReadOnlyCollection<Weights> AvailableWeights { get; }
public IReadOnlyCollection<ItemClass> AvailableItemClasses { get; }
public string Name { get; set; } = "Profile 1";
public string Description { get; set; } = "Some description.. lorem ipsum and all that stuff";
[ObservableProperty] private float _detectionThreshold = 0.6f;
[ObservableProperty] private float _mouseSensitivity = 1.5f;
public DataSet? DataSet { get; set; }
public Weights? Weights { get; set; }
public IReadOnlyList<ItemClass> ItemClasses { get; }
public ItemClass? ItemClassToAdd { get; set; }
public ICommand AddItemClassCommand => FakeViewModel.CommandSubstitute;
public ICommand RemoveItemClassCommand => FakeViewModel.CommandSubstitute;
public ICommand MoveItemClassUpCommand => FakeViewModel.CommandSubstitute;
public ICommand MoveItemClassDownCommand => FakeViewModel.CommandSubstitute;
public ICommand ApplyCommand => FakeViewModel.CommandSubstitute;

public FakeProfileEditorViewModel()
{
DataSet dataSet = new("Dataset 1");
var weights = dataSet.WeightsLibrary.CreateWeights(Array.Empty<byte>(), Array.Empty<byte>(), ModelSize.Nano, 100, 1.1f, 1.0f,
0.9f, Enumerable.Empty<Asset>());
var itemClass1 = dataSet.CreateItemClass("Item class 1", 0);
var itemClass2 = dataSet.CreateItemClass("Item class 2", 0);
var itemClass3 = dataSet.CreateItemClass("Item class 3", 0);
var itemClass4 = dataSet.CreateItemClass("Item class 4", 0);
ItemClassToAdd = itemClass3;
AvailableDataSets = new[] { dataSet };
AvailableWeights = new[] { weights };
ItemClasses = new[] { itemClass1, itemClass2 };
AvailableItemClasses = new[] { itemClass3, itemClass4 };
Weights = weights;
DataSet = dataSet;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Windows.Input;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.Common;

namespace SightKeeper.Avalonia.ViewModels.Tabs.Profiles.Editor;

public interface ProfileEditorViewModel
{
IReadOnlyCollection<DataSet> AvailableDataSets { get; }
IReadOnlyCollection<Weights> AvailableWeights { get; }
IReadOnlyCollection<ItemClass> AvailableItemClasses { get; }

string Name { get; set; }
string Description { get; set; }
float DetectionThreshold { get; set; }
float MouseSensitivity { get; set; }
DataSet? DataSet { get; set; }
Weights? Weights { get; set; }
IReadOnlyList<ItemClass> ItemClasses { get; }
ItemClass? ItemClassToAdd { get; set; }

ICommand AddItemClassCommand { get; }
ICommand RemoveItemClassCommand { get; }
ICommand MoveItemClassUpCommand { get; }
ICommand MoveItemClassDownCommand { get; }
ICommand ApplyCommand { get; }
}
File renamed without changes.
104 changes: 104 additions & 0 deletions SightKeeper.Avalonia/Views/Profiles/ProfileEditor.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<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:profilesEditorViewModels="clr-namespace:SightKeeper.Avalonia.ViewModels.Tabs.Profiles.Editor"
xmlns:icons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="450"
x:Class="SightKeeper.Avalonia.Views.ProfileEditor"
x:DataType="profilesEditorViewModels:ProfileEditorViewModel">
<Design.DataContext>
<profilesEditorViewModels:FakeProfileEditorViewModel/>
</Design.DataContext>
<UserControl.Styles>
<Style Selector="Slider">
<Setter Property="TickPlacement" Value="Outside"/>
<Setter Property="IsSnapToTickEnabled" Value="True"/>
<Setter Property="TickFrequency" Value="0.1"/>
<Setter Property="Minimum" Value="0.1"/>
</Style>
<Style Selector="NumericUpDown">
<Setter Property="MinWidth" Value="130"/>
<Setter Property="FormatString" Value="P0"/>
<Setter Property="Increment" Value="0.1"/>
<Setter Property="Minimum" Value="0.1"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</UserControl.Styles>
<Grid RowDefinitions="* Auto">
<StackPanel Grid.Row="0" Name="Root">
<TextBox Text="{Binding Name}"
Watermark="Name"/>
<ComboBox ItemsSource="{Binding AvailableDataSets}"
SelectedItem="{Binding DataSet}"
PlaceholderText="Dataset"/>
<ComboBox ItemsSource="{Binding AvailableWeights}"
SelectedItem="{Binding Weights}"
PlaceholderText="Weights"/>
<Grid ColumnDefinitions="Auto *">
<NumericUpDown Grid.Column="0"
Watermark="Detection threshold"
Value="{Binding DetectionThreshold}"
Maximum="0.9"/>
<Slider Grid.Column="1"
Maximum="0.9"
Value="{Binding DetectionThreshold}"/>
</Grid>
<Grid ColumnDefinitions="Auto *">
<NumericUpDown Grid.Column="0"
Watermark="Mouse sensitivity"
Value="{Binding MouseSensitivity}"
Maximum="5"/>
<Slider Grid.Column="1"
Maximum="5"
Value="{Binding MouseSensitivity}"/>
</Grid>
<StackPanel Orientation="Horizontal">
<ComboBox ItemsSource="{Binding AvailableItemClasses}"
SelectedItem="{Binding ItemClassToAdd}"/>
<Button Content="{icons:MaterialIconExt Plus}"
Command="{Binding AddItemClassCommand}"/>
</StackPanel>
<ItemsControl ItemsSource="{Binding ItemClasses}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Gray"
BorderThickness="1"
CornerRadius="5"
Margin="5"
Padding="5">
<Grid RowDefinitions="* *"
ColumnDefinitions="Auto * Auto">
<Button Grid.Row="0" Grid.Column="0"
Content="{icons:MaterialIconExt ChevronUp}"
Padding="5 0"
Command="{Binding #Root.((profilesEditorViewModels:ProfileEditorViewModel)DataContext).MoveItemClassUpCommand}"
CommandParameter="{Binding}"/>
<Button Grid.Row="1" Grid.Column="0"
Content="{icons:MaterialIconExt ChevronDown}"
Padding="5 0"
Command="{Binding #Root.((profilesEditorViewModels:ProfileEditorViewModel)DataContext).MoveItemClassDownCommand}"
CommandParameter="{Binding}"/>
<TextBlock Grid.Row="0" Grid.RowSpan="2"
Grid.Column="1"
Text="{Binding Name}"
VerticalAlignment="Center"
Margin="5 0 0 0"/>
<Button Grid.Row="0" Grid.RowSpan="2"
Grid.Column="2"
Content="{icons:MaterialIconExt Close}"
Command="{Binding #Root.((profilesEditorViewModels:ProfileEditorViewModel)DataContext).RemoveItemClassCommand}"
CommandParameter="{Binding}"/>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<Button Grid.Row="1"
Content="Apply"
Command="{Binding ApplyCommand}"
HorizontalAlignment="Right"
Margin="5"/>
</Grid>
</UserControl>
17 changes: 17 additions & 0 deletions SightKeeper.Avalonia/Views/Profiles/ProfileEditor.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;

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

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

0 comments on commit 7a8583c

Please sign in to comment.