SPARK-1917 - resizable order entry panel

This commit is contained in:
Jake Norbut committed 2018-12-12 09:23:45 -06:00
1 parent 6b24745ae8
commit dcaae15e28
4 files changed
+48 -17

No files matched your search

@@ -180,6 +180,8 @@ namespace mbts.spark {
// Settings are liable to change in the near future, so an internal IEqualityComparer simply won't do as it risks becoming out of date.
[ProtoContract]
class LadderSettings : IEquatable<LadderSettings> {
const double _default_order_entry_panel_width = 110.0;
// Default proto constructor
// Added this so that when clients upgrade to a version with new settings,
// the default values are applied correctly; thx to John for this tip
@@ -199,6 +201,7 @@ namespace mbts.spark {
cancel_sells_visible = true;
cancel_all_visible = true;
auto_clear_visible = true;
order_entry_panel_initial_width = _default_order_entry_panel_width;
}
public static LadderSettings Default {
@@ -253,7 +256,8 @@ namespace mbts.spark {
cancel_buys_visible = true,
cancel_sells_visible = true,
cancel_all_visible = true,
auto_clear_visible = true
auto_clear_visible = true,
order_entry_panel_initial_width = _default_order_entry_panel_width
};
}
}
@@ -346,7 +350,10 @@ namespace mbts.spark {
public bool cancel_all_visible { get; set; }
[ProtoMember(41), DefaultValue(true)]
public bool auto_clear_visible { get; set; }
//
[ProtoMember(42), DefaultValue(_default_order_entry_panel_width)]
public double order_entry_panel_initial_width { get; set; }
public bool Equals(LadderSettings other) =>
other != null &&
@@ -387,7 +394,8 @@ namespace mbts.spark {
cancel_buys_visible == other.cancel_buys_visible &&
cancel_sells_visible == other.cancel_sells_visible &&
cancel_all_visible == other.cancel_all_visible &&
auto_clear_visible == other.auto_clear_visible
auto_clear_visible == other.auto_clear_visible &&
order_entry_panel_initial_width == other.order_entry_panel_initial_width
;
public override bool Equals(object obj) => Equals(obj as LadderSettings);
@@ -431,7 +439,8 @@ namespace mbts.spark {
cancel_buys_visible.GetHashCode(),
cancel_sells_visible.GetHashCode(),
cancel_all_visible.GetHashCode(),
auto_clear_visible.GetHashCode()
auto_clear_visible.GetHashCode(),
order_entry_panel_initial_width.GetHashCode()
);
}
@@ -16,6 +16,7 @@ namespace mbts.spark {
class LadderSettingsVM : ViewModelBase, IWindowSettingsVM<LadderSettings>, ITemplateSelectorKey {
readonly Property<LadderSettings.BadgeStyle> _badge_style;
readonly Property<uint> _alternate_order_size;
readonly double _order_entry_panel_width;
readonly DelegateProperty<double> _row_height;
LadderSettings _current;
LadderColumnSettingsVM
@@ -50,13 +51,15 @@ namespace mbts.spark {
_cancel_all_visibility = new OrderEntryPanelItemVisibilityVM("Cancel All");
public LadderSettingsVM(bool is_synthetic) {
public LadderSettingsVM(bool is_synthetic, double left_panel_width) {
this.is_synthetic = is_synthetic;
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));
_order_entry_panel_width = left_panel_width;
// be sure to initialize backings before this measure_row_height call
_row_height = backing(nameof(row_height), () => LadderRender.measure_row_height(get_result()));
_orders.font_size_changed += on_font_size_changed;
_bid.font_size_changed += on_font_size_changed;
@@ -180,6 +183,10 @@ namespace mbts.spark {
_cancel_buys_visibility.show = settings.cancel_buys_visible;
_cancel_sells_visibility.show = settings.cancel_sells_visible;
_cancel_all_visibility.show = settings.cancel_all_visible;
// do not read the order entry panel width here from settings
// because it could have changed from the UI
// there might be a better way of doing this, like how
// does the widths of the ladder grid column pull this off?
}
public LadderSettings get_result() {
@@ -216,6 +223,7 @@ namespace mbts.spark {
clone.cancel_buys_visible = _cancel_buys_visibility.show;
clone.cancel_sells_visible = _cancel_sells_visibility.show;
clone.cancel_all_visible = _cancel_all_visibility.show;
clone.order_entry_panel_initial_width = _order_entry_panel_width;
return clone;
}
+12 -2
View File
@@ -24,6 +24,7 @@ namespace mbts.spark {
readonly IBus _bus;
readonly LadderModel _model;
readonly Property<double> _left_panel_width;
readonly Property<double> _high, _low, _change, _open, _settlement, _position;
readonly Property<ulong> _volume;
readonly Property<bool> _auto_clear, _show_day, _show_high, _show_low, _show_open, _show_settle, _show_volume, _show_account,
@@ -83,6 +84,7 @@ namespace mbts.spark {
backing(name, settings_manager.subscribe_current().OnDispatcher(), get_bool);
//
_left_panel_width = backing(nameof(left_panel_width), settings_manager.subscribe_current().OnDispatcher().Select(s => s.order_entry_panel_initial_width));
position_click_command = new DelegateCommand(() => size_calculator.value = DoubleHelper.safe_convert_to_uint(Math.Abs(position)));
send_order_command = new DelegateCommand<(double price, Side? side, bool size_from_alternate)>(send_order);
cancel_command = new AsyncCommand<LadderModel.CancelType>(_model.cancel_orders, true);
@@ -91,8 +93,8 @@ namespace mbts.spark {
settings_command = new DialogCommand(() => {
var vm = new WindowSettingsDialogVM<LadderSettings, LadderSettingsVM>(
settings_manager, s => s.ladder, UserSettings.FileExtensions.LADDER,
s => {
var svm = new LadderSettingsVM(security.ContractCase == Security.ContractOneofCase.Synthetic);
s => {
var svm = new LadderSettingsVM(security.ContractCase == Security.ContractOneofCase.Synthetic, left_panel_width);
svm.load(s);
return svm;
});
@@ -272,6 +274,7 @@ namespace mbts.spark {
public bool show_cancel_buys { get => _show_cancel_buys.Value; set => _show_cancel_buys.set(value); }
public bool show_cancel_sells { get => _show_cancel_sells.Value; set => _show_cancel_sells.set(value); }
public bool show_cancel_all { get => _show_cancel_all.Value; set => _show_cancel_all.set(value); }
public double left_panel_width { get => _left_panel_width.Value; set => _left_panel_width.set(value); }
internal LadderModel model => _model;
internal IObservable<LadderSettings> settings => _settings_manager.subscribe_current();
@@ -281,6 +284,13 @@ namespace mbts.spark {
return null;
var settings_clone = SparkUtils.clone_proto(_settings_manager.instance_settings);
settings_clone.default_order_type = order_properties_vm.selected_order_type?.order_type ?? settings_clone.default_order_type;
// the user would need to have set some kind of customization in the
// main settings form first for instance settings to have been saved at some point.
// After which, it's possible they will adjust the panel width without explicitly
// going into the settings form again.
// Right now I will save this change ...
settings_clone.order_entry_panel_initial_width = left_panel_width;
return settings_clone;
}
@@ -27,6 +27,7 @@
</converters:BooleanToObjectConverter>
<converters:EnumCharacterCasingConverter x:Key="casing_converter"/>
<converters:DoubleTextConverter x:Key="PositionTextConverter" Format="0" NaNText="-"/>
<converters:GridLengthConverter x:Key="GridLengthPixelConverter" UnitType="Pixel" />
<Style TargetType="GridViewColumnHeader">
<Setter Property="Background" Value="{mbts:BTSColor header}"/>
<Setter Property="Foreground" Value="{mbts:BTSColor header_text}"/>
@@ -267,8 +268,8 @@
<AdornerDecorator>
<Grid x:Name="_root">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="112"/>
<ColumnDefinition Width="2"/>
<ColumnDefinition Width="{Binding left_panel_width, Mode=TwoWay, Converter={StaticResource GridLengthPixelConverter}}"
MinWidth="70" MaxWidth="150"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
@@ -281,14 +282,13 @@
<RowDefinition Height="*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Margin="5,0">
<StackPanel.Resources>
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</StackPanel.Resources>
<Grid Margin="8,4,0,0">
<Grid Margin="4,4,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
@@ -304,7 +304,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Day -->
<TextBlock Grid.Column="0" Grid.Row="0" Text="Day"
<TextBlock Grid.Column="0" Grid.Row="0" Text="D:" ToolTip="Day"
Margin="0,0,0,4"
Visibility="{Binding show_day, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<TextBlock Grid.Column="2" Grid.Row="0" FontWeight="Bold"
@@ -319,7 +319,7 @@
</TextBlock.Text>
</TextBlock>
<!-- High -->
<TextBlock Grid.Column="0" Grid.Row="1" Text="High"
<TextBlock Grid.Column="0" Grid.Row="1" Text="H:" ToolTip="High"
Margin="0,0,0,4"
Visibility="{Binding show_high, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<TextBlock Grid.Column="2" Grid.Row="1" Foreground="{mbts:BTSColor UI.default_text}" FontWeight="Bold"
@@ -333,7 +333,7 @@
</TextBlock.Text>
</TextBlock>
<!-- Low -->
<TextBlock Grid.Column="0" Grid.Row="2" Text="Low"
<TextBlock Grid.Column="0" Grid.Row="2" Text="L:" ToolTip="Low"
Margin="0,0,0,4"
Visibility="{Binding show_low, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<TextBlock Grid.Column="2" Grid.Row="2" Foreground="{mbts:BTSColor UI.default_text}" FontWeight="Bold"
@@ -347,7 +347,7 @@
</TextBlock.Text>
</TextBlock>
<!-- Open -->
<TextBlock Grid.Column="0" Grid.Row="3" Text="Open"
<TextBlock Grid.Column="0" Grid.Row="3" Text="O:" ToolTip="Open"
Margin="0,0,0,4"
Visibility="{Binding show_open, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<TextBlock Grid.Column="2" Grid.Row="3" FontWeight="Bold"
@@ -361,7 +361,7 @@
</TextBlock.Text>
</TextBlock>
<!-- Settle -->
<TextBlock Grid.Column="0" Grid.Row="4" Text="Settle"
<TextBlock Grid.Column="0" Grid.Row="4" Text="S:" ToolTip="Settle"
Margin="0,0,0,4"
Visibility="{Binding show_settle, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<TextBlock Grid.Column="2" Grid.Row="4" FontWeight="Bold"
@@ -375,7 +375,7 @@
</TextBlock.Text>
</TextBlock>
<!-- Volume -->
<TextBlock Grid.Column="0" Grid.Row="5" Text="Volume"
<TextBlock Grid.Column="0" Grid.Row="5" Text="V:" ToolTip="Volume"
Margin="0,0,0,4"
Visibility="{Binding show_volume, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<TextBlock Grid.Column="2" Grid.Row="5" Text="{Binding volume, Mode=OneWay}" FontWeight="Bold"
@@ -545,6 +545,10 @@
</ControlTemplate>
</Button.Template>
</Button>
<!-- Since the GridSplitter will share a cell with other elements,
we add it in last so that it has the topmost Z order
-->
<GridSplitter Grid.Column="0" Grid.RowSpan="2" Width="5" />
</Grid>
</AdornerDecorator>
</UserControl>