port from perforce
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Intromat.Nodes.Code;
|
||||
using Intromat.Views.Editors;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
|
||||
namespace Intromat.ViewModels.Editors
|
||||
{
|
||||
public class FloatExpressionEditorViewModel : ExpressionEditorBaseViewModel<float, FloatLiteralValue, FloatLiteralModel>
|
||||
{
|
||||
private float _maxValue;
|
||||
private float _minValue;
|
||||
|
||||
static FloatExpressionEditorViewModel()
|
||||
{
|
||||
Locator.CurrentMutable.Register(() => new FloatExpressionEditorView(), typeof(IViewFor<FloatExpressionEditorViewModel>));
|
||||
}
|
||||
|
||||
public FloatExpressionEditorViewModel()
|
||||
{
|
||||
this.WhenAnyValue(vm => vm.Value)
|
||||
.Subscribe(t =>
|
||||
{
|
||||
var newValue = t!.Evaluate();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user