From 2b96a8a5c4d6730baa2bd809d95d392adbb3b260 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sun, 17 Jul 2022 11:03:36 -0500 Subject: [PATCH] ui: Enable grid background setting in all windows And remove bool props that were used to toggle this behavior --- .../Market/MarketView/MarketViewSettings.cs | 21 ++++++-- .../MarketView/MarketViewWindowFactory.cs | 12 ----- .../Modules/Trading/PNL/PNLWindowFactory.cs | 12 ----- .../Trading/PNL/Settings/PNLSettings.cs | 5 +- .../Controls/DIYGrid/Columns/RenderColumn.cs | 23 ++++++++- .../Controls/DIYGrid/Settings/GridSettings.cs | 50 ++----------------- .../DIYGrid/Settings/GridSettingsVM.cs | 22 +++----- .../DIYGrid/Settings/GridSettingsView.xaml | 5 +- .../DIYGrid/Settings/SimpleGridSettingsVM.cs | 14 ++---- .../Shell/Settings/ShellSettingsDialog.xaml | 6 +-- 10 files changed, 58 insertions(+), 112 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewSettings.cs b/src/client/spark/Modules/Market/MarketView/MarketViewSettings.cs index dbceb2b8e..d9e01baaa 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewSettings.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewSettings.cs @@ -36,7 +36,7 @@ namespace bts.shell.market_view { } public static GridSettings DefaultGridSettings => - GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria, enable_background_color: true); + GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria); public static fills.FillsSettings DefaultAuxiliaryFills { get { @@ -86,7 +86,7 @@ namespace bts.shell.market_view { } } // and enable background color upgrade - return s.with(columns, enable_background_color: true); + return s.with(columns); } static class DefaultColumns { @@ -102,8 +102,21 @@ namespace bts.shell.market_view { public static GridColumnSettings bid_implied_size => _mk(Columns.BidImpliedQty, ColHeader.ImpliedQty, ColWidth.MergedQty, fg: BTSColors.MarketData.bid); public static GridColumnSettings bid_direct_size => _mk(Columns.BidDirectQty, ColHeader.DirectQty, ColWidth.MergedQty, fg: BTSColors.MarketData.bid); public static GridColumnSettings bid_merged_size => _mk(Columns.BidMergedQty, ColHeader.MergedQty, ColWidth.MergedQty, fg: BTSColors.MarketData.bid); - public static GridColumnSettings bid => _mk(Columns.Bid, ColHeader.Bid, ColWidth.MViewPrice, fg: BTSColors.header_text, bg: BTSColors.MarketData.bid); - public static GridColumnSettings ask => _mk(Columns.Ask, ColHeader.Ask, ColWidth.MViewPrice, fg: BTSColors.header_text, bg: BTSColors.MarketData.ask); + + public static GridColumnSettings bid => _mk( + Columns.Bid, + ColHeader.Bid, + ColWidth.MViewPrice, + fg: BTSColors.header_text, + bg: BTSColors.MarketData.bid); + + public static GridColumnSettings ask => _mk( + Columns.Ask, + ColHeader.Ask, + ColWidth.MViewPrice, + fg: BTSColors.header_text, + bg: BTSColors.MarketData.ask); + public static GridColumnSettings ask_merged_size => _mk(Columns.AskMergedQty, ColHeader.MergedQty, ColWidth.MergedQty, fg: BTSColors.MarketData.ask); public static GridColumnSettings ask_direct_size => _mk(Columns.AskDirectQty, ColHeader.DirectQty, ColWidth.MergedQty, fg: BTSColors.MarketData.ask); public static GridColumnSettings ask_implied_size => _mk(Columns.AskImpliedQty, ColHeader.ImpliedQty, ColWidth.MergedQty, fg: BTSColors.MarketData.ask); diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index fbd02428a..d897ab3ff 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -83,18 +83,6 @@ namespace bts.shell { } } - [Export(typeof(IMarketViewGridSettingsMigrationRule))] - class InitBackgroundOverrideMigrationRule : IMarketViewGridSettingsMigrationRule { - public bool apply(GridSettings settings, out GridSettings new_settings) { - if (!settings.enable_background_color) { - new_settings = settings.with(enable_background_color: true); - return true; - } - new_settings = default; - return false; - } - } - [Export(typeof(IMarketViewGridSettingsMigrationRule))] class EnsureSelectionHighlightTranslucency : IMarketViewGridSettingsMigrationRule { public bool apply(GridSettings settings, out GridSettings new_settings) => diff --git a/src/client/spark/Modules/Trading/PNL/PNLWindowFactory.cs b/src/client/spark/Modules/Trading/PNL/PNLWindowFactory.cs index 54a115fce..6774c55ed 100644 --- a/src/client/spark/Modules/Trading/PNL/PNLWindowFactory.cs +++ b/src/client/spark/Modules/Trading/PNL/PNLWindowFactory.cs @@ -241,18 +241,6 @@ namespace bts.shell { } } - [Export(typeof(IPNLSettingsMigrationRule))] - class EnableGridBackgroundColorMigrationRule : IPNLSettingsMigrationRule { - public bool apply(PNLSettings settings, out PNLSettings new_settings) { - if (settings != null && !settings.grid.enable_background_color) { - new_settings = settings.with(grid: settings.grid.with(enable_background_color: true)); - return true; - } - new_settings = null; - return false; - } - } - [Export(typeof(IPNLSettingsMigrationRule))] class InitializeDataFormattingMigrationRule : IPNLSettingsMigrationRule { public bool apply(PNLSettings settings, out PNLSettings new_settings) { diff --git a/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs b/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs index b7ba7f643..0f5080797 100644 --- a/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs +++ b/src/client/spark/Modules/Trading/PNL/Settings/PNLSettings.cs @@ -158,10 +158,7 @@ namespace bts.shell.pnl { }; public static GridSettings DefaultGridSettings => - GridSettings.Default.with( - DefaultColumns.all, - DefaultColumns.default_sorting_criteria, - enable_background_color: true); + GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria); public static fills.FillsSettings DefaultAuxiliaryFills { get { diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs b/src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs index 034592607..989bc8d11 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/RenderColumn.cs @@ -31,8 +31,27 @@ namespace mbts.ui.controls { Func get_brush = null) : base() { _get_text = get_text; - Func get_default_background_brush = (TRowVM _) => this.background_brush; - _get_background_brush = get_brush ?? get_default_background_brush; + if (get_brush is not null) { + var get_row_brush = get_brush; + get_brush = r => { + var row_brush = get_row_brush(r); + if (row_brush is null) { + return background_brush; + } + if (row_brush is not SolidColorBrush row_sbrush || + background_brush is not SolidColorBrush col_sbrush) { + return row_brush; + } + var row_color = row_sbrush.Color.with( + (byte)(row_sbrush.Opacity * row_sbrush.Color.A)); + var col_color = col_sbrush.Color.with( + (byte)(col_sbrush.Opacity * col_sbrush.Color.A)); + return row_color.blend(col_color).to_brush(); + }; + } + _get_background_brush = get_brush ?? new Func(_ => { + return background_brush; + }); this.filter_model = filter; this.filter_template = filter_template; font_params_changed += refresh_glyph_context; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs index 893813d8c..a2f8cf9e1 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettings.cs @@ -1,6 +1,5 @@ namespace mbts.ui.settings { using bts; - using bts.proto; using bts.utils; using mbts.ui.converters; @@ -21,14 +20,12 @@ _default_font_color = 0, _default_background = 0x00FFFFFF; const ushort _default_font_weight = 400; - const uint _default_background_color = 0x00FFFFFF; // Colors.Transparent - const bool _default_enable_background_color = false; public static GridSettings Default => new GridSettings( - selection_highlight: FallbackValues.selection_highlight.rgb_color(), - background: _default_background_color, //new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity)); - enable_background_color: _default_enable_background_color); + selection_highlight: Colors.MediumSlateBlue.with(0x63).argb_color(), + background: BTSColors.Grid.default_column_background, + font_color: BTSColors.Grid.default_column_foreground); // corrects any inappropriate values that would render the grid unusable (usually nulls) // NOTE: if you add a property to GridSettings that could have such a value, please add a conditional-correction for it below) @@ -42,15 +39,6 @@ return grid_settings; } - public static class FallbackValues { - public static FontFamily font_family => new FontFamily(_default_font_family); - public static double font_size => _default_font_size; - public static Color font_color => _default_font_color.rgb_color(); - public static FontWeight font_weight => FontWeight.FromOpenTypeWeight(_default_font_weight); - public static Color selection_highlight => Colors.MediumSlateBlue.with(0x63); - public static uint background_color => _default_background; - } - public static IValueConverter font_family_converter => ValueConverter.create(gs => new FontFamily(gs.font_family)); public static IValueConverter font_weight_converter => ValueConverter.create(gs => gs.font_weight); public static IValueConverter font_size_converter => ValueConverter.create(gs => gs.font_size); @@ -72,24 +60,7 @@ [DefaultValue(_default_font_color)] readonly uint _font_color; // selection highlight - ColorOpacityProto _obsolete_selection_highlight_backing; uint _selection_highlight_backing; - [ProtoMember(5)] - ColorOpacityProto _obsolete_selection_highlight { - get => _obsolete_selection_highlight_backing; - set { - _obsolete_selection_highlight_backing = value; - // only overwrite non-obsolete selection highlight if it is 0 (assume that means 'unassigned'). - if (_selection_highlight_backing == 0) { - var color = value.argb_color; - // ensure reasonable opacity - color.A = color.A.within_range( - GridSettingsMigrationRules.SelectionHighlightIsTranslucent.min_alpha, - GridSettingsMigrationRules.SelectionHighlightIsTranslucent.max_alpha); - _selection_highlight_backing = color.rgb_color(); - } - } - } [ProtoMember(10)] uint _selection_highlight { get => _selection_highlight_backing; @@ -105,9 +76,6 @@ [ProtoMember(8)] [DefaultValue(_default_background)] uint _background; - [ProtoMember(9)] - [DefaultValue(_default_enable_background_color)] - readonly bool _enable_background_color; public GridSettings() { _font_family = _default_font_family; @@ -115,7 +83,6 @@ _font_weight = _default_font_weight; _font_color = _default_font_color; _background = _default_background; - _enable_background_color = _default_enable_background_color; } public GridSettings( @@ -126,8 +93,7 @@ uint selection_highlight = 0, IEnumerable columns = null, IEnumerable sorting_criteria = null, - uint background = _default_background, - bool enable_background_color = _default_enable_background_color) { + uint background = _default_background) { // _font_family = font_family; _font_size = font_size; @@ -137,7 +103,6 @@ _columns = new List(columns.empty_if_null()); _sorting_criteria = new List(sorting_criteria.empty_if_null()); _background = background; - _enable_background_color = enable_background_color; } public string font_family => _font_family; @@ -147,7 +112,6 @@ public Color background => _background.argb_color(); public Color selection_highlight => _selection_highlight.argb_color(); public uint background_color => _background; - public bool enable_background_color => _enable_background_color; public IReadOnlyList columns => _columns ?? (_columns = new List(0)); [Obsolete] // TODO: remove sorting_criteria from GridSettings entirely. This should be part of IShellWindow's StartupData, since it is an instance-specific setting, and prob not part of the shared defaults public IReadOnlyList sorting_criteria => _sorting_criteria ?? (_sorting_criteria = new List(0)); @@ -158,7 +122,6 @@ string font_family = null, double font_size = double.NaN, uint? background = null, - bool? enable_background_color = null, uint? selection_highlight = null) => new GridSettings( font_family ?? _font_family, @@ -168,8 +131,7 @@ selection_highlight ?? _selection_highlight, columns ?? _columns, sorting_criteria ?? _sorting_criteria, - background ?? _background, - enable_background_color ?? _enable_background_color); + background ?? _background); public GridSettings Clone() => with(); @@ -183,7 +145,6 @@ font_color == other.font_color && selection_highlight == other.selection_highlight && _background == other._background && - _enable_background_color == other._enable_background_color && EqualityComparer.safe_sequence_equals(columns, other.columns) && #pragma warning disable CS0612 // Type or member is obsolete EqualityComparer.safe_sequence_equals(sorting_criteria, other.sorting_criteria); @@ -200,7 +161,6 @@ font_color.GetHashCode(), selection_highlight.GetHashCode(), _background.GetHashCode(), - _enable_background_color.GetHashCode(), EqualityComparer.safe_aggregate_hash(columns), #pragma warning disable CS0612 // Type or member is obsolete EqualityComparer.safe_aggregate_hash(sorting_criteria)); diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs index 0008c430b..c8490ca56 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsVM.cs @@ -62,7 +62,7 @@ namespace mbts.spark { readonly Property _font_weight; readonly Property _font_display_name; readonly Property _font_size; - readonly Property _show_predicate_animations, _show_cell_predicate_animations, _show_background_color; + readonly Property _show_predicate_animations, _show_cell_predicate_animations; readonly OrdersModel _orders_model; readonly IReadOnlyDictionary _column_flags; @@ -89,7 +89,6 @@ namespace mbts.spark { _font_display_name = backing(nameof(font_display_name), () => TextUtils.display_name(font_family, font_size), new[] { nameof(font_family), nameof(font_size) }); _show_predicate_animations = backing(nameof(show_predicate_animations), true); _show_cell_predicate_animations = backing(nameof(show_cell_predicate_animations), true); - _show_background_color = backing(nameof(show_background_color), false); _current_column = backing(nameof(current_column)); predicate_animations = new ObservableEditableCollection(() => new PredicateRowAnimationVM(_create_predicate_vm(), _predicate_data_factory), true); @@ -106,9 +105,8 @@ namespace mbts.spark { public FontFamily font_family { get => _font_family.Value; set => _font_family.set(value); } public FontWeight font_weight { get => _font_weight.Value; set => _font_weight.set(value); } public ColorPickerPopupVM font_color { get; } = new ColorPickerPopupVM(); - public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM(); - public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM(); - public bool show_background_color => _show_background_color.Value; + public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM() { bind_opacity_to_alpha = true }; + public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM() { bind_opacity_to_alpha = true }; public double font_size { get => _font_size.Value; set => _font_size.set(value); } public bool enable_sound_triggers => true; public bool show_predicate_animations { get => _show_predicate_animations.Value; set => _show_predicate_animations.set(value); } @@ -140,9 +138,8 @@ namespace mbts.spark { animation_map.AddOrUpdate(g.Key, p => animation_tuple(c: g), (p, t) => t.cell_animations.AddRange(g)); } return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.color.rgb_color(), col_settings, - background: show_background_color ? - background_color.color.with((byte)(background_color.opacity.within_range(0, 1) * 255.0)).rgb_color() : - Colors.Transparent.rgb_color()), + background: background_color.color.with( + (byte)(background_color.opacity.within_range(0, 1) * 255.0)).rgb_color()), animation_map.Select(kv => PredicateAnimations.create_data(kv.Key, kv.Value.cell_animations, kv.Value.row_animations, kv.Value.sounds))); // (List row_animations, List sounds, List cell_animations) animation_tuple(IEnumerable r = null, IEnumerable s = null, IGrouping c = null) => @@ -154,14 +151,7 @@ namespace mbts.spark { _font_weight.set(sd.general.font_weight); font_color.load_from(sd.general.font_color.rgb_solid_brush()); selection_highlight.color = sd.general.selection_highlight; - _show_background_color.set(sd.general.enable_background_color); - if (sd.general.enable_background_color) { - // note that when the OB is moved to allow background colors - // we can just background_color.color instead of load_from - // so that we get all the alpha goodness similar to SimpleGridSettingsVM - // assuming bind_opacity_to_alpha on the picker. - background_color.load_from(sd.general.background_color.argb_color().to_solid_brush()); - } + background_color.color = sd.general.background; _font_size.set(sd.general.font_size); var col_animations = new Dictionary>>(); predicate_animations.Clear(); diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml index 5b16130ff..907186e88 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml +++ b/src/client/spark/view/Controls/DIYGrid/Settings/GridSettingsView.xaml @@ -394,12 +394,11 @@ Grid.Row="10" VerticalAlignment="Center" IsEnabled="{Binding can_override_background_color}" - IsChecked="{Binding is_background_color_overridden}" - Visibility="{Binding show_background_color, Converter={StaticResource BoolToVisibility}}"> + IsChecked="{Binding is_background_color_overridden}"> Override Background Color - + _font_weight; readonly Property _font_display_name; readonly Property _font_size; - readonly Property _show_predicate_animations, _show_cell_predicate_animations, _show_background_color; + readonly Property _show_predicate_animations, _show_cell_predicate_animations; readonly DeferrableActionWrapper _update; readonly IReadOnlyDictionary _column_flags; readonly Func _column_factory; @@ -55,7 +54,6 @@ namespace mbts.spark { _font_display_name = backing(nameof(font_display_name), () => TextUtils.display_name(font_family, font_size), new[] { nameof(font_family), nameof(font_size) }); _show_predicate_animations = backing(nameof(show_predicate_animations), true); _show_cell_predicate_animations = backing(nameof(show_cell_predicate_animations), true); - _show_background_color = backing(nameof(show_background_color), false); _current_column = backing(nameof(current_column)); // update _update = new DeferrableActionWrapper(() => result_changed?.Invoke()); @@ -90,7 +88,6 @@ namespace mbts.spark { public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM() { bind_opacity_to_alpha = true }; // TODO: consolidate background/background_color into 1 property (tricky merge yielded 2 properties with the same purpose) public ColorPickerPopupVM background => background_color; - public bool show_background_color => _show_background_color.Value; public double font_size { get => _font_size.Value; set => _font_size.set(value); } public bool enable_sound_triggers => false; public bool show_predicate_animations { get => _show_predicate_animations.Value; set => _show_predicate_animations.set(value); } @@ -126,9 +123,7 @@ namespace mbts.spark { font_color.color.rgb_color(), selection_highlight.color.rgb_color(), columns.Select(c => c.create()), - enable_background_color: show_background_color, - background: (show_background_color ? - background_color.color : Colors.Transparent).argb_color()); + background: background_color.color.argb_color()); public void load_from(GridSettings value) { if (value == null) @@ -138,10 +133,7 @@ namespace mbts.spark { _font_weight.set(value.font_weight); font_color.load_from(value.font_color.rgb_solid_brush()); selection_highlight.color = value.selection_highlight; - _show_background_color.set(value.enable_background_color); - if (value.enable_background_color) { - background_color.color = value.background; - } + background_color.color = value.background; _font_size.set(value.font_size); var curr_col_id = current_column?.id; columns.SetItems(value.columns.Select(_column_factory)); diff --git a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml index 5ba3f7d1a..2295a9f32 100644 --- a/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml +++ b/src/client/spark/view/Shell/Settings/ShellSettingsDialog.xaml @@ -92,9 +92,9 @@ Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" - SelectedColor="{Binding background.color}" - SelectedOpacity="{Binding background.opacity}" - Palettes="{Binding background.palettes}" /> + SelectedColor="{Binding background_color.color}" + SelectedOpacity="{Binding background_color.opacity}" + Palettes="{Binding background_color.palettes}" />