DIYGrid style changes
This commit is contained in:
1 parent
890143c806
commit
7c8da47f6e
7 files changed
+98
-51
No files matched your search
@@ -40,9 +40,9 @@ namespace mbts.spark {
|
||||
_orders_model = orders_model;
|
||||
string format_price(double price) => security.ContractSpec.format(price);
|
||||
_position = new CellProperty<int>(0);
|
||||
_bid_price = new CellProperty<double>(format_price, double.NaN);
|
||||
_bid_price = new CellProperty<double>(format_price, BTSColors.header_text_brush, double.NaN);
|
||||
_bid_size = new CellProperty<ushort>(0);
|
||||
_ask_price = new CellProperty<double>(format_price, double.NaN);
|
||||
_ask_price = new CellProperty<double>(format_price, BTSColors.header_text_brush, double.NaN);
|
||||
_ask_size = new CellProperty<ushort>(0);
|
||||
_last_price = new CellProperty<double>(format_price, double.NaN);
|
||||
_last_size = new CellProperty<ushort>(0);
|
||||
@@ -63,8 +63,8 @@ namespace mbts.spark {
|
||||
_working_best_ask = new CellProperty<double>(format_price, double.NaN);
|
||||
_working_bids_text = new CellProperty<string>(string.Empty);
|
||||
_working_asks_text = new CellProperty<string>(string.Empty);
|
||||
_security_formatted_text = TextUtils.GetFormattedText(smd.security.ToString(null));
|
||||
_security_key_formatted_text = TextUtils.GetFormattedText(smd.security.Id.ToString());
|
||||
_security_formatted_text = TextUtils.GetFormattedText(smd.security.ToString(null), FontSizes.Small);
|
||||
_security_key_formatted_text = TextUtils.GetFormattedText(smd.security.Id.ToString(), FontSizes.Small);
|
||||
//
|
||||
_dispose = Disposable.Create(
|
||||
_orders_model.on_security_orders(security.Id).ObserveOnDispatcher().Subscribe(_on_orders)
|
||||
@@ -240,37 +240,7 @@ namespace mbts.spark {
|
||||
_working_bids_text.on_next_distinct(OrderUtils.order_collection_summary(_working_bids, (x, y) => x.CompareTo(y), security.ContractSpec), ref dirty);
|
||||
_working_asks_text.on_next_distinct(OrderUtils.order_collection_summary(_working_asks, (x, y) => y.CompareTo(x), security.ContractSpec), ref dirty);
|
||||
}
|
||||
#endregion
|
||||
|
||||
class CellProperty<T> : IObserver<T> {
|
||||
readonly Func<T, string> _format;
|
||||
FormattedText _formatted_text;
|
||||
|
||||
public CellProperty(T initial_value = default)
|
||||
: this(t => t.ToString(), initial_value) { }
|
||||
|
||||
public CellProperty(Func<T, string> format, T initial_value = default) {
|
||||
_format = format;
|
||||
this.value = initial_value;
|
||||
}
|
||||
|
||||
public T value { get; private set; }
|
||||
public FormattedText formatted_text =>
|
||||
_formatted_text ?? (_formatted_text = TextUtils.GetFormattedText(_format(value)));
|
||||
|
||||
public void on_next_distinct(T value, ref bool dirty) {
|
||||
if (!value.Equals(this.value)) {
|
||||
OnNext(value);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
public void OnCompleted() { }
|
||||
public void OnError(Exception error) { }
|
||||
public void OnNext(T value) {
|
||||
this.value = value;
|
||||
_formatted_text = null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,8 +43,8 @@ namespace mbts.spark {
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.Position]) { Header = "Pos", original_width = 70 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.WorkingBids]) { Header = "Working", original_width = 70 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.BidSize]) { Header = "Qty", original_width = 70 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.Bid]) { Header = "Bid", original_width = 80 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.Ask]) { Header = "Ask", original_width = 80 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.Bid], BTSColors.MarketData.bid_brush) { Header = "Bid", original_width = 80 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.Ask], BTSColors.MarketData.ask_brush) { Header = "Ask", original_width = 80 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.AskSize]) { Header = "Qty", original_width = 70 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.WorkingAsks]) { Header = "Working", original_width = 70 });
|
||||
columns.Add(new DIYGrid.SimpleTextColumn<Row>(r => r[MarketViewView.Columns.Settlement]) { Header = "Settlement", original_width = 70 });
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using mbts.ui;
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
class CellProperty<T> : IObserver<T> {
|
||||
readonly Func<T, string> _format;
|
||||
readonly Brush _foreground;
|
||||
FormattedText _formatted_text;
|
||||
|
||||
public CellProperty(T initial_value = default)
|
||||
: this(t => t.ToString(), SystemColors.ControlTextBrush, initial_value) { }
|
||||
|
||||
public CellProperty(Func<T, string> format, T initial_value = default)
|
||||
: this(format, SystemColors.ControlTextBrush, initial_value) { }
|
||||
|
||||
public CellProperty(Func<T, string> format, Brush foreground, T initial_value = default) {
|
||||
_format = format;
|
||||
_foreground = foreground;
|
||||
value = initial_value;
|
||||
}
|
||||
|
||||
public T value { get; private set; }
|
||||
public FormattedText formatted_text =>
|
||||
_formatted_text ?? (_formatted_text = TextUtils.GetFormattedText(_format(value), FontSizes.Small, _foreground));
|
||||
|
||||
public void on_next_distinct(T value, ref bool dirty) {
|
||||
if (!value.Equals(this.value)) {
|
||||
OnNext(value);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
public void OnCompleted() { }
|
||||
public void OnError(Exception error) { }
|
||||
public void OnNext(T value) {
|
||||
this.value = value;
|
||||
_formatted_text = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,18 +12,25 @@ namespace mbts.ui.controls {
|
||||
public partial class DIYGrid {
|
||||
public interface IColumnBase<TRowVM> {
|
||||
void draw(TRowVM row, DrawingContext drawing_context, double left, double unclipped_left, double row_height, double padding, out double resultant_width);
|
||||
Brush background { get; }
|
||||
}
|
||||
|
||||
// To include extra data with your column type you are encouraged to derive from DIYGridColumn
|
||||
public abstract class ColumnBase : GridViewColumn {
|
||||
public ColumnBase() {
|
||||
protected ColumnBase(Brush background = null) {
|
||||
this.background = background ?? Brushes.Transparent;
|
||||
original_width = double.NaN;
|
||||
}
|
||||
|
||||
public double original_width { get; set; }
|
||||
public bool is_collapsed { get; set; }
|
||||
public Brush background { get; }
|
||||
}
|
||||
|
||||
public abstract class ColumnBase<TRowVM> : ColumnBase, IColumnBase<TRowVM> {
|
||||
protected ColumnBase(Brush background = null)
|
||||
: base(background) { }
|
||||
|
||||
public abstract void draw(TRowVM row, DrawingContext drawing_context, double left, double unclipped_left, double row_height, double padding, out double total_width);
|
||||
}
|
||||
|
||||
@@ -31,8 +38,8 @@ namespace mbts.ui.controls {
|
||||
public class SimpleTextColumn<TRowVM> : ColumnBase<TRowVM>, IColumnBase<TRowVM> {
|
||||
readonly Func<TRowVM, FormattedText> _get_formatted_text;
|
||||
|
||||
public SimpleTextColumn(Func<TRowVM, FormattedText> get_formatted_text) =>
|
||||
_get_formatted_text = get_formatted_text;
|
||||
public SimpleTextColumn(Func<TRowVM, FormattedText> get_formatted_text, Brush background = null)
|
||||
: base(background) => _get_formatted_text = get_formatted_text;
|
||||
|
||||
public override void draw(TRowVM row, DrawingContext drawing_context, double left, double unclipped_left, double row_height, double padding, out double total_width) {
|
||||
// draw text centered vertially
|
||||
|
||||
@@ -332,7 +332,7 @@ namespace mbts.ui.controls {
|
||||
set { SetValue(ColumnHeightProperty, value); }
|
||||
}
|
||||
public static readonly DependencyProperty ColumnHeightProperty =
|
||||
DependencyProperty.Register("ColumnHeight", typeof(double), typeof(DIYGrid), new FrameworkPropertyMetadata(25.0, column_height_changed));
|
||||
DependencyProperty.Register("ColumnHeight", typeof(double), typeof(DIYGrid), new FrameworkPropertyMetadata(17.0, column_height_changed));
|
||||
public IEnumerable Rows {
|
||||
get { return (IEnumerable)GetValue(RowsProperty); }
|
||||
set { SetValue(RowsProperty, value); }
|
||||
|
||||
@@ -3,15 +3,18 @@
|
||||
xmlns:mbts="clr-namespace:mbts.ui"
|
||||
xmlns:ui="clr-namespace:mbts.ui"
|
||||
xmlns:bts="clr-namespace:mbts.ui.controls">
|
||||
<SolidColorBrush x:Key="Row.MouseOver.Background" Color="MediumSlateBlue" Opacity="0.1"/>
|
||||
<SolidColorBrush x:Key="Row.SelectedActive.Background" Color="MediumSlateBlue" Opacity="0.4"/>
|
||||
<SolidColorBrush x:Key="Row.SelectedInactive.Background" Color="MediumSlateBlue" Opacity="0.25"/>
|
||||
<Style TargetType="bts:DIYGrid">
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="SelectionMode" Value="Extended" />
|
||||
<Setter Property="ColumnHeaderStyle">
|
||||
<Setter.Value>
|
||||
<Style TargetType="GridViewColumnHeader">
|
||||
<Setter Property="Background" Value="{mbts:BTSColor Name=header}"/>
|
||||
<Setter Property="Foreground" Value="{mbts:BTSColor Name=header_text}"/>
|
||||
<Setter Property="BorderBrush" Value="Black"/>
|
||||
<Setter Property="Background" Value="{mbts:BTSColor header}"/>
|
||||
<Setter Property="Foreground" Value="{mbts:BTSColor header_text}"/>
|
||||
<Setter Property="BorderBrush" Value="{mbts:BTSColor header}"/>
|
||||
<Setter Property="BorderThickness" Value="0,1,1,0"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
||||
<Setter Property="Height" Value="30" />
|
||||
@@ -27,7 +30,13 @@
|
||||
</Grid.RowDefinitions>
|
||||
<!--<Rectangle x:Name="UpperHighlight" Fill="#FFE3F7FF" Visibility="Collapsed"/>-->
|
||||
<Border Padding="{TemplateBinding Padding}" Grid.RowSpan="2">
|
||||
<ContentPresenter x:Name="HeaderContent" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0,0,0,1" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
<ContentPresenter
|
||||
x:Name="HeaderContent"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentStringFormat="{TemplateBinding ContentStringFormat}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Margin="0,0,0,1" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
@@ -36,6 +45,7 @@
|
||||
<Thumb.Style>
|
||||
<Style TargetType="{x:Type Thumb}">
|
||||
<Setter Property="Canvas.Right" Value="-9"/>
|
||||
<Setter Property="Cursor" Value="SizeWE"/>
|
||||
<Setter Property="Width" Value="18"/>
|
||||
<Setter Property="Height" Value="{Binding ActualHeight, RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
@@ -179,4 +189,4 @@
|
||||
</Setter>
|
||||
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
@@ -208,7 +208,7 @@ namespace mbts.ui.controls {
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class Row<TRowVM> : RowBase where TRowVM : IRowVM {
|
||||
public class Row<TRowVM> : RowBase where TRowVM : class, IRowVM {
|
||||
const double _padding = 5.0;
|
||||
TRowVM _row;
|
||||
|
||||
@@ -216,15 +216,33 @@ namespace mbts.ui.controls {
|
||||
DataContextChanged += (s, e) => {
|
||||
if (e.OldValue is TRowVM old_row)
|
||||
old_row.invalidated -= InvalidateVisual;
|
||||
_row = (TRowVM)e.NewValue;
|
||||
_row.invalidated += InvalidateVisual;
|
||||
_row = e.NewValue as TRowVM;
|
||||
if (_row != null)
|
||||
_row.invalidated += InvalidateVisual;
|
||||
};
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc) {
|
||||
if (_grid == null) return;
|
||||
// Fill with transparent for hit testing
|
||||
dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, new Rect(0, 0, _column_geometry.Sum(g => g.width), RenderSize.Height));
|
||||
// batch background draws
|
||||
using (var col_en = _column_geometry.GetEnumerator()) {
|
||||
Brush curr_brush = Brushes.Transparent;
|
||||
double x = 0, curr_dist = 0, height = RenderSize.Height;
|
||||
while (col_en.MoveNext()) {
|
||||
ColumnBase col = col_en.Current.column;
|
||||
if (col.background.Equals(curr_brush))
|
||||
curr_dist += col.ActualWidth;
|
||||
else {
|
||||
draw_background_part();
|
||||
x += curr_dist;
|
||||
curr_brush = col.background;
|
||||
curr_dist = col.ActualWidth;
|
||||
}
|
||||
}
|
||||
void draw_background_part() =>
|
||||
dc.DrawRectangle(curr_brush, null, new Rect(x, 0, curr_dist, height));
|
||||
}
|
||||
if (_row == null) return;
|
||||
|
||||
string last_group = "";
|
||||
foreach (var cell in _column_geometry) {
|
||||
|
||||
Reference in new issue
Block a user