Add most of the UI code for profile configuration

This commit is contained in:
Robert committed 2026-01-24 13:06:08 +01:00
1 parent 3004293051
commit 77a4d8201e
29 files changed
+508 -68

No files matched your search

@@ -0,0 +1,8 @@
namespace Artemis.Core;
/// <summary>
/// Represents a configuration item that accepts ColorGradient input from the user.
/// </summary>
public class ConfigurationColorGradientItem : ConfigurationInputItem<ColorGradient>
{
}
@@ -5,4 +5,7 @@
/// </summary>
public class ConfigurationNumericItem : ConfigurationInputItem<Numeric>
{
public Numeric? Minimum { get; set; }
public Numeric? Maximum { get; set; }
public bool Slider { get; set; }
}
@@ -308,12 +308,12 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable,
ConfigurationSections.Add(new ConfigurationSection()
{
Name = "General (slot 0)",
Slot = 0,
Slot = 2,
});
ConfigurationSections.Add(new ConfigurationSection()
{
Name = "Other (slot 1)",
Slot = 1
Slot = 2
});
ConfigurationSections.Add(new ConfigurationSection()
{
@@ -321,11 +321,14 @@ public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable,
Slot = 2
});
ConfigurationSections[0].Items.Add(new ConfigurationTextItem() {Text = "This is a placeholder text item in the General section."});
ConfigurationSections[0].Items.Add(new ConfigurationNumericItem() {Name = "Numeric item"});
ConfigurationSections[0].Items.Add(new ConfigurationNumericItem() {Name = "Numeric item", Description = "This one also has a description"});
ConfigurationSections[0].Items.Add(new ConfigurationBooleanItem() {Name = "Do the thing?", TrueText = "Absolutely", FalseText = "Nope"});
ConfigurationSections[1].Items.Add(new ConfigurationTextItem() {Text = "This is a placeholder text item in the Other section."});
ConfigurationSections[2].Items.Add(new ConfigurationTextItem() {Text = "This is a placeholder text item in the Something else section."});
ConfigurationSections[2].Items.Add(new ConfigurationTextItem() {Text = "This is another placeholder text item in the Something else section."});
ConfigurationSections[2].Items.Add(new ConfigurationNumericItem() {Name = "Numeric item", Description = "This one uses a slider", Minimum = 0, Maximum = 10, Slider = true});
ConfigurationSections[2].Items.Add(new ConfigurationColorGradientItem() {Name = "Color gradient"});
ConfigurationSections[2].Items.Add(new ConfigurationSKColorItem() {Name = "A simple color", Description = "Again with a description"});
}
/// <inheritdoc />
+3 -1
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
namespace Artemis.Core;
@@ -11,7 +12,8 @@ namespace Artemis.Core;
/// Usage outside that context is not recommended due to conversion overhead.
/// </para>
/// </summary>
public readonly struct Numeric : IComparable<Numeric>, IConvertible
[TypeConverter(typeof(NumericTypeConverter))]
public readonly struct Numeric : IComparable<Numeric>, IConvertible, IEquatable<Numeric>
{
private readonly float _value;
@@ -0,0 +1,90 @@
using System;
using System.ComponentModel;
using System.Globalization;
namespace Artemis.Core;
/// <summary>
/// Type converter for <see cref="Numeric" /> to support Avalonia binding from other numeric types
/// </summary>
public class NumericTypeConverter : TypeConverter
{
/// <inheritdoc />
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
return sourceType == typeof(double) ||
sourceType == typeof(float) ||
sourceType == typeof(int) ||
sourceType == typeof(long) ||
sourceType == typeof(byte) ||
sourceType == typeof(short) ||
sourceType == typeof(decimal) ||
sourceType == typeof(uint) ||
sourceType == typeof(ulong) ||
sourceType == typeof(ushort) ||
sourceType == typeof(sbyte) ||
sourceType == typeof(string) ||
base.CanConvertFrom(context, sourceType);
}
/// <inheritdoc />
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
{
return destinationType == typeof(double) ||
destinationType == typeof(float) ||
destinationType == typeof(int) ||
destinationType == typeof(long) ||
destinationType == typeof(byte) ||
destinationType == typeof(short) ||
destinationType == typeof(decimal) ||
destinationType == typeof(uint) ||
destinationType == typeof(ulong) ||
destinationType == typeof(ushort) ||
destinationType == typeof(sbyte) ||
destinationType == typeof(string) ||
base.CanConvertTo(context, destinationType);
}
/// <inheritdoc />
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
return value switch
{
double d => new Numeric(d),
float f => new Numeric(f),
int i => new Numeric(i),
long l => new Numeric(l),
byte b => new Numeric(b),
short s => new Numeric(s),
decimal dec => new Numeric((double)dec),
uint ui => new Numeric(ui),
ulong ul => new Numeric((long)ul),
ushort us => new Numeric(us),
sbyte sb => new Numeric(sb),
string str => Numeric.TryParse(str, out Numeric result) ? result : throw new FormatException($"Unable to convert '{str}' to Numeric"),
_ => base.ConvertFrom(context, culture, value)
};
}
/// <inheritdoc />
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
if (value is Numeric numeric)
{
if (destinationType == typeof(double)) return (double)numeric;
if (destinationType == typeof(float)) return (float)numeric;
if (destinationType == typeof(int)) return (int)numeric;
if (destinationType == typeof(long)) return (long)numeric;
if (destinationType == typeof(byte)) return (byte)numeric;
if (destinationType == typeof(short)) return (short)numeric;
if (destinationType == typeof(decimal)) return (decimal)numeric;
if (destinationType == typeof(uint)) return (uint)numeric;
if (destinationType == typeof(ulong)) return (ulong)numeric;
if (destinationType == typeof(ushort)) return (ushort)numeric;
if (destinationType == typeof(sbyte)) return (sbyte)numeric;
if (destinationType == typeof(string)) return numeric.ToString(CultureInfo.InvariantCulture);
}
return base.ConvertTo(context, culture, value, destinationType);
}
}