SPARK-1544 Ability to change number pad quantities in Ladder
This commit is contained in:
1 parent
b5e6cfea8f
commit
6608bee39f
5 files changed
+127
-6
No files matched your search
@@ -4,6 +4,11 @@ using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.collections {
|
||||
static class ObservableEditableCollection {
|
||||
public static ObservableEditableCollection<T> create<T>() where T : new() =>
|
||||
new ObservableEditableCollection<T>(() => new T());
|
||||
}
|
||||
|
||||
class ObservableEditableCollection<T> : ObservableCollection<T> {
|
||||
public ObservableEditableCollection(Func<T> factory, bool insert_new_item_at_front = false) {
|
||||
AddItemCommand = insert_new_item_at_front ? new DelegateCommand(() => Insert(0, factory())) : new DelegateCommand(() => Add(factory()));
|
||||
|
||||
@@ -5,6 +5,7 @@ using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -30,6 +31,10 @@ namespace mbts.spark {
|
||||
void load_from(T value);
|
||||
}
|
||||
|
||||
interface IMutableValueWrapperVM<T> : INotifyPropertyChanged {
|
||||
T value { get; set; }
|
||||
}
|
||||
|
||||
interface IViewValue {
|
||||
object value { get; }
|
||||
object view { get; }
|
||||
@@ -70,6 +75,12 @@ namespace mbts.spark {
|
||||
return vm;
|
||||
}
|
||||
|
||||
public static IMutableValueWrapperVM<T> create_mutable_vm<T>(T init = default) =>
|
||||
create_mutable_vm(EqualityComparer<T>.Default, init);
|
||||
|
||||
public static IMutableValueWrapperVM<T> create_mutable_vm<T>(IEqualityComparer<T> comparer, T init = default) =>
|
||||
new MutableValueWrapperVM<T>(comparer, init);
|
||||
|
||||
public static ITemplatedPropertyWrapperVM<TSource> create_vm<TSource, TValue>(string template_key, Func<TSource, TValue> get, Action<TSource, TValue> set, Dictionary<string, IObservable<object>> named_params = null) =>
|
||||
new DelegatePropertyWrapperVM<TSource, TValue>(template_key, get, set, named_params);
|
||||
|
||||
@@ -88,6 +99,20 @@ namespace mbts.spark {
|
||||
public static IPropertyWrapperVM<TOutter> link<TOutter, TInner>(this IPropertyWrapperVM<TInner> inner, Func<TOutter, TInner> get, Action<TOutter, TInner> set) =>
|
||||
new LinkedPropertyWrapperVM<TOutter, TInner>(inner, get, set);
|
||||
|
||||
class MutableValueWrapperVM<T> : ViewModelBase, IMutableValueWrapperVM<T> {
|
||||
readonly IEqualityComparer<T> _comparer;
|
||||
readonly Property<T> _value;
|
||||
|
||||
public MutableValueWrapperVM(IEqualityComparer<T> comparer, T init) {
|
||||
_comparer = comparer;
|
||||
_value = backing(nameof(value), comparer, init);
|
||||
}
|
||||
|
||||
public T value { get => _value.Value; set => _value.set(value); }
|
||||
|
||||
public override string ToString() => value?.ToString();
|
||||
}
|
||||
|
||||
class LinkedPropertyWrapperVM<TOutter, TInner> : ViewModelBase, IPropertyWrapperVM<TOutter> {
|
||||
readonly Func<TOutter, TInner> _get;
|
||||
readonly Action<TOutter, TInner> _set;
|
||||
|
||||
@@ -113,8 +113,11 @@ namespace mbts.ui.shell
|
||||
protected delegate void PropertyChange<T>(T oldval, T newval);
|
||||
|
||||
// use nameof() to add compile time checks
|
||||
protected Property<T> backing<T>(string name, T default_value = default(T)) {
|
||||
return new Property<T>(this, name, default_value);
|
||||
protected Property<T> backing<T>(string name, T default_value = default(T)) =>
|
||||
backing(name, EqualityComparer<T>.Default, default_value);
|
||||
|
||||
protected Property<T> backing<T>(string name, IEqualityComparer<T> comparer, T default_value = default(T)) {
|
||||
return new Property<T>(this, name, comparer, default_value);
|
||||
}
|
||||
|
||||
protected Property<T> backing<T>(Expression<Func<T>> member, T default_value) {
|
||||
@@ -134,12 +137,17 @@ namespace mbts.ui.shell
|
||||
|
||||
protected class Property<T> : IObservable<(T oldval,T newval)> {
|
||||
readonly string _propname;
|
||||
readonly IEqualityComparer<T> _comparer;
|
||||
readonly ViewModelBase _owner;
|
||||
T _value;
|
||||
|
||||
public Property(ViewModelBase owner, string name, T default_value) {
|
||||
public Property(ViewModelBase owner, string name, T default_value)
|
||||
: this(owner, name, EqualityComparer<T>.Default, default_value) { }
|
||||
|
||||
public Property(ViewModelBase owner, string name, IEqualityComparer<T> comparer, T default_value) {
|
||||
_owner = owner;
|
||||
_propname = name;
|
||||
_comparer = comparer;
|
||||
_value = default_value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using bts.api;
|
||||
using mbts.collections;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls.color_picker;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -32,6 +32,8 @@ namespace mbts.spark {
|
||||
_session_range_fill = new LadderMarketBreakLineVM("Session Range", 0, 0, false);
|
||||
|
||||
public LadderSettingsVM() {
|
||||
size_presets = new ObservableEditableCollection<IMutableValueWrapperVM<uint>>(_create_size_preset_vm);
|
||||
size_presets.CollectionChanged += (s, e) => RaisePropertyChanged(nameof(size_presets_text));
|
||||
_badge_style = backing<LadderSettings.BadgeStyle>(nameof(badge_style));
|
||||
_badge_style.Changed += _badge_style_Changed;
|
||||
_alternate_order_size = backing<uint>(nameof(alternate_order_size));
|
||||
@@ -81,6 +83,8 @@ namespace mbts.spark {
|
||||
public LadderColumnSettingsVM ask_column => _ask;
|
||||
public LadderColumnSettingsVM last_column => _last;
|
||||
public LadderMarketBreakLineVM session_range_fill => _session_range_fill;
|
||||
public ObservableEditableCollection<IMutableValueWrapperVM<uint>> size_presets { get; }
|
||||
public string size_presets_text => string.Join(", ", size_presets);
|
||||
|
||||
public IEnumerable<LadderMarketBreakLineVM> mkt_break_items {
|
||||
get {
|
||||
@@ -97,6 +101,7 @@ namespace mbts.spark {
|
||||
_current = settings;
|
||||
badge_style = settings.badge_style;
|
||||
alternate_order_size = settings.alternate_order_size;
|
||||
size_presets.SetItems(settings.calculator_buttons.empty_if_null().Select(s => _create_size_preset_vm((uint)s)));
|
||||
_orders.assign_from(_current.orders_column);
|
||||
_bid.assign_from(_current.bid_column);
|
||||
_ask.assign_from(_current.ask_column);
|
||||
@@ -114,6 +119,7 @@ namespace mbts.spark {
|
||||
var clone = SparkUtils.clone_proto(_current);
|
||||
clone.badge_style = badge_style;
|
||||
clone.alternate_order_size = alternate_order_size;
|
||||
clone.calculator_buttons = size_presets.Select(vm => (int)vm.value).ToArray();
|
||||
clone.orders_column = _orders.get_settings();
|
||||
clone.bid_column = _bid.get_settings();
|
||||
clone.price_column = _price.get_settings();
|
||||
@@ -128,6 +134,13 @@ namespace mbts.spark {
|
||||
clone.row_height = LadderRender.measure_row_height(clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
IMutableValueWrapperVM<uint> _create_size_preset_vm() => _create_size_preset_vm(0);
|
||||
IMutableValueWrapperVM<uint> _create_size_preset_vm(uint init) {
|
||||
var vm = PropertyWrapperVMUtils.create_mutable_vm(init);
|
||||
vm.PropertyChanged += (s, e) => RaisePropertyChanged(nameof(size_presets_text));
|
||||
return vm;
|
||||
}
|
||||
|
||||
public class LadderColumnSettingsVM : ViewModelBase {
|
||||
readonly Property<double> _font_size;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<sys:Double x:Key="VerticalPush">4</sys:Double>
|
||||
<sys:Double x:Key="VerticalSectionBreak">6</sys:Double>
|
||||
<sys:Double x:Key="VerticalSplit">8</sys:Double>
|
||||
<sys:Double x:Key="CollapsedSizePresetsHeight">24</sys:Double>
|
||||
<cv:ValueMap x:Key="ColumnSpanToVisibilityConverter" Default="{u:Visibility Visible}">
|
||||
<cv:KeyValue Key="{u:Int 0}" Value="{u:Visibility Collapsed}"/>
|
||||
</cv:ValueMap>
|
||||
@@ -69,6 +70,8 @@
|
||||
</UserControl.Resources>
|
||||
<Grid Grid.IsSharedSizeScope="True">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -86,9 +89,76 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="1" VerticalAlignment="Center">Order Badge Style</TextBlock>
|
||||
<ComboBox Grid.Column="3" ItemsSource="{u:EnumBindingSource {u:Nested sp:LadderSettings.BadgeStyle}}" SelectedItem="{Binding badge_style}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="1" VerticalAlignment="Center">Alternate Order Qty</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="3" Text="{Binding alternate_order_size}" u:TextBoxBehavior.InputFilter="{u:RegexInputFilter Regex={x:Static Member=Integer, MemberType={u:Nested txt:TextUtils.RegexFilters}}}"/>
|
||||
<GroupBox Grid.Row="4" Grid.ColumnSpan="5" Padding="8" Header="Fonts and Colors">
|
||||
|
||||
<GroupBox Grid.Row="4" Grid.ColumnSpan="5" VerticalAlignment="Center">
|
||||
<GroupBox.Style>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsChecked, ElementName=SizePresetsExpanderToggle}" Value="{u:False}">
|
||||
<Setter Property="Height" Value="{StaticResource CollapsedSizePresetsHeight}"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</GroupBox.Style>
|
||||
<GroupBox.Header>
|
||||
<c:ExpanderToggleButton x:Name="SizePresetsExpanderToggle">
|
||||
<TextBlock>
|
||||
<TextBlock.Inlines>
|
||||
<Run Text="Size Presets"/>
|
||||
<Run FontStyle="Italic" Text="{Binding size_presets_text, StringFormat='{}({0})', Mode=OneWay}">
|
||||
<Run.Style>
|
||||
<Style TargetType="Run">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsChecked, ElementName=SizePresetsExpanderToggle}" Value="{u:True}">
|
||||
<Setter Property="Text" Value="{x:Static sys:String.Empty}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Run.Style>
|
||||
</Run>
|
||||
</TextBlock.Inlines>
|
||||
</TextBlock>
|
||||
</c:ExpanderToggleButton>
|
||||
</GroupBox.Header>
|
||||
<Grid HorizontalAlignment="Left">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ItemsControl ItemsSource="{Binding size_presets}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Columns="2" Focusable="False"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="52"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button
|
||||
Command="{Binding DataContext.size_presets.RemoveItemCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding}"
|
||||
Style="{StaticResource RoundCloseButton}"
|
||||
/>
|
||||
<c:TickUpDownUInt Grid.Column="1" Margin="2,0,0,0" Value="{Binding value}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Grid.Row="2" Command="{Binding size_presets.AddItemCommand}">
|
||||
Add Size
|
||||
</Button>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="6" Grid.ColumnSpan="5" Padding="8" Header="Fonts and Colors">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="27"/>
|
||||
@@ -161,7 +231,7 @@
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="6" Grid.ColumnSpan="5" Padding="8" Header="Market Break Lines">
|
||||
<GroupBox Grid.Row="8" Grid.ColumnSpan="5" Padding="8" Header="Market Break Lines">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="27"/>
|
||||
|
||||
Reference in new issue
Block a user