using System; using System.Diagnostics.CodeAnalysis; namespace DesktopMagic.Api.Settings; /// /// Represents a slider control. /// public sealed class Slider : Setting { private double _value; /// /// Gets or sets the maximum value for the element. /// public double Maximum { get; } /// /// Gets or sets the minimum value for the element. /// public double Minimum { get; } /// /// Gets or sets the value assigned to the element. /// [SuppressMessage("Major Bug", "S1244:Floating point numbers should not be tested for equality", Justification = "Not applicable here since we want to detect changes in the value.")] public double Value { get => _value; set { if (_value != value) { _value = value; ValueChanged(); } } } /// /// Initializes a new instance of the class with the provided value, value and . /// /// The maximum value for the element. /// The minimum value for the element. /// The value assigned to the element. public Slider(double min, double max, double value = 0) { 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; } internal override string GetJsonValue() { return Value.ToString(); } internal override void SetJsonValue(string value) { _ = double.TryParse(value, out double result); Value = result; } }