Browse Source

Add Seed card

pull/165/head
Ionite 1 year ago
parent
commit
d3c3b099b6
No known key found for this signature in database
  1. 67
      StabilityMatrix.Avalonia/Controls/SeedCard.axaml
  2. 7
      StabilityMatrix.Avalonia/Controls/SeedCard.axaml.cs
  3. 25
      StabilityMatrix.Avalonia/DesignData/DesignData.cs

67
StabilityMatrix.Avalonia/Controls/SeedCard.axaml

@ -0,0 +1,67 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="using:StabilityMatrix.Avalonia.Controls"
xmlns:vmInference="using:StabilityMatrix.Avalonia.ViewModels.Inference"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:icons="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia"
x:DataType="vmInference:SeedCardViewModel"
xmlns:mocks="clr-namespace:StabilityMatrix.Avalonia.DesignData">
<Design.PreviewWith>
<Grid MinWidth="400">
<controls:SeedCard DataContext="{x:Static mocks:DesignData.SeedCardViewModel}"/>
</Grid>
</Design.PreviewWith>
<Style Selector="controls|SeedCard">
<!-- Set Defaults -->
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Template">
<ControlTemplate>
<controls:Card Padding="8" HorizontalAlignment="{TemplateBinding HorizontalAlignment}">
<Grid Margin="4" RowDefinitions="Auto,*">
<Grid Grid.Row="1" ColumnDefinitions="Auto,*,Auto,Auto">
<TextBlock
Grid.Column="0"
Margin="0,0,8,0"
VerticalAlignment="Center"
Text="Seed" />
<NumericUpDown
Grid.Column="1"
Name="SeedNumberBox"
IsReadOnly="{Binding !#RandomizeToggleButton.IsChecked}"
FormatString="F0"
ParsingNumberStyle="Integer"
Value="{Binding Seed, Mode=TwoWay}"
HorizontalAlignment="Stretch" />
<RepeatButton
Grid.Column="2"
Name="GenerateRandomSeedButton"
Command="{Binding GenerateNewSeedCommand}"
IsVisible="{Binding #RandomizeToggleButton.IsChecked}"
Margin="8,0,0,0">
<icons:Icon Margin="1" Value="fa-solid fa-rotate" />
</RepeatButton>
<ToggleButton
Name="RandomizeToggleButton"
ToolTip.Tip="{Binding RandomizeButtonToolTip}"
IsChecked="{Binding IsRandomizeEnabled}"
Grid.Column="3" Margin="8,0,0,0">
<Panel>
<icons:Icon
Margin="1"
Value="fa-solid fa-lock"
IsVisible="{Binding #RandomizeToggleButton.IsChecked}"/>
<icons:Icon
Margin="1"
Value="fa-solid fa-dice-d20"
IsVisible="{Binding !#RandomizeToggleButton.IsChecked}"/>
</Panel>
</ToggleButton>
</Grid>
</Grid>
</controls:Card>
</ControlTemplate>
</Setter>
</Style>
</Styles>

7
StabilityMatrix.Avalonia/Controls/SeedCard.axaml.cs

@ -0,0 +1,7 @@
using Avalonia.Controls.Primitives;
namespace StabilityMatrix.Avalonia.Controls;
public class SeedCard : TemplatedControl
{
}

25
StabilityMatrix.Avalonia/DesignData/DesignData.cs

@ -10,6 +10,7 @@ using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels;
using StabilityMatrix.Avalonia.ViewModels.Dialogs;
using StabilityMatrix.Avalonia.ViewModels.Inference;
using StabilityMatrix.Core.Api;
using StabilityMatrix.Core.Database;
using StabilityMatrix.Core.Helper;
@ -334,4 +335,28 @@ public static class DesignData
{
State = ProgressState.Success
};
public static SeedCardViewModel SeedCardViewModel => new();
public static Indexer Types => new();
public class Indexer
{
public object? this[string typeName]
{
get
{
var type = Type.GetType(typeName) ??
throw new ArgumentException($"Type {typeName} not found");
try
{
return Services.GetService(type);
}
catch (InvalidOperationException)
{
return Activator.CreateInstance(type);
}
}
}
}
}

Loading…
Cancel
Save