PNLView - get rid of magic const row height

This commit is contained in:
John Colvin committed 2020-02-21 17:39:35 -06:00
1 parent b1b1597686
commit e9615bc3aa
4 files changed
+1238 -1164

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -6,6 +6,7 @@ using mbts.ui;
using mbts.ui.controls;
using mbts.ui.controls.adorners;
using mbts.ui.converters;
using mbts.ui.dpi;
using mbts.ui.extensions;
using mbts.ui.spark;
using mbts.ui.utility;
@@ -31,6 +32,10 @@ namespace bts.shell.pnl {
}
partial class PNLView : UserControl {
public static readonly double
MinGroupRowHeight = 24.0.RoundLayoutValue(),
MinHeaderRowHeight = 24.0.RoundLayoutValue();
public enum Columns {
Account = 1,
// Security
@@ -85,6 +90,7 @@ namespace bts.shell.pnl {
public static readonly IValueConverter
IncrementalGroupLevelConverter = ValueConverter.create<int, int>(level => level + 1),
GroupLevelMarginConverter = ValueConverter.create<int, Thickness>(level => new Thickness(24 * level, 0, 0, 0)),
HeaderRowHeightConverter = new RangeBlockConverter<double> { Minimum = MinHeaderRowHeight },
ExpandedVisualStateConverter = ValueConverter.create<bool, string>(is_expanded => is_expanded ? "Expanded" : "Collapsed");
public static readonly IMultiValueConverter
@@ -163,17 +169,22 @@ namespace bts.shell.pnl {
void _grid_loaded(object sender, RoutedEventArgs e) {
// this is a hack to make room for the 'totals row' between the column headers and the regular rows.
if (_grid.try_find_descendent_of_type(out DIYGridRowsPresenter rp)) {
rp.SetBinding(MarginProperty, new Binding(nameof(PNLVM.header_row_display)) {
Converter = ValueConverter.create<PNLHeaderRowDisplay, Thickness>(hrd => {
double top = 0;
if ((hrd & PNLHeaderRowDisplay.Total) != 0)
top += 24;
if ((hrd & PNLHeaderRowDisplay.SelectedTotal) != 0)
top += 24;
return new Thickness(0, top, 0, 0);
}),
Source = DataContext
});
rp.SetBinding(MarginProperty,
BindingHelper.create_multi(
ValueConverter.create<PNLHeaderRowDisplay, double, Thickness>((hrd, row_height) => {
double top = 0;
if ((hrd & PNLHeaderRowDisplay.Total) != 0)
top += row_height;
if ((hrd & PNLHeaderRowDisplay.SelectedTotal) != 0)
top += row_height;
return new Thickness(0, top, 0, 0);
}),
new Binding(nameof(PNLVM.header_row_display)),
new Binding {
Path = new PropertyPath(DIYGrid.RowHeightProperty),
Converter = HeaderRowHeightConverter,
Source = _grid
}));
}
}
#endregion
@@ -0,0 +1,46 @@
using System;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;
namespace mbts.ui.converters {
class RangeBlockConverter : IValueConverter {
public IComparable Minimum { get; set; }
public IComparable Maximum { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (value is IComparable comp) {
if (Minimum != null && comp.CompareTo(Minimum) < 0)
return Minimum;
if (Maximum != null && comp.CompareTo(Maximum) > 0)
return Maximum;
} else {
return new ValidationResult(false, $"Value does not implement {typeof(IComparable)}.");
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotImplementedException();
}
class RangeBlockConverter<T> : IValueConverter where T : struct, IComparable<T> {
public T? Maximum { get; set; }
public T? Minimum { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (value is T v) {
if (Minimum.HasValue && v.CompareTo(Minimum.Value) < 0)
return Minimum.Value;
if (Maximum.HasValue && v.CompareTo(Maximum.Value) > 0)
return Maximum.Value;
} else {
return new ValidationResult(false, $"Value is not of type {typeof(T)}.");
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotImplementedException();
}
}
@@ -0,0 +1,14 @@
using System.Windows.Data;
namespace mbts.ui {
static class BindingHelper {
public static MultiBinding create_multi(IMultiValueConverter converter, params Binding[] bindings) {
var mb = new MultiBinding {
Converter = converter
};
for (int i = 0; i < bindings.Length; i++)
mb.Bindings.Add(bindings[i]);
return mb;
}
}
}