ui: Adjust ladder ticks-per-row with ctrl+shift+mousewheel

This commit is contained in:
John Colvin committed 2025-07-22 01:36:50 -04:00
1 parent 6539e94422
commit 85250a9769
5 files changed
+79 -7

No files matched your search

@@ -105,6 +105,7 @@ namespace mbts.spark {
ulong _misc_time = 0;
ulong _last_trade_time = 0;
ulong _last_bbo_time = 0;
uint? _ticks_per_row_override;
SpreaderType _spreader_type = SpreaderType.Requote;
IReadOnlyDictionary<uint, OrderRecordTuple> _cache = DictionaryHelper.empty<uint, OrderRecordTuple>();
ImmutableDictionary<AlgoKey, LadderFavoriteAlgoMetadata> _favorite_algo_metadata_map =
@@ -406,6 +407,7 @@ namespace mbts.spark {
public event Action? request_settings_dialog;
public event Action? request_recenter;
public event Action? settings_invalidated;
public event Action? ticks_per_row_changed;
public event Action<double>? request_go_to_price;
event Action<bool>? _on_disposed_impl;
@@ -458,6 +460,30 @@ namespace mbts.spark {
public double day_position => _day_position;
public double raw_day_position => _raw_day_position;
public ulong volume => _volume.Value;
public uint? ticks_per_row_override {
get => _ticks_per_row_override;
set {
if (_ticks_per_row_override.HasValue && value.HasValue && current_settings is not null) {
var oldval = _ticks_per_row_override.Value;
var newval = value.Value;
var stgval = current_settings.ticks_per_row;
// This value comes from a mouse-wheel input. If the new override crosses
// over the value in settings, set the override to null.
if (oldval != stgval && oldval > stgval != newval > stgval) {
_ticks_per_row_override = null;
_spec = null;
RaisePropertyChanged();
ticks_per_row_changed?.Invoke();
return;
}
}
if (Set(ref _ticks_per_row_override, value)) {
_spec = null;
RaisePropertyChanged(nameof(spec));
ticks_per_row_changed?.Invoke();
}
}
}
// left panel styles
public LadderPanelRelativePricePointVM day_change_style { get; } = new();
@@ -384,7 +384,7 @@ namespace mbts.spark {
if (_spec_backing is not null) {
return _spec_backing;
} else if (_vm != null) {
_spec_backing = TickUtils.multiply_tick_size(security.regional_ticks(), _settings?.ticks_per_row ?? 1);
_spec_backing = _vm.spec;
return _spec_backing;
}
return RegionalTickFactors.Default;
@@ -959,6 +959,7 @@ namespace mbts.spark {
local_vm.request_go_to_price += on_request_go_to_price;
_settings_sub = _vm.settings.OnDispatcher().Subscribe(_settings_updated);
_volume_sub = _vm.model.order_gateway.md_auxiliary_model.security_volume_at_price(security.Id).Subscribe(t => _volume_container.write_value(t.state.Values));
_vm.ticks_per_row_changed += on_ticks_per_row_changed;
// **unhook from local_vm.request_recenter.
// todo: organize these subs into a single entity, prob _vm_subs.
// This hasn't already been done bc the ladder a bit fragile, so changes must be carefully implemented,
@@ -967,6 +968,7 @@ namespace mbts.spark {
_vm_sub = Disposable.Create(() => {
local_vm.request_recenter -= on_request_recenter;
local_vm.request_go_to_price -= on_request_go_to_price;
local_vm.ticks_per_row_changed -= on_ticks_per_row_changed;
});
void on_request_go_to_price(double price) =>
@@ -976,6 +978,11 @@ namespace mbts.spark {
recenter_command?.ExecuteIfCan(null);
_refresh_frozen_mkt_lines();
}
void on_ticks_per_row_changed() {
// Forces redraw
_settings_updated(local_vm.current_settings);
}
}
}
@@ -1510,7 +1517,11 @@ namespace mbts.spark {
if (_price_list.Count > 0) {
var high_price = _price_list.First();
var new_tickdiff = _spec.count_ticks(high_price);
_price_list.high_tick = (long)new_tickdiff;
if (new_tickdiff.HasValue) {
_price_list.high_tick = (long)new_tickdiff;
} else {
Log.Ui.warn($"LadderGridHost failed to count ticks to 'high_price' {high_price} ({_spec})");
}
}
_price_list.regional_tick = _spec;
}
@@ -77,7 +77,14 @@ namespace mbts.spark {
public static int index_of(IList<double> prices, double price, IComparer<double> comparer, bool relative_idx) {
for (int i = 1; i < prices.Count; i++) {
Log.assert(prices[i - 1] > prices[i]);
if (!(prices[i - 1] > prices[i])) {
if (prices.All(double.IsNaN)) {
return -1;
}
var prices_str = ", ".join(prices);
Log.Ui.fatal($"LadderRender - unsorted prices: [{prices_str}]");
Log.assert(false);
}
}
var idx = CollectionHelper.binary_search(prices, price, comparer);
if (relative_idx && idx < 0) {
@@ -133,6 +133,25 @@ namespace mbts.spark {
private void LadderView_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) {
base.OnPreviewMouseWheel(e);
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) {
if (KeyboardExtensions.IsShiftDown()) {
var vm = _ladder.DataContext as LadderVM;
if (vm is not null) {
var tpr_delta = e.Delta / 10;
tpr_delta = tpr_delta.within_range(-10, 10);
if (tpr_delta == 0) {
tpr_delta = tpr_delta > 0 ? 1 : -1;
}
var ticks_per_row = vm.ticks_per_row_override ?? vm.current_settings?.ticks_per_row ?? 1;
if (tpr_delta < 0 && tpr_delta >= ticks_per_row) {
ticks_per_row = 1;
} else {
ticks_per_row = (uint)(ticks_per_row + tpr_delta);
}
ticks_per_row = ticks_per_row.within_range(1, 1_000_000);
vm.ticks_per_row_override = ticks_per_row;
}
return;
}
var delta = (e.Delta > 0) ? 0.1 : -0.1;
var proposed_scaler_value = _ui_scaler.Value + delta;
// Here we enforce the same contraints that are on the gui slider regarding min and max
@@ -1,18 +1,20 @@
using bts.utils;
using ProtoBuf;
using System;
using System.ComponentModel;
namespace mbts.user.settings {
[ProtoContract]
public class RegionalTickFactors : IEquatable<RegionalTickFactors> {
[ProtoMember(1)]
[ProtoContract]
public class RegionalTickFactors : IEquatable<RegionalTickFactors> {
[ProtoMember(1)]
readonly TickFactors _low_tick;
[ProtoMember(2)]
readonly TickFactors _high_tick;
[ProtoMember(3), DefaultValue(double.NaN)]
readonly double _low_tick_inclusive_end;
public RegionalTickFactors()
: this(new TickFactors(), new TickFactors(), double.MinValue) { }
@@ -48,6 +50,13 @@ namespace mbts.user.settings {
return hash ^ _low_tick_inclusive_end.GetHashCode();
}
public override string ToString() {
return $"{{ \"lo\": {TickFactorsToString(_low_tick)}, \"hi\": {TickFactorsToString(_high_tick)}, \"pb\": {low_tick_inclusive_end} }}";
string TickFactorsToString(TickFactors tf) =>
$"[{tf.tick_unit}, {tf.tick_base}]";
}
static bool _equals(RegionalTickFactors x_not_null, RegionalTickFactors y_not_null) =>
x_not_null._low_tick == y_not_null._low_tick &&
x_not_null._high_tick == y_not_null._high_tick &&