Merge branch 'SP-175-bg_color'

This commit is contained in:
Pedro Pinto committed 2019-08-28 14:31:00 -04:00
commit 8f43c2e172
26 files changed
+404 -121

No files matched your search

@@ -1,5 +1,6 @@
using bts.api;
using bts.collections;
using bts.proto;
using bts.utils;
using mbts.persist;
using mbts.spark.filters;
@@ -46,8 +47,8 @@ namespace mbts.spark {
add_col(Columns.BidImpliedSize, implied_size_col_header, r => r.bid_implied_size.ToString(), nameof(Row.bid_implied_size), DefaultColumnWidths.ImpliedDirectMergedSize, bid_implied_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right);
add_col(Columns.BidDirectSize, direct_size_col_header, r => r.bid_direct_size.ToString(), nameof(Row.bid_direct_size), DefaultColumnWidths.ImpliedDirectMergedSize, bid_direct_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right);
add_hl_merged_size_col(Columns.BidMergedSize, merged_size_col_header, nameof(Row.bid_merged_size), nameof(Row.bid_merged_size_text), nameof(Row.bid_merged_size_click), bid_merged_size_filter, BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right);
add_hl_price_col(Columns.Bid, "Bid", nameof(Row.bid_price), nameof(Row.bid_price_click), bid_price_filter, BTSColors.header_text, BTSColors.MarketData.bid_brush, h_alignment: System.Windows.HorizontalAlignment.Right);
add_hl_price_col(Columns.Ask, "Ask", nameof(Row.ask_price), nameof(Row.ask_price_click), ask_price_filter, BTSColors.header_text, BTSColors.MarketData.ask_brush, h_alignment: System.Windows.HorizontalAlignment.Right);
add_hl_price_col(Columns.Bid, "Bid", nameof(Row.bid_price), nameof(Row.bid_price_click), bid_price_filter, BTSColors.header_text, BTSColors.MarketData.bid, h_alignment: System.Windows.HorizontalAlignment.Right);
add_hl_price_col(Columns.Ask, "Ask", nameof(Row.ask_price), nameof(Row.ask_price_click), ask_price_filter, BTSColors.header_text, BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right);
add_hl_merged_size_col(Columns.AskMergedSize, merged_size_col_header, nameof(Row.ask_merged_size), nameof(Row.ask_merged_size_text), nameof(Row.ask_merged_size_click), ask_merged_size_filter, BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right);
add_col(Columns.AskDirectSize, direct_size_col_header, r => r.ask_direct_size.ToString(), nameof(Row.ask_direct_size), DefaultColumnWidths.ImpliedDirectMergedSize, ask_direct_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right);
add_col(Columns.AskImpliedSize, implied_size_col_header, r => r.ask_implied_size.ToString(), nameof(Row.ask_implied_size), DefaultColumnWidths.ImpliedDirectMergedSize, ask_implied_size_filter, DataGridFilterKnownTemplates.UIntMinMax, font_color: BTSColors.MarketData.ask, h_alignment: System.Windows.HorizontalAlignment.Right);
@@ -77,18 +78,18 @@ namespace mbts.spark {
horizontal_alignment = h_alignment
});
void add_hl_price_col(Columns col_key, string header, string prop, string command_prop, IDataGridColumnFilter filter, Color foreground, Brush background, System.Windows.HorizontalAlignment h_alignment) =>
add_hl_col(col_key, header, price_binding(prop), prop, command_prop, filter, DataGridFilterKnownTemplates.DoubleMinMax, DefaultColumnWidths.MViewPrice, foreground, background, DefaultSelectionHighlight, h_alignment);
void add_hl_price_col(Columns col_key, string header, string prop, string command_prop, IDataGridColumnFilter filter, Color foreground, Color? background, System.Windows.HorizontalAlignment h_alignment) =>
add_hl_col(col_key, header, price_binding(prop), prop, command_prop, filter, DataGridFilterKnownTemplates.DoubleMinMax, DefaultColumnWidths.MViewPrice, foreground, background, h_alignment);
void add_hl_merged_size_col(Columns col_key, string header, string sort_prop, string text_prop, string command_prop, IDataGridColumnFilter filter, Color foreground, System.Windows.HorizontalAlignment h_alignment) =>
add_hl_col(col_key, header, new Binding(text_prop), sort_prop, command_prop, filter, DataGridFilterKnownTemplates.UIntMinMax, DefaultColumnWidths.ImpliedDirectMergedSize, foreground, null, null, h_alignment);
add_hl_col(col_key, header, new Binding(text_prop), sort_prop, command_prop, filter, DataGridFilterKnownTemplates.UIntMinMax, DefaultColumnWidths.ImpliedDirectMergedSize, foreground, null, h_alignment);
void add_hl_working_orders_col(Columns col_key, string header, string text_prop, string sort_prop, string command_prop, IDataGridColumnFilter filter, Color foreground, System.Windows.HorizontalAlignment h_alignment) =>
add_hl_col(col_key, header, new Binding(text_prop), sort_prop, command_prop, filter, DataGridFilterKnownTemplates.IntMinMax, working_orders_col_width, foreground, null, null, h_alignment);
add_hl_col(col_key, header, new Binding(text_prop), sort_prop, command_prop, filter, DataGridFilterKnownTemplates.IntMinMax, working_orders_col_width, foreground, null, h_alignment);
void add_hl_col(
Columns col_key, string header, BindingBase binding, string prop, string command_prop,
IDataGridColumnFilter filter, string filter_template, double width, Color foreground, Brush background, Brush background_overlay, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) =>
IDataGridColumnFilter filter, string filter_template, double width, Color foreground, Color? background, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) =>
columns.Add(new HyperlinkElementColumn<Row, Columns>(
col_key, binding, new Binding(command_prop), filter, filter_template) {
// it's necessary to have this id populated for grid settings
@@ -96,8 +97,7 @@ namespace mbts.spark {
Header = header,
sort_member_path = prop,
font_color_override = foreground,
background = background,
background_overlay = background_overlay,
background_color_override = background,
Width = DefaultColumnWidths.Price,
horizontal_alignment = h_alignment
});
@@ -111,14 +111,8 @@ namespace mbts.spark {
//
// make font-color immutable for Side, Size, (the font-color rule is hard-coded: MarketData.bid for Buy orders, MarketData.ask for Sells)
var col_settings_flags = new Dictionary<string, GridColumnSettingsFeatureFlags> {
{ Columns.Bid.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.Ask.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.BidImpliedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.BidDirectSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.BidMergedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.AskImpliedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.AskDirectSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.AskMergedSize.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.Bid.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor | GridColumnSettingsFeatureFlags.ImmutableBackgroundColor },
{ Columns.Ask.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor | GridColumnSettingsFeatureFlags.ImmutableBackgroundColor},
{ Columns.WorkingAsks.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
{ Columns.WorkingBids.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor }
};
@@ -153,7 +153,7 @@ namespace mbts.spark {
s => _vm.grid_settings_manager.create_vm(
// we need to get the most up to date GridSettings when launching b/c users may
// have changed some settings on the grid directly, like column widths.
s.with(_vm.columns.Select(c => c.create()))
MarketViewWindowFactory.StartupData.sanitize(s).with(_vm.columns.Select(c => c.create()))
)
);
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
@@ -1,4 +1,5 @@
using bts.api;
using bts.proto;
using mbts.persist;
using mbts.spark;
using mbts.spark.filters;
@@ -36,9 +37,9 @@ namespace bts.shell {
_bus.post(SparkTags.ShowWindow, _create(StartupData.Default(criteria)));
IShellWindow _create(StartupData state) {
var settings_manager = new WindowSettingsManager<GridSettings>(_settings_hub,
state.grid,
get: us => us.market_view_grid,
var settings_manager = new WindowSettingsManager<GridSettings>(_settings_hub,
StartupData.sanitize(state.grid),
get: us => StartupData.sanitize(us.market_view_grid),
set: (us, gs) => us.with(provided_market_view_gridsettings: gs));
return new MarketViewWindow(this, _bus, _orders_model, state, settings_manager);
}
@@ -68,7 +69,29 @@ namespace bts.shell {
_sorting_criteria = sort;
}
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion);
public static GridSettings sanitize(GridSettings s) {
if (s == null) {
return null;
}
// column upgrade
var columns = s.columns.ToList();
var bid_col_index = columns.FindIndex(x => x.id == col_id(Columns.Bid));
var ask_col_index = columns.FindIndex(x => x.id == col_id(Columns.Ask));
if (bid_col_index > -1 && ask_col_index > -1) {
if (!columns[bid_col_index].background_color_override.HasValue) {
columns[bid_col_index] = columns[bid_col_index].with(background_color_override: new NullableColorProto(BTSColors.MarketData.bid.ToUint()));
}
if (!columns[ask_col_index].background_color_override.HasValue) {
columns[ask_col_index] = columns[ask_col_index].with(background_color_override: new NullableColorProto(BTSColors.MarketData.ask.ToUint()));
}
}
// and enable background color upgrade
return s.with(columns, enable_background_color: true);
}
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion, enable_background_color: true);
public IReadOnlyList<SortingCriteria> sorting_criterion => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criterion.ToList());
@@ -86,8 +109,8 @@ namespace bts.shell {
public static GridColumnSettings bid_implied_size => new GridColumnSettings(col_id(Columns.BidImpliedSize), DefaultColumnHeaders.ImpliedSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings bid_direct_size => new GridColumnSettings(col_id(Columns.BidDirectSize), DefaultColumnHeaders.DirectSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings bid_merged_size => new GridColumnSettings(col_id(Columns.BidMergedSize), DefaultColumnHeaders.MergedSize, font_color_override: BTSColors.MarketData.bid, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings bid => new GridColumnSettings(col_id(Columns.Bid), DefaultColumnHeaders.Bid, font_color_override: BTSColors.header_text, width:DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings ask => new GridColumnSettings(col_id(Columns.Ask), DefaultColumnHeaders.Ask, font_color_override: BTSColors.header_text, width: DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings bid => new GridColumnSettings(col_id(Columns.Bid), DefaultColumnHeaders.Bid, font_color_override: BTSColors.header_text, width:DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right, background_color_override: BTSColors.MarketData.bid);
public static GridColumnSettings ask => new GridColumnSettings(col_id(Columns.Ask), DefaultColumnHeaders.Ask, font_color_override: BTSColors.header_text, width: DefaultColumnWidths.MViewPrice, horizontal_alignment: System.Windows.HorizontalAlignment.Right, background_color_override: BTSColors.MarketData.ask);
public static GridColumnSettings ask_merged_size => new GridColumnSettings(col_id(Columns.AskMergedSize), DefaultColumnHeaders.MergedSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings ask_direct_size => new GridColumnSettings(col_id(Columns.AskDirectSize), DefaultColumnHeaders.DirectSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings ask_implied_size => new GridColumnSettings(col_id(Columns.AskImpliedSize), DefaultColumnHeaders.ImpliedSize, font_color_override: BTSColors.MarketData.ask, width: DefaultColumnWidths.ImpliedDirectMergedSize, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
@@ -22,6 +22,7 @@ namespace bts.proto {
}
public Color color => _color.rgb_color();
public Color argb_color => Color.FromArgb((byte)(MathUtils.within_range(0, 1, _opacity) * 255.0), color.R, color.G, color.B);
public double opacity => _opacity;
public ColorOpacityProto with(uint? color = null, double? opacity = null) =>
@@ -16,14 +16,8 @@ namespace bts.proto {
public NullableColorProto(uint value) =>
_value = value;
public Color? value {
get {
if (_value.HasValue)
return _value.Value.rgb_color();
return null;
}
}
public Color? value => _value?.rgb_color();
public Color? argb => _value?.argb_color();
public bool Equals(NullableColorProto other) =>
EqualityComparer.nullable_equals(_value, other._value);
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using bts.utils;
using mbts.ui.extensions;
namespace mbts.ui.controls.adorners {
public class RowSelectionAdorner : Adorner, DIYGrid.ISelectionHighlightListener, IDisposable {
Brush _fill = DIYGrid.DefaultSelectionHighlight;
Pen _stroke = DIYGrid.DefaultSelectionStroke;
DIYGridRowsPresenter _diy_rp;
ScrollViewer _diy_scroll;
ScrollContentPresenter _diy_scp;
List<IDisposable> _disposables = new List<IDisposable>();
#region Fill
public static readonly DependencyProperty FillProperty =
WPFHelper.create_dp<Brush, RowSelectionAdorner>(
nameof(Fill),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._fill = v,
DIYGrid.DefaultSelectionHighlight);
public SolidColorBrush Fill {
get => GetValue(FillProperty) as SolidColorBrush;
set => SetValue(FillProperty, value);
}
#endregion
#region Stroke
public static readonly DependencyProperty StrokeProperty =
WPFHelper.create_dp<Pen, RowSelectionAdorner>(
nameof(Stroke),
FrameworkPropertyMetadataOptions.AffectsRender,
(o, v) => o._stroke = v,
DIYGrid.DefaultSelectionStroke);
public Pen Stroke {
get => GetValue(StrokeProperty) as Pen;
set => SetValue(StrokeProperty, value);
}
#endregion
internal RowSelectionAdorner(DIYGridRowsPresenter adorned_element, ScrollViewer scroll_viewer) : base(adorned_element) {
// we want our clicks to go through to the underlying grid
IsHitTestVisible = false;
_diy_rp = adorned_element;
_diy_scroll = scroll_viewer;
_diy_scp = _diy_rp.descendants_of_type<ScrollContentPresenter>().empty_if_null().FirstOrDefault();
// We actually don't need mouse up/down or key up/down when we can just respond to selection changes
_disposables.Add(((System.Windows.Controls.Primitives.Selector)_diy_rp).SubscribeSelectionChanged((s, e) => InvalidateVisual()));
// so that we update the highlight as the grid scrolls
_disposables.Add(_diy_scroll.SubscribeScrollChanged((s, e) => InvalidateVisual()));
}
protected override void OnRender(DrawingContext drawingContext) {
base.OnRender(drawingContext);
if (AdornedElement is ListBox lb && lb.SelectedItems != null && lb.SelectedItems.Count > 0) {
foreach(var lbi in lb.SelectedItems) {
if (_diy_rp.ItemContainerGenerator.ContainerFromItem(lbi) is FrameworkElement row && row.IsVisible) {
var top_left = lb.GetChildTopLeft(row);
var top_is_within_bounds = top_left.Y >= 0;
// Note that the top of the row can still technically be visible but we wont show
// the adorner rectangle b/c the bottom of the row will be obscured by the scrollbar
var bottom_is_within_bounds = lb.GetChildBounds(row).BottomRight.Y <= _diy_scroll.ActualHeight;
if (top_is_within_bounds && bottom_is_within_bounds) {
// we use the scroll content presenter in the X point calculation instead of the row
// because of the OB which has a right side panel that takes up some space over
// row width
drawingContext.DrawRectangle(_fill,
_stroke,
new Rect(top_left, new Point(top_left.X + _diy_scp.ActualWidth, top_left.Y + row.ActualHeight)));
}
}
}
}
}
public void on_selection_fill(SolidColorBrush selection_fill) {
Fill = selection_fill;
Stroke = new Pen(selection_fill.Color.to_solid_brush(), 1);
InvalidateVisual();
}
public void Dispose() {
_disposables.DisposeAll();
}
}
}
@@ -1,7 +1,9 @@
using bts.proto;
using bts.utils;
using mbts.spark;
using mbts.ui.controls.color_picker;
using mbts.ui.shell;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
@@ -38,16 +40,42 @@ namespace mbts.ui.controls {
class ColorPickerPopupVM : ViewModelBase, IValueFactory<SolidColorBrush> {
readonly Property<Color> _color;
readonly Property<double> _opacity;
ObservableCollection<ColorPaletteVM> _palettes;
bool _bind_opacity_to_alpha;
IDisposable _opacity_alpha_binding;
public ColorPickerPopupVM() {
_color = backing(nameof(color), Colors.Black);
_opacity = backing(nameof(opacity), 1.0);
palettes = new ObservableCollection<ColorPaletteVM>(ColorPalette.all_presets().Select(p => new ColorPaletteVM(p)));
}
public Color color { get => _color.Value; set => _color.set(value); }
public double opacity { get => _opacity.Value; set => _opacity.set(value); }
public ObservableCollection<ColorPaletteVM> palettes { get; }
public ObservableCollection<ColorPaletteVM> palettes => _palettes ?? (_palettes = new ObservableCollection<ColorPaletteVM>(ColorPalette.all_presets().Select(p => new ColorPaletteVM(p))));
public bool bind_opacity_to_alpha {
get => _bind_opacity_to_alpha;
set {
if (_bind_opacity_to_alpha != value) {
Disposable.dispose(ref _opacity_alpha_binding);
_bind_opacity_to_alpha = value;
if (value) {
_opacity.Changed += opacity_changed;
_color.Changed += color_changed;
color_changed(default, color);
void opacity_changed(double oldval, double newval) {
_color.Changed -= color_changed;
_color.set(color.with((byte)(MathUtils.within_range(0, 1, newval) * 255.0)));
_color.Changed += color_changed;
}
void color_changed(Color oldval, Color newval) {
_opacity.Changed -= opacity_changed;
_opacity.set(newval.A / 255.0);
_opacity.Changed += opacity_changed;
}
}
}
}
}
public SolidColorBrush create() => new SolidColorBrush(color) { Opacity = opacity }.frozen();
public void load_from(SolidColorBrush brush) {
@@ -304,11 +304,6 @@ namespace mbts.ui.controls {
}
drawingContext.Pop();
}
if (bg != null) {
var bgo = GetBackgroundOverlay(this);
if (bgo != null)
drawingContext.DrawRectangle(bgo, null, rect);
}
}
bool _point_horizontally_over_text(double x) {
@@ -1,4 +1,5 @@
using mbts.spark;
using bts.proto;
using mbts.spark;
using mbts.spark.filters;
using mbts.ui.settings;
using mbts.ui.shell;
@@ -165,7 +166,7 @@ namespace mbts.ui.controls {
}
public interface ISelectionHighlightListener {
void on_selection_fill(Brush selection_fill);
void on_selection_fill(SolidColorBrush selection_fill);
}
// To include extra data with your column type you are encouraged to derive from DIYGridColumn
@@ -173,16 +174,19 @@ namespace mbts.ui.controls {
//readonly ExternalProperty<FontWeight?> _font_weigh
FontWeight _fallback_font_weight;
Color _fallback_font_color;
Color _fallback_background_color;
double _fallback_font_size;
FontFamily _fallback_font_family;
FontWeight? _font_weight_override;
Color? _font_color_override;
Color? _background_color_override;
object _header_copy;
protected ColumnBase() {
var gs = GridSettings.Default;
_fallback_font_weight = gs.font_weight;
_fallback_font_color = gs.font_color.rgb_color();
_fallback_background_color = gs.background_color.argb_color();
_fallback_font_size = gs.font_size;
_fallback_font_family = new FontFamily(gs.font_family);
original_width = double.NaN;
@@ -215,6 +219,9 @@ namespace mbts.ui.controls {
public FontWeight font_weight => font_weight_override ?? _fallback_font_weight;
public Color font_color => font_color_override ?? _fallback_font_color;
public Brush font_brush => new SolidColorBrush(font_color);
public Color? background_color_override { get => _background_color_override; set => _set_font_param(ref _background_color_override, value); }
public Color? background_color => background_color_override ?? _fallback_background_color;
public Brush background_brush => background_color?.to_brush();
// TODO: find a better way to store the header-property in a thread-safe manner - a value for GridSettings.display_name, more specifically.
// Since save_state is called from a different thread in IShared/SlowWindows, it is not safe to access the DependencyProperty store from that method.
// By updating a local _header_copy field in the Header setter, the DependencyProperty lookup may be bypassed when appropriate (see create method below).
@@ -224,7 +231,7 @@ namespace mbts.ui.controls {
}
public GridColumnSettings create() =>
new GridColumnSettings(id, _header_copy?.ToString(), is_visible, is_collapsed, font_weight_override, font_color_override, ActualWidth, horizontal_alignment, horizontal_offset);
new GridColumnSettings(id, _header_copy?.ToString(), is_visible, is_collapsed, font_weight_override, font_color_override, ActualWidth, horizontal_alignment, horizontal_offset, background_color_override);
void _set_font_param<T>(ref T field, T value) {
field = value;
@@ -235,7 +242,7 @@ namespace mbts.ui.controls {
if (settings == null)
return;
using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(is_visible), nameof(is_collapsed), nameof(font_weight_override), nameof(font_weight),
nameof(font_color_override), nameof(font_color), nameof(font_brush), nameof(font_family), nameof(font_size), nameof(horizontal_alignment), nameof(horizontal_offset))) {
nameof(font_color_override), nameof(font_color), nameof(font_brush), nameof(font_family), nameof(font_size), nameof(horizontal_alignment), nameof(horizontal_offset), nameof(background_color_override), nameof(background_color), nameof(background_brush))) {
//
id = settings.id;
if (!string.IsNullOrEmpty(settings.display_name))
@@ -246,6 +253,7 @@ namespace mbts.ui.controls {
font_color_override = settings.font_color_override;
horizontal_alignment = settings.horizontal_alignment;
horizontal_offset = settings.horizontal_offset;
background_color_override = settings.background_color_override;
}
if (original_width != settings.width) {
original_width = settings.width;
@@ -255,11 +263,12 @@ namespace mbts.ui.controls {
}
// 'fallback' font-params (aka 'grid-level' font-params)
public void set_fallback_font_params(FontFamily font_family, double font_size, Color font_color, FontWeight font_weight) {
using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(font_family), nameof(font_size), nameof(font_color), nameof(font_weight))) {
public void set_fallback_font_params(FontFamily font_family, double font_size, Color font_color, FontWeight font_weight, Color background_color) {
using (ReflectionHelper.detect_property_changes(this, _raise_prop_changed, nameof(font_family), nameof(font_size), nameof(font_color), nameof(font_weight), nameof(background_color), nameof(background_brush))) {
_fallback_font_family = font_family;
_fallback_font_size = font_size;
_fallback_font_color = font_color;
_fallback_background_color = background_color;
_fallback_font_weight = font_weight;
}
font_params_changed?.Invoke();
@@ -7,7 +7,7 @@ using System.Windows.Media;
namespace mbts.ui.controls {
partial class DIYGrid {
internal class HyperlinkElementColumn<TRowVM, TKey> : FrameworkElementColumnBase<TKey>, IFrameworkElementColumn, IFilterableColumn, IKeyedColumn<TKey>, ISelectionHighlightListener {
internal class HyperlinkElementColumn<TRowVM, TKey> : FrameworkElementColumnBase<TKey>, IFrameworkElementColumn, IFilterableColumn, IKeyedColumn<TKey> {
static readonly Thickness _default_padding = new Thickness(6, 0, 6, 0);
readonly BindingBase _binding, _command_binding;
@@ -22,27 +22,17 @@ namespace mbts.ui.controls {
public IDataGridColumnFilter filter { get; }
public string filter_template { get; }
public Thickness padding { get; set; } = _default_padding;
public Brush background { get; set; }
public Brush background_overlay { get; set; } = DefaultSelectionHighlight;
public void on_selection_fill(Brush selection_fill) =>
background_overlay = selection_fill;
public override FrameworkElement view_factory() {
var hl = new HyperlinkCell { Foreground = font_brush, Background = background, Padding = padding };
var hl = new HyperlinkCell { Padding = padding };
hl.SetBinding(HyperlinkCell.ForegroundProperty, new Binding(nameof(font_brush)) { Source = this });
hl.SetBinding(HyperlinkCell.TextProperty, _binding);
hl.SetBinding(HyperlinkCell.FontFamilyProperty, new Binding(nameof(font_family)) { Source = this });
hl.SetBinding(HyperlinkCell.FontSizeProperty, new Binding(nameof(font_size)) { Source = this });
hl.SetBinding(HyperlinkCell.HorizontalAlignmentProperty, new Binding(nameof(horizontal_alignment)) { Source = this });
hl.SetBinding(HyperlinkCell.CommandProperty, _command_binding);
hl.SetBinding(HyperlinkCell.WidthProperty, new Binding(nameof(ActualWidth)) { Source = this });
if (background_overlay != null) {
hl.SetBinding(BackgroundOverlayProperty, new Binding(nameof(ListBoxItem.IsSelected)) {
Converter = new AnonymousValueConverter<bool, Brush>(val => val ? background_overlay : null),
Mode = BindingMode.OneWay,
RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ListBoxItem), 1)
});
}
hl.SetBinding(HyperlinkCell.BackgroundProperty, new Binding(nameof(background_brush)) { Source = this });
return hl;
}
}
@@ -30,7 +30,7 @@ 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;
Func<TRowVM, Brush> get_default_background_brush = (TRowVM _) => this.background_brush;
_get_background_brush = get_brush ?? get_default_background_brush;
this.filter = filter;
this.filter_template = filter_template;
@@ -42,7 +42,6 @@ namespace mbts.ui.controls {
public IDataGridColumnFilter filter { get; }
public string filter_template { get; }
public Brush background { get; set; }
public VerticalAlignment vertical_alignment { get; set; } = VerticalAlignment.Center;
public Thickness padding { get; set; } = DefaultCellPadding;
public GlyphContext glyph_context { get; private set; }
@@ -126,6 +126,7 @@ namespace mbts.ui.controls {
double _row_height = DIYGrid.DefaultRowHeight;
DIYGrid _grid;
DragRectAdorner _drag_rect_adorner;
RowSelectionAdorner _rsa;
ScrollViewer _scroll_viewer;
Point? _drag_start;
double _drag_start_vertical_drift;
@@ -148,12 +149,18 @@ namespace mbts.ui.controls {
_drag_rect_adorner.SetResourceReference(DragRectAdorner.StrokeProperty, DIYGrid.SelectionStrokeKey);
_drag_rect_adorner.attach();
}
_rsa = new RowSelectionAdorner(this, _scroll_viewer);
_rsa.attach();
};
Unloaded += (s, e) => {
if (_drag_rect_adorner != null) {
_drag_rect_adorner.detach();
Disposable.dispose(ref _drag_rect_adorner);
}
if (_rsa != null) {
_rsa.detach();
Disposable.dispose(ref _rsa);
}
};
void on_row_height_changed(double v) => _row_height = v;
}
@@ -261,6 +268,12 @@ namespace mbts.ui.controls {
o.Resources[SelectionStrokeKey] = new Pen(o.SelectionHighlight.Color.to_solid_brush().frozen(), 1).frozen();
foreach (var col in o.Columns.empty_if_null().OfType<ISelectionHighlightListener>())
col.on_selection_fill(v);
var ad_layer = System.Windows.Documents.AdornerLayer.GetAdornerLayer(o);
if (ad_layer != null) {
foreach (var ad in ad_layer.descendants_of_type<ISelectionHighlightListener>()) {
ad.on_selection_fill(v);
}
}
}, (o, v) => v as SolidColorBrush ?? DefaultSelectionHighlight,
DefaultSelectionHighlight);
@@ -594,18 +607,6 @@ namespace mbts.ui.controls {
// Public Properties
#region Public Properties
public static readonly DependencyProperty BackgroundOverlayProperty =
DependencyProperty.RegisterAttached(
"BackgroundOverlay",
typeof(Brush),
typeof(DIYGrid),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsRender));
public static Brush GetBackgroundOverlay(DependencyObject d) => d.GetValue(BackgroundOverlayProperty) as Brush;
public static void SetBackgroundOverlay(DependencyObject d, Brush value) => d.SetValue(BackgroundOverlayProperty, value);
#region RowStyle
public static readonly DependencyProperty RowStyleProperty =
WPFHelper.create_dp<Style, DIYGrid>(
@@ -29,22 +29,6 @@
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
/>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="False"/>
<Condition Property="IsSelected" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static bts:DIYGrid.InactiveSelectionHighlightKey}}"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="True"/>
<Condition Property="IsSelected" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{Binding SelectionHighlight, RelativeSource={RelativeSource AncestorType=bts:DIYGrid}}"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
@@ -60,6 +60,9 @@ namespace mbts.ui.settings {
[DefaultValue(_default_horizontal_offset)]
readonly double _horizontal_offset;
[ProtoMember(10)]
readonly NullableColorProto _background_color_override;
public GridColumnSettings() {
_is_visible = _default_is_visible;
_is_collapsed = _default_is_collapsed;
@@ -69,7 +72,7 @@ namespace mbts.ui.settings {
}
public GridColumnSettings(string id, string display_name = null, bool is_visible = _default_is_visible, bool is_collapsed = _default_is_collapsed, FontWeight? font_weight_override = null, Color? font_color_override = null,
double width = _default_width, HorizontalAlignment horizontal_alignment = _default_horizontal_alignment, double horizontal_offset = _default_horizontal_offset) {
double width = _default_width, HorizontalAlignment horizontal_alignment = _default_horizontal_alignment, double horizontal_offset = _default_horizontal_offset, Color? background_color_override = null) {
_id = id;
_display_name = display_name;
_is_visible = is_visible;
@@ -79,6 +82,7 @@ namespace mbts.ui.settings {
_width = width;
_horizontal_alignment = horizontal_alignment;
_horizontal_offset = horizontal_offset;
_background_color_override = new NullableColorProto(background_color_override);
}
public string id => _id;
@@ -90,10 +94,11 @@ namespace mbts.ui.settings {
public HorizontalAlignment horizontal_alignment => _horizontal_alignment;
public double horizontal_offset => _horizontal_offset;
public string display_name => _display_name;
public Color? background_color_override => _background_color_override.argb;
public GridColumnSettings with(
string display_name = null, bool? is_visible = null, bool? is_collapsed = null, NullableFontWeightProto? font_weight_override = null, NullableColorProto? font_color_override = null,
double? width = null, HorizontalAlignment? horizontal_alignment = null, double? horizontal_offset = null) =>
double? width = null, HorizontalAlignment? horizontal_alignment = null, double? horizontal_offset = null, NullableColorProto? background_color_override = null) =>
//
new GridColumnSettings(_id,
display_name ?? this.display_name,
@@ -103,7 +108,8 @@ namespace mbts.ui.settings {
(font_color_override ?? _font_color_override).value,
width ?? this.width,
horizontal_alignment ?? this.horizontal_alignment,
horizontal_offset ?? this.horizontal_offset);
horizontal_offset ?? this.horizontal_offset,
(background_color_override ?? _background_color_override).argb);
public bool Equals(GridColumnSettings other) =>
other != null &&
@@ -116,7 +122,8 @@ namespace mbts.ui.settings {
width == other.width &&
horizontal_alignment == other.horizontal_alignment &&
horizontal_offset == other.horizontal_offset &&
display_name == other.display_name;
display_name == other.display_name &&
background_color_override.Equals(other.background_color_override);
public override bool Equals(object obj) =>
Equals(obj as GridColumnSettings);
@@ -132,7 +139,8 @@ namespace mbts.ui.settings {
width.GetHashCode(),
horizontal_alignment.GetHashCode(),
horizontal_offset.GetHashCode(),
display_name.GetHashCode()
display_name.GetHashCode(),
background_color_override.GetHashCode()
);
public override string ToString() {
@@ -22,11 +22,13 @@ namespace mbts.spark {
/// </para>
/// For flag behavior implementation, see <see cref="GridSettingsVM{TRowData, TPredicateBuilder}.ColumnVM.apply_flags(GridColumnSettingsFeatureFlags)"/>
/// </summary>
[Flags]
enum GridColumnSettingsFeatureFlags {
None = 0,
ImmutableFontColor = 1,
ImmutableFontWeight = 1 << 1,
ImmutableHeader = 1 << 2
ImmutableHeader = 1 << 2,
ImmutableBackgroundColor = 1 << 3
}
partial class GridSettingsVM<TRowData, TPredicateData, TSettingsData> {
@@ -50,7 +52,9 @@ namespace mbts.spark {
_can_override_font_color = true,
_is_font_color_overridden,
_can_override_font_weight = true,
_is_font_weight_overridden;
_is_font_weight_overridden,
_can_override_background_color = true,
_is_background_color_overridden;
FontWeight _font_weight_override;
GridColumnSettings _settings;
@@ -78,6 +82,10 @@ namespace mbts.spark {
public bool can_override_font_weight { get => _can_override_font_weight; private set => Set(ref _can_override_font_weight, value); }
public bool is_font_weight_overridden { get => _is_font_weight_overridden; set => Set(ref _is_font_weight_overridden, value); }
public FontWeight font_weight_override { get => _font_weight_override; set => Set(ref _font_weight_override, value); }
// background color override
public bool can_override_background_color { get => _can_override_background_color; private set => Set(ref _can_override_background_color, value); }
public bool is_background_color_overridden { get => _is_background_color_overridden; set => Set(ref _is_background_color_overridden, value); }
public ColorPickerPopupVM background_color_override { get; } = new ColorPickerPopupVM() { bind_opacity_to_alpha = true };
// animations
public ObservableEditableCollection<PredicateCellAnimationVM> predicate_animations { get; }
@@ -89,7 +97,9 @@ namespace mbts.spark {
is_font_weight_overridden ? new NullableFontWeightProto(font_weight_override) : default,
is_font_color_overridden ? new NullableColorProto(font_color_override.color) : default,
width,
horizontal_alignment);
horizontal_alignment,
background_color_override: is_background_color_overridden ?
new NullableColorProto(background_color_override.color) : default);
var animations_lookup = predicate_animations.ToFlatLookup(pa => pa.predicate.create_assigned(owner._predicate_data_factory), pa => pa.animations.Select(a => a.create()));
return (settings, animations_lookup);
}
@@ -111,6 +121,11 @@ namespace mbts.spark {
if (is_font_weight_overridden) {
_font_weight_override = _settings.font_weight_override.Value;
}
// background color
is_background_color_overridden = _settings.background_color_override.HasValue;
if (is_background_color_overridden) {
background_color_override.color = _settings.background_color_override.Value;
}
predicate_animations.SetItems(value.animations.empty_if_null().Select(g => {
var vm = new PredicateCellAnimationVM(id, owner._create_column_predicate_vm(id), owner._predicate_data_factory);
vm.load_from((g.Key, g));
@@ -129,6 +144,9 @@ namespace mbts.spark {
// font weight
can_override_font_weight = (flags & GridColumnSettingsFeatureFlags.ImmutableFontWeight) == 0;
is_font_weight_overridden &= can_override_font_weight;
// background color
can_override_background_color = (flags & GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) == 0;
is_background_color_overridden &= can_override_background_color;
}
public override string ToString() => $"{display_name} ({id})";
@@ -17,9 +17,14 @@ namespace mbts.ui.settings {
const double _default_font_size = 11;
const uint _default_font_color = 0;
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: new ColorOpacityProto(FallbackValues.selection_highlight.Color, FallbackValues.selection_highlight.Opacity));
new GridSettings(
selection_highlight: new ColorOpacityProto(FallbackValues.selection_highlight.Color, FallbackValues.selection_highlight.Opacity),
background_color: _default_background_color, //new ColorOpacityProto(FallbackValues.background_color.Color, FallbackValues.background_color.Opacity));
enable_background_color: _default_enable_background_color);
// 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)
@@ -39,6 +44,7 @@ namespace mbts.ui.settings {
public static Color font_color => _default_font_color.rgb_color();
public static FontWeight font_weight => FontWeight.FromOpenTypeWeight(_default_font_weight);
public static SolidColorBrush selection_highlight => DIYGrid.DefaultSelectionHighlight;
public static uint background_color => _default_background_color;
}
public static IValueConverter selection_highlight_converter => ValueConverter.create<GridSettings, SolidColorBrush>(gs => gs.selection_highlight.to_brush().frozen());
@@ -65,17 +71,26 @@ namespace mbts.ui.settings {
List<GridColumnSettings> _columns;
[ProtoMember(7)]
List<SortingCriteria> _sorting_criterion;
[ProtoMember(8)]
readonly uint _background_color;
[ProtoMember(9)]
[DefaultValue(false)]
readonly bool _enable_background_color;
public GridSettings() {
_font_family = _default_font_family;
_font_size = _default_font_size;
_font_weight = _default_font_weight;
_font_color = _default_font_color;
// new setting in proto defaulted here
_background_color = _default_background_color;
_enable_background_color = _default_enable_background_color;
}
public GridSettings(
string font_family = _default_font_family, double font_size = _default_font_size, FontWeight font_weight = default, uint font_color = _default_font_color,
ColorOpacityProto? selection_highlight = null, IEnumerable<GridColumnSettings> columns = null, IEnumerable<SortingCriteria> sorting_criterion = null) {
ColorOpacityProto? selection_highlight = null, IEnumerable<GridColumnSettings> columns = null, IEnumerable<SortingCriteria> sorting_criterion = null, uint background_color = _default_background_color, bool enable_background_color = _default_enable_background_color) {
//
_font_family = font_family;
_font_size = font_size;
@@ -84,6 +99,8 @@ namespace mbts.ui.settings {
_selection_highlight = selection_highlight ?? new ColorOpacityProto(0, 1);
_columns = new List<GridColumnSettings>(columns.empty_if_null());
_sorting_criterion = new List<SortingCriteria>(sorting_criterion.empty_if_null());
_background_color = background_color;
_enable_background_color = enable_background_color;
}
public string font_family => _font_family;
@@ -91,14 +108,17 @@ namespace mbts.ui.settings {
public uint font_color => _font_color;
public FontWeight font_weight => FontWeight.FromOpenTypeWeight(_font_weight);
public ColorOpacityProto selection_highlight => _selection_highlight;
public uint background_color => _background_color;
public bool enable_background_color => _enable_background_color;
public IReadOnlyList<GridColumnSettings> columns => _columns ?? (_columns = new List<GridColumnSettings>(0));
[Obsolete] // TODO: remove sorting_criterion 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_criterion => _sorting_criterion ?? (_sorting_criterion = new List<SortingCriteria>(0));
public static GridSettings get_default() =>
new GridSettings(_default_font_family, _default_font_size, FontWeights.Normal, _default_font_color, new ColorOpacityProto(Colors.MediumSlateBlue, 0.4));
new GridSettings(_default_font_family, _default_font_size, FontWeights.Normal, _default_font_color, new ColorOpacityProto(DIYGrid.DefaultSelectionHighlight.Color, DIYGrid.DefaultSelectionHighlight.Opacity),
background_color: _default_background_color);
public GridSettings with(IEnumerable<GridColumnSettings> columns = null, IEnumerable<SortingCriteria> sorting_criterion = null, string font_family = null, double font_size = double.NaN) =>
public GridSettings with(IEnumerable<GridColumnSettings> columns = null, IEnumerable<SortingCriteria> sorting_criterion = null, string font_family = null, double font_size = double.NaN, bool? enable_background_color = null) =>
new GridSettings(
font_family ?? _font_family,
DoubleHelper.IsNaNOrInfinityOr(font_size, 0) ? _font_size : font_size,
@@ -106,7 +126,9 @@ namespace mbts.ui.settings {
_font_color,
_selection_highlight,
columns ?? _columns,
sorting_criterion ?? _sorting_criterion);
sorting_criterion ?? _sorting_criterion,
_background_color,
enable_background_color ?? _enable_background_color);
public GridSettings clone() => with();
@@ -119,8 +141,10 @@ namespace mbts.ui.settings {
selection_highlight == other.selection_highlight &&
EqualityComparer.safe_sequence_equals(columns, other.columns) &&
#pragma warning disable CS0612 // Type or member is obsolete
EqualityComparer.safe_sequence_equals(sorting_criterion, other.sorting_criterion);
EqualityComparer.safe_sequence_equals(sorting_criterion, other.sorting_criterion) &&
#pragma warning restore CS0612 // Type or member is obsolete
background_color == other.background_color &&
enable_background_color == other.enable_background_color;
public override bool Equals(object obj) =>
Equals(obj as GridSettings);
@@ -134,7 +158,9 @@ namespace mbts.ui.settings {
selection_highlight.GetHashCode(),
EqualityComparer.safe_aggregate_hash(columns),
#pragma warning disable CS0612 // Type or member is obsolete
EqualityComparer.safe_aggregate_hash(sorting_criterion));
EqualityComparer.safe_aggregate_hash(sorting_criterion),
#pragma warning restore CS0612 // Type or member is obsolete
background_color.GetHashCode(),
enable_background_color.GetHashCode());
}
}
@@ -30,7 +30,7 @@ namespace mbts.ui {
readonly DelegateProperty<FontFamily> _font_family;
readonly DelegateProperty<FontWeight> _font_weight;
readonly DelegateProperty<double> _font_size;
readonly DelegateProperty<SolidColorBrush> _font_color, _selection_highlight;
readonly DelegateProperty<SolidColorBrush> _font_color, _selection_highlight, _background_color;
readonly SetMap<IPredicate<TRowData>, AnimationDefinitionWrapper<TRow>> _animation_defs = new SetMap<IPredicate<TRowData>, AnimationDefinitionWrapper<TRow>>();
readonly Func<TPredicateData> _predicate_data_factory;
readonly Func<TPredicateData, IPredicate<TRowData>> _predicate_factory;
@@ -77,6 +77,7 @@ namespace mbts.ui {
_font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size));
_font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings));
_selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings));
_background_color = backing(nameof(background_color), () => grid_settings.background_color.argb_color().to_solid_brush().frozen(), nameof(grid_settings));
}
public void Dispose() =>
@@ -88,6 +89,7 @@ namespace mbts.ui {
public double font_size => _font_size.Value;
public SolidColorBrush font_color => _font_color.Value;
public SolidColorBrush selection_highlight => _selection_highlight.Value;
public SolidColorBrush background_color => _background_color.Value;
public GridSettingsVM<TRowData, TPredicateData, TSettingsData> create_vm(GridSettings settings) {
var vm = new GridSettingsVM<TRowData, TPredicateData, TSettingsData>(_bus, _orders_model, _predicate_data_factory, _notification_predicate_factory, _create_predicate_vm, _create_column_predicate_vm, _create_settings_obj, _column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags));
@@ -112,7 +114,7 @@ namespace mbts.ui {
var grid = value.general ?? GridSettings.Default;
_grid_settings.set(grid);
foreach (ColumnBase col in _columns)
col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight);
col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb_color());
_predicate_animations_data = value.predicate_animations;
_animation_defs.clear();
foreach (var pa in _predicate_animations_data) {
@@ -1,5 +1,6 @@
using bts.api;
using bts.collections;
using bts.proto;
using bts.shell;
using bts.utils;
using mbts.collections;
@@ -56,7 +57,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;
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations, _show_background_color;
readonly OrdersModel _orders_model;
readonly IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> _column_flags;
@@ -83,6 +84,7 @@ 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);
@@ -100,6 +102,8 @@ namespace mbts.spark {
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 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); }
@@ -130,7 +134,8 @@ namespace mbts.spark {
foreach (IGrouping<TPredicateData, CellAnimation> g in animations)
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.to_proto(), col_settings),
return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings,
background_color: background_color.color.with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 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) =>
@@ -142,6 +147,14 @@ namespace mbts.spark {
_font_weight.set(sd.general.font_weight);
font_color.load_from(sd.general.font_color.rgb_solid_brush());
selection_highlight.load_from(sd.general.selection_highlight.to_brush());
_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());
}
_font_size.set(sd.general.font_size);
var col_animations = new Dictionary<string, Dictionary<TPredicateData, List<CellAnimation>>>();
predicate_animations.Clear();
@@ -642,6 +642,8 @@
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
@@ -672,6 +674,16 @@
Visibility="{Binding DataContext.current_column.is_font_color_overridden, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}"
/>
<ComboBox Grid.Row="8" Grid.Column="2" Style="{StaticResource DisabledPlaceholderComboBox}" Visibility="{Binding current_column.is_font_color_overridden, Converter={StaticResource FalseVisibilityConverter}}"/>
<CheckBox Grid.Row="10" VerticalAlignment="Center" IsEnabled="{Binding current_column.can_override_background_color}" IsChecked="{Binding current_column.is_background_color_overridden}" Visibility="{Binding show_background_color, Converter={StaticResource BoolToVisibility}}">Override Background Color</CheckBox>
<StackPanel Grid.Row="10" Grid.Column="2" Visibility="{Binding show_background_color, Converter={StaticResource BoolToVisibility}}">
<c:ColorPickerPopup
Grid.Row="10"
Grid.Column="2"
DataContext="{Binding current_column.background_color_override}"
Visibility="{Binding DataContext.current_column.is_background_color_overridden, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}"
/>
<ComboBox Grid.Row="10" Grid.Column="2" Style="{StaticResource DisabledPlaceholderComboBox}" Visibility="{Binding current_column.is_background_color_overridden, Converter={StaticResource FalseVisibilityConverter}}"/>
</StackPanel>
</Grid>
</GroupBox>
<!--TODO: Make this visible when cell animations are ready-->
@@ -21,6 +21,9 @@ namespace mbts.ui {
if ((flags & GridColumnSettingsFeatureFlags.ImmutableFontWeight) != 0) {
stores_per_flag.Add(new ImmutableFontWeightOverrideStore());
}
if ((flags & GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) != 0) {
stores_per_flag.Add(new ImmutableBackgroundColorOverrideStore());
}
return new CompositeImmutableSettingsStore(stores_per_flag, flags);
}
@@ -66,6 +69,19 @@ namespace mbts.ui {
_value = new NullableFontWeightProto(settings.font_weight_override);
}
class ImmutableBackgroundColorOverrideStore : ImmutableColumnSettingStore {
NullableColorProto _value;
public ImmutableBackgroundColorOverrideStore()
: base(GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) { }
public override GridColumnSettings apply(GridColumnSettings settings) =>
settings.with(background_color_override: _value);
public override void store(GridColumnSettings settings) =>
_value = new NullableColorProto(settings.background_color_override);
}
class CompositeImmutableSettingsStore : ImmutableColumnSettingStore {
readonly IReadOnlyList<ImmutableColumnSettingStore> _stores;
public CompositeImmutableSettingsStore(IReadOnlyList<ImmutableColumnSettingStore> stores, GridColumnSettingsFeatureFlags flags)
@@ -21,7 +21,9 @@ namespace mbts.spark {
_can_override_font_color = true,
_is_font_color_overridden,
_can_override_font_weight = true,
_is_font_weight_overridden;
_is_font_weight_overridden,
_can_override_background_color = true,
_is_background_color_overridden;
FontWeight _font_weight_override;
GridColumnSettings _settings;
@@ -43,16 +45,23 @@ namespace mbts.spark {
public bool can_override_font_weight { get => _can_override_font_weight; private set => Set(ref _can_override_font_weight, value); }
public bool is_font_weight_overridden { get => _is_font_weight_overridden; set => Set(ref _is_font_weight_overridden, value); }
public FontWeight font_weight_override { get => _font_weight_override; set => Set(ref _font_weight_override, value); }
// background color override
public bool can_override_background_color { get => _can_override_background_color; private set => Set(ref _can_override_background_color, value); }
public bool is_background_color_overridden { get => _is_background_color_overridden; set => Set(ref _is_background_color_overridden, value); }
public ColorPickerPopupVM background_color_override { get; } = new ColorPickerPopupVM();
public GridColumnSettings create() =>
_settings.with(
can_override_display_name ? display_name : null,
is_visible,
null,
is_font_weight_overridden ? new NullableFontWeightProto(font_weight_override) : (NullableFontWeightProto?)null,
is_font_color_overridden ? new NullableColorProto(font_color_override.color) : (NullableColorProto?)null,
can_override_font_weight ? (is_font_weight_overridden ? new NullableFontWeightProto(font_weight_override) : new NullableFontWeightProto()) : (NullableFontWeightProto?)null,
can_override_font_color ? (is_font_color_overridden ? new NullableColorProto(font_color_override.color) : new NullableColorProto()) : (NullableColorProto?)null,
width,
horizontal_alignment);
horizontal_alignment,
background_color_override:
can_override_background_color ? (is_background_color_overridden ? new NullableColorProto(background_color_override.color) : new NullableColorProto()) : (NullableColorProto ?)null
);
public void load_from(GridColumnSettings value) {
_settings = value;
@@ -71,6 +80,14 @@ namespace mbts.spark {
if (is_font_weight_overridden) {
_font_weight_override = _settings.font_weight_override.Value;
}
// background color
is_background_color_overridden = _settings.background_color_override.HasValue;
if (is_background_color_overridden) {
background_color_override.load_from(
new SolidColorBrush(_settings.background_color_override.Value) {
//Opacity = _settings.background_color_override.Value.opacity
});
}
}
public void apply_flags(GridColumnSettingsFeatureFlags flags) {
@@ -84,6 +101,9 @@ namespace mbts.spark {
// font weight
can_override_font_weight = (flags & GridColumnSettingsFeatureFlags.ImmutableFontWeight) == 0;
is_font_weight_overridden &= can_override_font_weight;
// background color
can_override_background_color = (flags & GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) == 0;
is_background_color_overridden &= can_override_background_color;
}
public override string ToString() => $"{display_name} ({id})";
@@ -20,7 +20,7 @@ namespace mbts.ui {
readonly DelegateProperty<FontFamily> _font_family;
readonly DelegateProperty<FontWeight> _font_weight;
readonly DelegateProperty<double> _font_size;
readonly DelegateProperty<SolidColorBrush> _font_color, _selection_highlight;
readonly DelegateProperty<SolidColorBrush> _font_color, _selection_highlight, _background_color;
readonly IReadOnlyDictionary<string, ImmutableColumnSettingStore> _column_flags;
public SimpleGridSettingsManager(ObservableCollection<ColumnBase> columns)
@@ -35,6 +35,7 @@ namespace mbts.ui {
_font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size));
_font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings));
_selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings));
_background_color = backing(nameof(background_color), () => grid_settings.background_color.argb_color().to_solid_brush().frozen(), nameof(grid_settings));
_row_vms = row_vms;
}
@@ -44,6 +45,7 @@ namespace mbts.ui {
public double font_size => _font_size.Value;
public SolidColorBrush font_color => _font_color.Value;
public SolidColorBrush selection_highlight => _selection_highlight.Value;
public SolidColorBrush background_color => _background_color.Value;
public SimpleGridSettingsVM create_vm(GridSettings settings) {
var vm = new SimpleGridSettingsVM(_column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags));
@@ -86,7 +88,7 @@ namespace mbts.ui {
grid = grid ?? GridSettings.Default;
_grid_settings.set(grid);
foreach (ColumnBase col in _columns)
col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight);
col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb_color());
// ** in the unfortunate event that we botch backwards compatability, and the columns don't bear a 1:1 relationship with the column-settings
// don't add insult to injury by crashing **
if (grid_settings.columns != null) {
@@ -1,4 +1,5 @@
using bts.collections;
using bts.proto;
using bts.utils;
using mbts.ui;
using mbts.ui.controls;
@@ -36,7 +37,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;
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations, _show_background_color;
readonly DeferrableActionWrapper _update;
readonly IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> _column_flags;
@@ -48,6 +49,7 @@ 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());
@@ -78,7 +80,9 @@ 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 selection_highlight { get; } = new ColorPickerPopupVM(){ bind_opacity_to_alpha = true };
public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM() { bind_opacity_to_alpha = true };
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); }
@@ -98,12 +102,20 @@ namespace mbts.spark {
get {
yield return font_color;
yield return selection_highlight;
yield return background_color;
yield return this;
}
}
// Note that one of the responsibilites of create() is via instance_vm.get_result() in the ShellSettingsDialogVM.export_to_custom_cmd,
// which is what handles saving .grid files. This means if you have introduced any optional args, say for example enable_background_color
// that is not yet a feature of all windows at this point in time, 8/28/2019, you need to be sure it's explicity set if the proto
// constructor parameter default has been initialized to different default value.
public GridSettings create() =>
new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), columns.Select(c => c.create()));
new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(),
columns.Select(c => c.create()),
background_color: show_background_color ? background_color.color.rgb_color() : GridSettings.FallbackValues.background_color,
enable_background_color: show_background_color);
public void load_from(GridSettings value) {
if (value == null)
@@ -112,7 +124,11 @@ namespace mbts.spark {
_font_family.set(new FontFamily(value.font_family));
_font_weight.set(value.font_weight);
font_color.load_from(value.font_color.rgb_solid_brush());
selection_highlight.load_from(value.selection_highlight.to_brush());
selection_highlight.color = value.selection_highlight.argb_color;
_show_background_color.set(value.enable_background_color);
if (value.enable_background_color) {
background_color.color = value.background_color.argb_color();
}
_font_size.set(value.font_size);
var curr_col_id = current_column?.id;
columns.SetItems(value.columns.Select(col => {
@@ -156,6 +156,19 @@ namespace mbts.ui.extensions {
}
}
public static IDisposable SubscribePreviewKeyUp(this UIElement target, KeyEventHandler callback) {
target.PreviewKeyUp += callback;
return Disposable.Create(() => target.PreviewKeyUp -= callback);
}
public static IDisposable SubscribePreviewKeyUp(this UIElement target, Key key, Action callback) {
return SubscribePreviewKeyUp(target, on_preview_key_up);
void on_preview_key_up(object sender, KeyEventArgs e) {
if (e.Key == key)
callback();
}
}
public static IObservable<KeyEventArgs> SubscribePreviewKeyDown(this UIElement target) =>
Observable.Create<KeyEventArgs>(o => {
target.PreviewKeyDown += on_preview_key_down;
@@ -197,6 +210,13 @@ namespace mbts.ui.extensions {
}
}
public static class SelectorExtensions {
public static IDisposable SubscribeSelectionChanged(this System.Windows.Controls.Primitives.Selector target, SelectionChangedEventHandler callback) {
target.SelectionChanged += callback;
return Disposable.Create(() => target.SelectionChanged -= callback);
}
}
public static class ScrollViewerExtensions {
public static IDisposable SubscribeScrollChanged(this ScrollViewer target, ScrollChangedEventHandler callback) {
target.ScrollChanged += callback;
@@ -66,11 +66,18 @@ namespace mbts.ui {
}
}
// TODO: replace this method with 'argb_color'
// - before that, need to verify that no settings/colors become 'invisible' as a result.
public static Color rgb_color(this UInt32 color) {
var bytes = BitConverter.GetBytes(color);
return Color.FromRgb(bytes[2], bytes[1], bytes[0]);
}
public static Color argb_color(this uint color) {
var bytes = BitConverter.GetBytes(color);
return Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
}
public static SolidColorBrush to_brush(this BTSColor color) =>
new SolidColorBrush(color);
@@ -103,6 +110,9 @@ namespace mbts.ui {
return brush;
}
public static Color with(this Color color, byte alpha) =>
Color.FromArgb(alpha, color.R, color.G, color.B);
public static SolidColorBrush with(this SolidColorBrush brush, double opacity) {
brush.Opacity = opacity;
return brush;
@@ -49,6 +49,8 @@
<RowDefinition Height="{Binding Source={StaticResource VerticalPush1}}"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="{Binding Source={StaticResource VerticalPush1}}"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="{Binding Source={StaticResource VerticalPush1}}"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
@@ -69,8 +71,10 @@
</Grid>
<TextBlock Grid.Row="2">Font Color (default)</TextBlock>
<c:ColorPickerPopupWithOpacitySlider Grid.Row="2" Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" DataContext="{Binding font_color}" CanUserEditOpacity="False"/>
<TextBlock Grid.Row="4">Selection Highlight</TextBlock>
<c:ColorPickerPopupWithOpacitySlider Grid.Row="4" Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" DataContext="{Binding selection_highlight}"/>
<TextBlock Grid.Row="4" Visibility="{Binding show_background_color, Converter={StaticResource BoolToVisibility}}">Background Color (default)</TextBlock>
<c:ColorPickerPopupWithOpacitySlider Grid.Row="4" Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" DataContext="{Binding background_color}" Visibility="{Binding DataContext.show_background_color, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=usp:GridSettingsView}, Converter={StaticResource BoolToVisibility}}" />
<TextBlock Grid.Row="6">Selection Highlight</TextBlock>
<c:ColorPickerPopupWithOpacitySlider Grid.Row="6" Grid.Column="2" HorizontalAlignment="Left" Width="{StaticResource ControlLongWidth}" DataContext="{Binding selection_highlight}"/>
</Grid>
</DataTemplate>