PNL group/header font color settings work now
This commit is contained in:
1 parent
69fdec2866
commit
f9b67c7ee4
6 files changed
+73
-53
No files matched your search
@@ -61,17 +61,16 @@ namespace bts.shell.pnl {
|
||||
[ProtoMember(1)]
|
||||
public FontParamsProto font_params { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public uint? foreground { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public uint? background { get; set; }
|
||||
|
||||
public static PNLCellAppearanceProto from_appearance(PNLCellAppearance cell_appearance) =>
|
||||
new PNLCellAppearanceProto {
|
||||
font_params = new FontParamsProto {
|
||||
font_family = cell_appearance.font_family?.name(),
|
||||
typeface = new TypefaceProto(
|
||||
cell_appearance.font_family?.name(),
|
||||
(cell_appearance.font_weight ?? FontWeights.Normal).ToOpenTypeWeight()),
|
||||
font_color = cell_appearance.foreground?.rgb_color() ?? 0,
|
||||
font_size = cell_appearance.font_size,
|
||||
font_weight = (cell_appearance.font_weight ?? FontWeights.Normal).ToOpenTypeWeight()
|
||||
},
|
||||
background = cell_appearance.background?.rgb_color()
|
||||
};
|
||||
@@ -79,7 +78,7 @@ namespace bts.shell.pnl {
|
||||
public PNLCellAppearance to_appearance() {
|
||||
var font = font_params?.to_wpf_params();
|
||||
return new PNLCellAppearance(
|
||||
foreground?.rgb_color(),
|
||||
font?.color,
|
||||
background?.argb_color(),
|
||||
font?.weight,
|
||||
font?.family,
|
||||
@@ -88,7 +87,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
public bool Equals(PNLCellAppearanceProto other) =>
|
||||
other != null &&
|
||||
foreground == other.foreground &&
|
||||
background == other.background &&
|
||||
font_params.safe_equals(other.font_params);
|
||||
|
||||
|
||||
@@ -83,19 +83,21 @@ namespace bts.shell.pnl {
|
||||
header_row_display = PNLHeaderRowDisplay.Total,
|
||||
_anchors = new[] { Columns.Account, Columns.Symbol },
|
||||
_group_cell_appearance = new PNLCellAppearanceProto {
|
||||
foreground = Colors.Black.rgb_color(),
|
||||
font_params = new FontParamsProto {
|
||||
font_family = GridSettings.Default.font_family,
|
||||
font_weight = FontWeights.Bold.ToOpenTypeWeight(),
|
||||
typeface = new TypefaceProto(
|
||||
GridSettings.Default.font_family,
|
||||
FontWeights.Bold.ToOpenTypeWeight()),
|
||||
font_color = Colors.Black.rgb_color(),
|
||||
font_size = 11
|
||||
},
|
||||
background = Colors.Transparent.rgb_color()
|
||||
},
|
||||
_header_cell_appearance = new PNLCellAppearanceProto {
|
||||
foreground = Colors.Black.rgb_color(),
|
||||
font_params = new FontParamsProto {
|
||||
font_family = GridSettings.Default.font_family,
|
||||
font_weight = FontWeights.Bold.ToOpenTypeWeight(),
|
||||
typeface = new TypefaceProto(
|
||||
GridSettings.Default.font_family,
|
||||
FontWeights.Bold.ToOpenTypeWeight()),
|
||||
font_color = Colors.Black.rgb_color(),
|
||||
font_size = 12
|
||||
},
|
||||
background = Colors.Transparent.rgb_color()
|
||||
@@ -214,6 +216,12 @@ namespace bts.shell.pnl {
|
||||
background: grid.background,
|
||||
foreground: grid.font_color.rgb_color());
|
||||
|
||||
public PNLCellAppearance group_defaults =>
|
||||
group_cell_appearance.to_appearance().merge(grid_defaults);
|
||||
|
||||
public PNLCellAppearance header_defaults =>
|
||||
header_cell_appearance.to_appearance().merge(grid_defaults);
|
||||
|
||||
public PNLCellAppearanceProto group_cell_appearance {
|
||||
get => _group_cell_appearance ?? _grid_cell_appearance;
|
||||
set => _group_cell_appearance = value;
|
||||
@@ -234,11 +242,11 @@ namespace bts.shell.pnl {
|
||||
PNLCellAppearanceProto _grid_cell_appearance => _grid_cell_appearance_backing ?? (
|
||||
_grid_cell_appearance_backing = new PNLCellAppearanceProto {
|
||||
background = grid.background.rgb_color(),
|
||||
foreground = grid.font_color,
|
||||
font_params = new FontParamsProto {
|
||||
//font_color = grid.font_color,
|
||||
font_family = grid.font_family,
|
||||
font_weight = grid.font_weight.ToOpenTypeWeight(),
|
||||
font_color = grid.font_color,
|
||||
typeface = new TypefaceProto(
|
||||
grid.font_family,
|
||||
grid.font_weight.ToOpenTypeWeight()),
|
||||
font_size = grid.font_size
|
||||
}
|
||||
});
|
||||
|
||||
@@ -107,15 +107,15 @@ namespace bts.shell.pnl {
|
||||
public PNLCellAppearanceProto to_appearance_proto() =>
|
||||
new PNLCellAppearanceProto {
|
||||
background = is_background_overridden ? background_override.color.rgb_color() : (uint?)null,
|
||||
foreground = is_font_color_overridden ? font_color_override.color.rgb_color() : (uint?)null,
|
||||
font_params = to_font_params()
|
||||
};
|
||||
|
||||
public FontParamsProto to_font_params() =>
|
||||
new FontParamsProto {
|
||||
typeface = new TypefaceProto(
|
||||
font_family_override?.name(),
|
||||
is_font_weight_overridden ? font_weight_override.ToOpenTypeWeight() : 0),
|
||||
font_color = is_font_color_overridden ? font_color_override.color.rgb_color() : 0,
|
||||
font_weight = is_font_weight_overridden ? font_weight_override.ToOpenTypeWeight() : 0,
|
||||
font_family = font_family_override?.name(),
|
||||
font_size = font_size_override
|
||||
};
|
||||
}
|
||||
|
||||
@@ -316,8 +316,8 @@ namespace bts.shell.pnl {
|
||||
header_row_display = settings.header_row_display;
|
||||
//
|
||||
map_appearances(ref _default_appearances, settings.grid.columns, settings.grid_defaults);
|
||||
map_appearances(ref _default_group_appearances, settings.group_columns, settings.group_cell_appearance.to_appearance().merge(settings.grid_defaults));
|
||||
map_appearances(ref _default_header_appearances, settings.header_columns, settings.header_cell_appearance.to_appearance().merge(settings.grid_defaults));
|
||||
map_appearances(ref _default_group_appearances, settings.group_columns, settings.group_cell_appearance.to_appearance().merge(settings.group_defaults));
|
||||
map_appearances(ref _default_header_appearances, settings.header_columns, settings.header_cell_appearance.to_appearance().merge(settings.header_defaults));
|
||||
_triggers = settings.triggers();
|
||||
_group_triggers = settings.group_triggers();
|
||||
_header_triggers = settings.header_triggers();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using mbts.ui;
|
||||
using bts.utils;
|
||||
using mbts.ui;
|
||||
using mbts.ui.utility.text;
|
||||
using ProtoBuf;
|
||||
using System;
|
||||
@@ -9,49 +10,56 @@ using FontFamily = System.Windows.Media.FontFamily;
|
||||
namespace bts.proto {
|
||||
[ProtoContract]
|
||||
class FontParamsProto : IEquatable<FontParamsProto> {
|
||||
static readonly int _type_hash = typeof(FontParamsProto).GetHashCode();
|
||||
|
||||
[ProtoMember(1)]
|
||||
public string font_family { get; set; }
|
||||
public TypefaceProto typeface { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public int font_weight { get; set; }
|
||||
public double font_size { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public uint font_color { get; set; }
|
||||
[ProtoMember(4)]
|
||||
public double font_size { get; set; }
|
||||
|
||||
public (FontFamily family, FontWeight? weight, Color? color, double size) to_wpf_params() =>
|
||||
(string.IsNullOrEmpty(font_family) ? null : new FontFamily(font_family),
|
||||
font_weight == 0 ? (FontWeight?)null : FontWeight.FromOpenTypeWeight(font_weight),
|
||||
font_color == 0 ? (Color?)null : font_color.argb_color(),
|
||||
// zero is an invalid font size, convert to nan to follow convention
|
||||
font_size == 0 ? double.NaN : font_size);
|
||||
|
||||
public (FontFamily family, FontWeight weight, Color color, double size) to_wpf_params_safe(
|
||||
FontFamily fallback_family = null,
|
||||
FontWeight? fallback_weight = null,
|
||||
Color? fallback_color = null,
|
||||
double fallback_size = double.NaN) {
|
||||
//
|
||||
var (family, weight, color, size) = to_wpf_params();
|
||||
return (
|
||||
family ?? fallback_family ?? TextUtils.StandardFontFamily,
|
||||
weight ?? fallback_weight ?? FontWeights.Normal,
|
||||
color ?? fallback_color ?? Colors.Black,
|
||||
double.IsNaN(font_size) ? double.IsNaN(fallback_size) ? FontSizes.Small : fallback_size : font_size);
|
||||
}
|
||||
public string font_family => typeface.font_family;
|
||||
public int font_weight => typeface.font_weight;
|
||||
|
||||
public bool Equals(FontParamsProto other) =>
|
||||
other != null &&
|
||||
font_family == other.font_family &&
|
||||
font_weight == other.font_weight &&
|
||||
font_color == other.font_color &&
|
||||
font_size.Equals(other.font_size);
|
||||
typeface == other.typeface &&
|
||||
font_size == other.font_size &&
|
||||
font_color == other.font_color;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as FontParamsProto);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
_type_hash;
|
||||
typeface.GetHashCode();
|
||||
}
|
||||
|
||||
static class FontParamsProtoExtensions {
|
||||
public static (FontFamily family, FontWeight? weight, Color? color, double size) to_wpf_params(this FontParamsProto proto) =>
|
||||
proto.typeface.to_typeface_parts().with(
|
||||
_to_nullable_color(proto.font_color),
|
||||
// zero/negative are invalid font sizes, convert to nan to follow convention
|
||||
proto.font_size <= 0 ? double.NaN : proto.font_size);
|
||||
|
||||
public static (FontFamily family, FontWeight? weight, Color? color, double size) to_wpf_params_safe(this FontParamsProto proto,
|
||||
FontFamily fallback_family = null,
|
||||
FontWeight? fallback_weight = null,
|
||||
Color? fallback_color = null,
|
||||
double fallback_size = double.NaN) =>
|
||||
//
|
||||
proto.typeface.to_typeface_parts_safe(fallback_family, fallback_weight).with(
|
||||
_to_color_safe(proto.font_color, fallback_color ?? Colors.Black),
|
||||
_to_size_safe(proto.font_size));
|
||||
|
||||
static Color? _to_nullable_color(uint proto) =>
|
||||
proto == 0 ? (Color?)null : proto.argb_color();
|
||||
|
||||
static Color _to_color_safe(uint proto, Color fallback_color) =>
|
||||
_to_nullable_color(proto) ?? fallback_color;
|
||||
|
||||
static double _to_size_safe(double size, double fallback_size = double.NaN) =>
|
||||
double.IsNaN(size) ?
|
||||
(double.IsNaN(fallback_size) ? FontSizes.Small : fallback_size) :
|
||||
size;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace bts.utils {
|
||||
public static class TupleExtensions {
|
||||
public static (T1, T2, T3, T4) with<T1, T2, T3, T4>(this (T1, T2) tuple, T3 value3, T4 value4) =>
|
||||
(tuple.Item1, tuple.Item2, value3, value4);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user