mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 23:39:29 +02:00
Improved plugin settings support
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
{
|
||||
public class CheckBox : Element
|
||||
{
|
||||
private bool _value;
|
||||
|
||||
public bool Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
if (_value != value)
|
||||
{
|
||||
_value = value;
|
||||
ValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CheckBox(bool value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
{
|
||||
public abstract class Element
|
||||
{
|
||||
public event Action OnValueChanged;
|
||||
|
||||
protected void ValueChanged()
|
||||
{
|
||||
OnValueChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)
|
||||
]
|
||||
public class ElementAttribute : Attribute
|
||||
{
|
||||
public string Name { get; }
|
||||
public int OrderIndex { get; }
|
||||
|
||||
public ElementAttribute(string name, int orderIndex = 0)
|
||||
{
|
||||
Name = name;
|
||||
OrderIndex = orderIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
{
|
||||
public class Heading : Element
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
public Heading(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
{
|
||||
public class IntegerUpDown : Element
|
||||
{
|
||||
private int _value;
|
||||
public int Maximum { get; }
|
||||
public int Minimum { get; }
|
||||
|
||||
public int Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
if (_value != value)
|
||||
{
|
||||
_value = value;
|
||||
ValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IntegerUpDown(int min, int max, int value = 0)
|
||||
{
|
||||
if (min < 0)
|
||||
{
|
||||
throw new ArgumentException("Value can not be negative!", nameof(min));
|
||||
}
|
||||
if (max < 0)
|
||||
{
|
||||
throw new ArgumentException("Value can not be negative!", nameof(max));
|
||||
}
|
||||
if (min > max)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
|
||||
}
|
||||
if (value > max)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!");
|
||||
}
|
||||
if (value < min)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
|
||||
}
|
||||
|
||||
Minimum = min;
|
||||
Maximum = max;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
{
|
||||
public sealed class Slider : Element
|
||||
{
|
||||
private double _value;
|
||||
public double Maximum { get; }
|
||||
public double Minimum { get; }
|
||||
|
||||
public double Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
if (_value != value)
|
||||
{
|
||||
_value = value;
|
||||
ValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Slider(double min, double max, double value = 0)
|
||||
{
|
||||
if (min < 0)
|
||||
{
|
||||
throw new ArgumentException("Value can not be negative!", nameof(min));
|
||||
}
|
||||
if (max < 0)
|
||||
{
|
||||
throw new ArgumentException("Value can not be negative!", nameof(max));
|
||||
}
|
||||
if (min > max)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(min)} is greater than or equal to {nameof(max)}!");
|
||||
}
|
||||
if (value > max)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(value)} is greater than {nameof(max)}!");
|
||||
}
|
||||
if (value < min)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(value)} is less than {nameof(min)}!");
|
||||
}
|
||||
|
||||
Minimum = min;
|
||||
Maximum = max;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DesktopMagicPluginAPI.Inputs
|
||||
{
|
||||
public class TextBox : Element
|
||||
{
|
||||
private string _value;
|
||||
|
||||
public string Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
if (_value != value)
|
||||
{
|
||||
_value = value;
|
||||
ValueChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextBox(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user