ui: Enable grid background setting in all windows

And remove bool props that were used to toggle this behavior
This commit is contained in:
John Colvin committed 2022-08-07 13:51:52 -04:00
1 parent 31866c76b7
commit 2b96a8a5c4
10 files changed
+58 -112

No files matched your search

@@ -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);
@@ -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) =>
@@ -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) {
@@ -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 {
@@ -31,8 +31,27 @@ namespace mbts.ui.controls {
Func<TRowVM, Brush> get_brush = null)
: base() {
_get_text = get_text;
Func<TRowVM, Brush> 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<TRowVM, Brush>(_ => {
return background_brush;
});
this.filter_model = filter;
this.filter_template = filter_template;
font_params_changed += refresh_glyph_context;
@@ -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<GridSettings, FontFamily>(gs => new FontFamily(gs.font_family));
public static IValueConverter font_weight_converter => ValueConverter.create<GridSettings, FontWeight>(gs => gs.font_weight);
public static IValueConverter font_size_converter => ValueConverter.create<GridSettings, double>(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<GridColumnSettings> columns = null,
IEnumerable<SortingCriteria> 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<GridColumnSettings>(columns.empty_if_null());
_sorting_criteria = new List<SortingCriteria>(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<GridColumnSettings> columns => _columns ?? (_columns = new List<GridColumnSettings>(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<SortingCriteria> sorting_criteria => _sorting_criteria ?? (_sorting_criteria = new List<SortingCriteria>(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));
@@ -62,7 +62,7 @@ namespace mbts.spark {
readonly Property<FontWeight> _font_weight;
readonly Property<string> _font_display_name;
readonly Property<double> _font_size;
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations, _show_background_color;
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations;
readonly OrdersModel _orders_model;
readonly IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> _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<IColumnVM>(nameof(current_column));
predicate_animations = new ObservableEditableCollection<PredicateRowAnimationVM>(() =>
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<TRowData, TPredicateData>(kv.Key, kv.Value.cell_animations, kv.Value.row_animations, kv.Value.sounds)));
//
(List<RowAnimation> row_animations, List<SoundNotification> sounds, List<CellAnimation> cell_animations) animation_tuple(IEnumerable<RowAnimation> r = null, IEnumerable<SoundNotification> s = null, IGrouping<TPredicateData, CellAnimation> 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<string, Dictionary<TPredicateData, List<CellAnimation>>>();
predicate_animations.Clear();
@@ -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
</CheckBox>
<StackPanel Grid.Row="10" Grid.Column="2" Visibility="{Binding show_background_color, Converter={StaticResource BoolToVisibility}}">
<StackPanel Grid.Row="10" Grid.Column="2">
<c:ColorPickerPopup
Grid.Row="10"
Grid.Column="2"
@@ -18,7 +18,6 @@ using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Media;
using FontFamily = System.Windows.Media.FontFamily;
@@ -41,7 +40,7 @@ namespace mbts.spark {
readonly Property<FontWeight> _font_weight;
readonly Property<string> _font_display_name;
readonly Property<double> _font_size;
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations, _show_background_color;
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations;
readonly DeferrableActionWrapper _update;
readonly IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> _column_flags;
readonly Func<GridColumnSettings, ISimpleColumnVM> _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<ISimpleColumnVM>(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));
@@ -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}" />
</Grid>
</DataTemplate>