fix: Set init val through display-translator in SizeCalculator

The init val was being passed to the erroneous `UserProperty<T?> _value` field,
which should have been deleted when the _display_translator was introduced.

Bugs (fixed):
   * the ladder-view's initial size field is null when
This commit is contained in:
John Colvin committed 2022-04-19 11:42:44 -04:00
1 parent 0afd06be9c
commit 0f0d8df572
1 file changed
+13 -5
@@ -1,6 +1,5 @@
namespace mbts.spark {
using bts.api.domain;
using bts.utils;
using mbts.ui;
using mbts.ui.shell;
@@ -10,16 +9,18 @@
using System.Windows.Input;
public class CalculatorLogic<T> : DisposableViewModelBase where T : struct, IFloatingPoint<T> {
readonly UserProperty<T?> _value;
readonly OptionalDisplayQuantityMultiplier<T> _display_translator = new();
TickDisplaySettingsImmutable _display_settings =
SecurityDataHelper.Defaults.quantity_display_settingsi;
bool _value_setter_called;
IDisposable _prop_changes_echo;
T[] _buttons;
public CalculatorLogic(T? initial_size) {
_value = new UserProperty<T?>(backing(nameof(value), initial_size));
if (initial_size.HasValue) {
bypass_value_setter(initial_size.Value, true);
}
_echo_props_changed();
}
@@ -37,7 +38,10 @@
}
public T? display_value {
get => _display_translator.display_value;
set => _display_translator.display_value = value;
set {
_display_translator.display_value = value;
value_setter_called = true;
}
}
public TickDisplaySettingsImmutable display_settings {
get => _display_settings;
@@ -50,7 +54,11 @@
public double unit_quantity =>
display_settings.TickFactors.to_tick_factors().tick_unit_frac();
public bool value_setter_called => _value.setter_called;
public bool value_setter_called {
get => _value_setter_called;
set => Set(ref _value_setter_called, value);
}
public T[] buttons { get => _buttons; set => Set(ref _buttons, value); }
public ICommand click => new DelegateCommand<T>(handle_calculator_click);
public ICommand set_display_value_command => new DelegateCommand<T>(v => _display_translator.display_value = v);