53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System;
|
|
using Intromat.Views.Editors;
|
|
using NodeNetwork.Toolkit.ValueNode;
|
|
using ReactiveUI;
|
|
using Splat;
|
|
|
|
namespace Intromat.ViewModels.Editors
|
|
{
|
|
public class FloatValueEditorViewModel : ValueEditorViewModel<float>
|
|
{
|
|
private float _minValue;
|
|
private float _maxValue;
|
|
|
|
static FloatValueEditorViewModel()
|
|
{
|
|
Locator.CurrentMutable.Register(() => new FloatValueEditorView(), typeof(IViewFor<FloatValueEditorViewModel>));
|
|
}
|
|
|
|
public FloatValueEditorViewModel(float min = 0, float max = 1)
|
|
{
|
|
MinValue = min;
|
|
MaxValue = max;
|
|
Value = 0;
|
|
|
|
this.WhenAnyValue(vm => vm.Value)
|
|
.Subscribe(newValue =>
|
|
{
|
|
if (newValue > MaxValue)
|
|
{
|
|
var delta = newValue - MinValue;
|
|
MaxValue = newValue + delta;
|
|
}
|
|
else if (newValue < MinValue)
|
|
{
|
|
var delta = MaxValue - newValue;
|
|
MinValue = newValue - delta;
|
|
}
|
|
});
|
|
}
|
|
|
|
public float MinValue
|
|
{
|
|
get => _minValue;
|
|
set => this.RaiseAndSetIfChanged(ref _minValue, value);
|
|
}
|
|
|
|
public float MaxValue
|
|
{
|
|
get => _maxValue;
|
|
set => this.RaiseAndSetIfChanged(ref _maxValue, value);
|
|
}
|
|
}
|
|
} |