port from perforce
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using Intromat.Views.Editors;
|
||||
using NodeNetwork.Toolkit.ValueNode;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
|
||||
namespace Intromat.ViewModels.Editors
|
||||
{
|
||||
public class IntegerValueEditorViewModel : ValueEditorViewModel<int>
|
||||
{
|
||||
private int _minValue;
|
||||
private int _maxValue;
|
||||
|
||||
static IntegerValueEditorViewModel()
|
||||
{
|
||||
Locator.CurrentMutable.Register(() => new IntegerValueEditorView(), typeof(IViewFor<IntegerValueEditorViewModel>));
|
||||
}
|
||||
|
||||
public IntegerValueEditorViewModel(int min = 0, int max = 100)
|
||||
{
|
||||
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 int MinValue
|
||||
{
|
||||
get => _minValue;
|
||||
set => this.RaiseAndSetIfChanged(ref _minValue, value);
|
||||
}
|
||||
|
||||
public int MaxValue
|
||||
{
|
||||
get => _maxValue;
|
||||
set => this.RaiseAndSetIfChanged(ref _maxValue, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user