fix(ui): kit follow-ups for lists, chart contrast, activation and RTL bars
- ListBox (and the Library card grid) get a theme template that keeps their fill when disabled; ListView keeps the system GridView template. - BarChart, HeatmapStrip, SeriesChart and TimelineBands draw their labels in TextMuted; heatmap cells without data take the Stroke tone. - Category charts show the hand cursor and take the keyboard (arrows, Home, End, Enter, Space) only while an activation handler is attached to them; the keyboard item is outlined, read out and exposed as ItemStatus. - Horizontal bar charts and stacked bars start on the reading side in right-to-left languages; vertical bars, heatmaps and time axes stay LTR. - Archive drops its local list template, Focus.Inset copy, chart brush aliases and the redundant FlowDirection on the template box. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
10 files changed
+350
-197
No files matched your search
@@ -8,36 +8,6 @@
|
||||
xmlns:infra="clr-namespace:Titano.App.Infrastructure"
|
||||
xmlns:shell="clr-namespace:Titano.App.Shell">
|
||||
<UserControl.Resources>
|
||||
<!-- Keyboard focus drawn inside the row (DESIGN §4 ring): an outer ring would be clipped by the list's scroll viewer. -->
|
||||
<Style x:Key="Focus.Inset">
|
||||
<Setter Property="Control.Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Border BorderBrush="{DynamicResource Brush.Accent}" BorderThickness="2" CornerRadius="{StaticResource Radius.Control}" SnapsToDevicePixels="True" />
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!--
|
||||
Lists keep their panel's fill while the screen behind a dialog is disabled: the system template would paint them
|
||||
white. Rows and buttons dim themselves.
|
||||
-->
|
||||
<Style TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBox">
|
||||
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Padding="1" SnapsToDevicePixels="True">
|
||||
<ScrollViewer Focusable="False" Padding="{TemplateBinding Padding}">
|
||||
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Text.PanelHeading" TargetType="TextBlock" BasedOn="{StaticResource Text.Section}">
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
@@ -162,7 +132,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{l:Loc Archive.Rename.Template}" Style="{StaticResource Text.DialogLabel}" />
|
||||
<!-- A naming template keeps its tokens and separators in order in every language. -->
|
||||
<TextBox Grid.Column="1" Style="{StaticResource TextBox.Mono}" FlowDirection="LeftToRight"
|
||||
<TextBox Grid.Column="1" Style="{StaticResource TextBox.Mono}"
|
||||
Text="{Binding Template.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" shell:EditBehavior.Field="{Binding Template}"
|
||||
ToolTip="{Binding Template.ToolTip}" AutomationProperties.Name="{l:Loc Archive.Rename.Template}" />
|
||||
</Grid>
|
||||
@@ -366,13 +336,6 @@
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Column="2">
|
||||
<!--
|
||||
Chart labels in TextMuted as in Archive.html: the kit's charts draw them in TextFaint, too faint for 11 px data
|
||||
labels (reported to the shared controls; remove this alias once they draw in TextMuted).
|
||||
-->
|
||||
<Grid.Resources>
|
||||
<SolidColorBrush x:Key="Brush.TextFaint" Color="{DynamicResource Color.TextMuted}" />
|
||||
</Grid.Resources>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="14" />
|
||||
@@ -432,12 +395,7 @@
|
||||
</DockPanel>
|
||||
<v:HeatmapStrip Rows="{Binding MonthRows}" ColumnLabels="{Binding MonthLabels}" ValueFormatter="{Binding CountFormatter}" MaxCellSize="32" ShowScale="False"
|
||||
ToolTip="{l:Loc Tooltips.Archive.Months}" AutomationProperties.Name="{l:Loc Archive.Chart.Months}"
|
||||
AutomationProperties.HelpText="{Binding MonthsDescription}">
|
||||
<!-- Months still to come in the Stroke tone: the kit fills them with Card, the panel's own colour in the light theme. -->
|
||||
<v:HeatmapStrip.Resources>
|
||||
<SolidColorBrush x:Key="Brush.Card" Color="{DynamicResource Color.Stroke}" />
|
||||
</v:HeatmapStrip.Resources>
|
||||
</v:HeatmapStrip>
|
||||
AutomationProperties.HelpText="{Binding MonthsDescription}" />
|
||||
</DockPanel>
|
||||
</Border>
|
||||
<Border Grid.Row="2" Grid.Column="2" Style="{StaticResource Border.Panel}" Padding="14,10">
|
||||
|
||||
@@ -750,7 +750,30 @@
|
||||
</Style>
|
||||
|
||||
<!-- ===================== Lists and tables ===================== -->
|
||||
<Style TargetType="ListBox">
|
||||
<!--
|
||||
The system template paints a disabled list white whatever the theme (a list behind a dialog is disabled): this one
|
||||
keeps the list's own fill, and its rows and buttons dim themselves. Same frame and scroll viewer as the system's.
|
||||
-->
|
||||
<ControlTemplate x:Key="Template.ListBox" TargetType="ListBox">
|
||||
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Padding="1" SnapsToDevicePixels="True">
|
||||
<ScrollViewer Focusable="False" Padding="{TemplateBinding Padding}">
|
||||
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="True" />
|
||||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<!-- Shared by ListBox and ListView; a ListView keeps the system template, which carries the GridView header row. -->
|
||||
<Style x:Key="ListBox.Base" TargetType="ListBox">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
|
||||
@@ -761,6 +784,10 @@
|
||||
<Setter Property="VirtualizingPanel.ScrollUnit" Value="Pixel" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="ListBox" BasedOn="{StaticResource ListBox.Base}">
|
||||
<Setter Property="Template" Value="{StaticResource Template.ListBox}" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="FocusVisualStyle" Value="{StaticResource Focus.Inset}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
|
||||
@@ -820,7 +847,7 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="ListView" BasedOn="{StaticResource {x:Type ListBox}}">
|
||||
<Style TargetType="ListView" BasedOn="{StaticResource ListBox.Base}">
|
||||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
|
||||
</Style>
|
||||
|
||||
|
||||
@@ -29,8 +29,10 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- Virtualized, recycling card grid (BRIEF §12.2). Item template: a v:SequenceCard bound to the item. -->
|
||||
<!-- Virtualized, recycling card grid (BRIEF §12.2). Item template: a v:SequenceCard bound to the item. Disabled (behind a
|
||||
dialog), it keeps its fill like every other list (Controls.xaml Template.ListBox). -->
|
||||
<Style x:Key="ListBox.Cards" TargetType="ListBox">
|
||||
<Setter Property="Template" Value="{DynamicResource Template.ListBox}" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
|
||||
@@ -7,4 +7,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Titano.Core\Titano.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="Titano.App.Tests" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -8,10 +8,11 @@ namespace Titano.Ui.Visuals;
|
||||
|
||||
/// <summary>
|
||||
/// Bars for labelled values (Archive: storage by year, by camera, by format; uploads per day). Horizontal bars put
|
||||
/// the category labels on the left and the value labels after each bar, as in the Archive mockup; vertical bars
|
||||
/// put the categories underneath (skipping labels that would collide). Optional value gridlines use nice ticks.
|
||||
/// A bar's opacity can follow its value (<see cref="MinimumOpacity"/>). Hovering reads out the bar; clicking raises
|
||||
/// <see cref="ItemActivatedEvent"/>.
|
||||
/// the category labels on the reading side and the value labels after each bar, as in the Archive mockup, and
|
||||
/// mirror in a right-to-left language; vertical bars put the categories underneath (skipping labels that would
|
||||
/// collide) and keep them left to right. Optional value gridlines use nice ticks. A bar's opacity can follow its
|
||||
/// value (<see cref="MinimumOpacity"/>). Hovering reads out the bar; clicking raises <see cref="ItemActivatedEvent"/>,
|
||||
/// and a handler attached to the chart also gives it the hand cursor and the keyboard.
|
||||
/// </summary>
|
||||
public sealed class BarChart : DrawingElement
|
||||
{
|
||||
@@ -52,7 +53,6 @@ public sealed class BarChart : DrawingElement
|
||||
|
||||
private Rect _area;
|
||||
private double _pitch;
|
||||
private int _hover = -1;
|
||||
|
||||
/// <summary>Bars in display order.</summary>
|
||||
public IReadOnlyList<ChartItem>? Items { get => (IReadOnlyList<ChartItem>?)GetValue(ItemsProperty); set => SetValue(ItemsProperty, value); }
|
||||
@@ -79,27 +79,32 @@ public sealed class BarChart : DrawingElement
|
||||
/// <summary>Culture-aware value formatting for value labels, ticks and readouts.</summary>
|
||||
public Func<double, string>? ValueFormatter { get => (Func<double, string>?)GetValue(ValueFormatterProperty); set => SetValue(ValueFormatterProperty, value); }
|
||||
|
||||
/// <summary>Raised when a bar is clicked, or chosen with the keyboard and Enter; attach it to the chart itself to make the bars interactive.</summary>
|
||||
public event ChartItemEventHandler ItemActivated
|
||||
{
|
||||
add => AddHandler(ItemActivatedEvent, value);
|
||||
remove => RemoveHandler(ItemActivatedEvent, value);
|
||||
add
|
||||
{
|
||||
AddHandler(ItemActivatedEvent, value);
|
||||
TrackActivation(value, added: true);
|
||||
}
|
||||
remove
|
||||
{
|
||||
RemoveHandler(ItemActivatedEvent, value);
|
||||
TrackActivation(value, added: false);
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override string? AutomationDescription =>
|
||||
Items is { Count: > 0 } items ? string.Join(Environment.NewLine, items.Select(ReadoutText)) : null;
|
||||
|
||||
protected override int ItemCount => Items?.Count ?? 0;
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
var count = Items?.Count ?? 0;
|
||||
return Orientation == Orientation.Horizontal ? new Size(0, count * (BarThickness + RowGap)) : new Size(0, 120);
|
||||
}
|
||||
|
||||
protected override void OnDataChanged()
|
||||
{
|
||||
_hover = -1;
|
||||
base.OnDataChanged();
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc)
|
||||
{
|
||||
DrawHitArea(dc);
|
||||
@@ -108,39 +113,40 @@ public sealed class BarChart : DrawingElement
|
||||
var max = ScaleMaximum(items);
|
||||
if (Orientation == Orientation.Horizontal) RenderHorizontal(dc, items, max);
|
||||
else RenderVertical(dc, items, max);
|
||||
DrawKeyboardItem(dc);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
protected override int ItemAt(Point point)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
var p = e.GetPosition(this);
|
||||
_hover = HitTest(p);
|
||||
Readout.Show(_hover >= 0 && Items is { } items ? ReadoutText(items[_hover]) : null, p);
|
||||
var count = ItemCount;
|
||||
if (count == 0 || _area.IsEmpty || !(_pitch > 0)) return -1;
|
||||
var index = Orientation == Orientation.Horizontal
|
||||
? (int)Math.Floor((point.Y - _area.Top) / _pitch)
|
||||
: (int)Math.Floor((point.X - _area.Left) / _pitch);
|
||||
var inside = Orientation == Orientation.Horizontal ? point.X >= 0 && point.X <= ActualWidth : point.Y >= 0 && point.Y <= ActualHeight;
|
||||
return inside && index >= 0 && index < count ? index : -1;
|
||||
}
|
||||
|
||||
protected override void OnQueryCursor(QueryCursorEventArgs e)
|
||||
/// <summary>A horizontal bar's whole row (label, bar and value), a vertical bar's whole column.</summary>
|
||||
protected override Rect ItemBounds(int item)
|
||||
{
|
||||
base.OnQueryCursor(e);
|
||||
if (e.Handled || _hover < 0) return;
|
||||
e.Cursor = Cursors.Hand;
|
||||
e.Handled = true;
|
||||
if (_area.IsEmpty || !(_pitch > 0)) return Rect.Empty;
|
||||
return Orientation == Orientation.Horizontal
|
||||
? new Rect(1, _area.Top + _pitch * item + 1, Math.Max(0, ActualWidth - 2), Math.Max(0, _pitch - 2))
|
||||
: new Rect(_area.Left + _pitch * item + 1, 1, Math.Max(0, _pitch - 2), Math.Max(0, ActualHeight - 2));
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_hover = -1;
|
||||
Readout.Hide();
|
||||
}
|
||||
protected override string? ItemText(int item) => Items is { } items && item < items.Count ? ReadoutText(items[item]) : null;
|
||||
|
||||
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
/// <summary>Up/Down move along horizontal bars, Left/Right along vertical ones (left to right in every language).</summary>
|
||||
protected override int Navigate(int item, Key key) => (Orientation, key) switch
|
||||
{
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
var index = HitTest(e.GetPosition(this));
|
||||
if (index < 0) return;
|
||||
RaiseEvent(new ChartItemEventArgs(ItemActivatedEvent, index, -1));
|
||||
e.Handled = true;
|
||||
}
|
||||
(Orientation.Horizontal, Key.Up) or (Orientation.Vertical, Key.Left) => Math.Max(0, item - 1),
|
||||
(Orientation.Horizontal, Key.Down) or (Orientation.Vertical, Key.Right) => item + 1,
|
||||
_ => -1,
|
||||
};
|
||||
|
||||
protected override void Activate(int item) => RaiseEvent(new ChartItemEventArgs(ItemActivatedEvent, item, -1));
|
||||
|
||||
private string Format(double value) => (ValueFormatter ?? DefaultFormat)(value);
|
||||
|
||||
@@ -160,24 +166,29 @@ public sealed class BarChart : DrawingElement
|
||||
private double OpacityOf(double value, double max) =>
|
||||
MinimumOpacity >= 1 ? 1 : MinimumOpacity + (1 - MinimumOpacity) * Math.Clamp(value / max, 0, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Laid out from the left and mirrored in a right-to-left language (<see cref="DrawingElement.FromStart"/>): labels on
|
||||
/// the reading side, bars growing away from it, each value after its bar's end.
|
||||
/// </summary>
|
||||
private void RenderHorizontal(DrawingContext dc, IReadOnlyList<ChartItem> items, double max)
|
||||
{
|
||||
var faint = GetBrush("Brush.TextFaint");
|
||||
var muted = GetBrush("Brush.TextMuted");
|
||||
var text = GetBrush("Brush.Text");
|
||||
var labels = new FormattedText[items.Count];
|
||||
var values = new FormattedText?[items.Count];
|
||||
double labelWidth = 0, valueWidth = 0;
|
||||
for (var i = 0; i < items.Count; i++)
|
||||
{
|
||||
labels[i] = CreateLabel(items[i].Label, LabelSize, faint);
|
||||
labels[i] = CreateLabel(items[i].Label, LabelSize, muted);
|
||||
labelWidth = Math.Max(labelWidth, labels[i].Width);
|
||||
if (!ShowValues) continue;
|
||||
values[i] = CreateLabel(items[i].ValueText ?? Format(items[i].Value), LabelSize, text);
|
||||
valueWidth = Math.Max(valueWidth, values[i]!.Width);
|
||||
}
|
||||
var width = ActualWidth;
|
||||
var gridHeight = ShowGrid ? 16 : 0;
|
||||
var left = Math.Ceiling(labelWidth) + 8;
|
||||
var right = ActualWidth - (ShowValues ? valueWidth + 6 : 0);
|
||||
var right = width - (ShowValues ? valueWidth + 6 : 0);
|
||||
_area = new Rect(left, 0, Math.Max(0, right - left), Math.Max(0, ActualHeight - gridHeight));
|
||||
_pitch = Math.Min(_area.Height / items.Count, BarThickness + RowGap);
|
||||
var thickness = Math.Max(1, Math.Min(BarThickness, _pitch - 2));
|
||||
@@ -187,28 +198,29 @@ public sealed class BarChart : DrawingElement
|
||||
{
|
||||
var item = items[i];
|
||||
var cy = _area.Top + _pitch * (i + 0.5);
|
||||
DrawTextAt(dc, labels[i], new Point(left - 8 - labels[i].Width, cy - labels[i].Height / 2));
|
||||
DrawTextAt(dc, labels[i], new Point(FromStart(left - 8 - labels[i].Width, labels[i].Width, width), cy - labels[i].Height / 2));
|
||||
var length = _area.Width * Math.Clamp(item.Value / max, 0, 1);
|
||||
if (length > 0)
|
||||
{
|
||||
dc.PushOpacity(OpacityOf(item.Value, max));
|
||||
dc.DrawRoundedRectangle(GetBrush(item.BrushKey ?? BrushKey), null, new Rect(left, cy - thickness / 2, length, thickness), 2, 2);
|
||||
dc.DrawRoundedRectangle(GetBrush(item.BrushKey ?? BrushKey), null, new Rect(FromStart(left, length, width), cy - thickness / 2, length, thickness), 2, 2);
|
||||
dc.Pop();
|
||||
}
|
||||
if (values[i] is { } value) DrawTextAt(dc, value, new Point(left + length + 6, cy - value.Height / 2));
|
||||
if (values[i] is { } value) DrawTextAt(dc, value, new Point(FromStart(left + length + 6, value.Width, width), cy - value.Height / 2));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Categories run left to right in every language: vertical bars often stand for days or years.</summary>
|
||||
private void RenderVertical(DrawingContext dc, IReadOnlyList<ChartItem> items, double max)
|
||||
{
|
||||
var faint = GetBrush("Brush.TextFaint");
|
||||
var sample = CreateText("0", LabelSize, faint);
|
||||
var muted = GetBrush("Brush.TextMuted");
|
||||
var sample = CreateText("0", LabelSize, muted);
|
||||
var labelHeight = Math.Ceiling(sample.Height) + 4;
|
||||
var valueHeight = ShowValues ? labelHeight : 0;
|
||||
var axisWidth = 0.0;
|
||||
if (ShowGrid)
|
||||
{
|
||||
var top = CreateText(Format(max), LabelSize, faint);
|
||||
var top = CreateText(Format(max), LabelSize, muted);
|
||||
axisWidth = Math.Ceiling(top.Width) + 8;
|
||||
}
|
||||
_area = new Rect(axisWidth, valueHeight, Math.Max(0, ActualWidth - axisWidth), Math.Max(0, ActualHeight - labelHeight - valueHeight));
|
||||
@@ -234,7 +246,7 @@ public sealed class BarChart : DrawingElement
|
||||
var value = CreateLabel(item.ValueText ?? Format(item.Value), LabelSize, text);
|
||||
if (value.Width <= _pitch) DrawTextAt(dc, value, new Point(cx - value.Width / 2, _area.Bottom - height - value.Height - 2));
|
||||
}
|
||||
var label = CreateLabel(item.Label, LabelSize, faint);
|
||||
var label = CreateLabel(item.Label, LabelSize, muted);
|
||||
var x = cx - label.Width / 2;
|
||||
if (x < lastLabelRight + 6) continue;
|
||||
DrawTextAt(dc, label, new Point(x, _area.Bottom + 4));
|
||||
@@ -242,21 +254,25 @@ public sealed class BarChart : DrawingElement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Gridlines at nice ticks along the value axis, with labels below (horizontal bars) or left (vertical bars).</summary>
|
||||
/// <summary>
|
||||
/// Gridlines at nice ticks along the value axis, with labels below (horizontal bars, mirrored with them) or left
|
||||
/// (vertical bars).
|
||||
/// </summary>
|
||||
private void DrawValueGrid(DrawingContext dc, double max, bool horizontal)
|
||||
{
|
||||
var ticks = NiceScale.Inner(0, max, horizontal ? Math.Max(2, (int)(_area.Width / 80)) : Math.Max(2, (int)(_area.Height / 36)));
|
||||
var pen = GetHairline("Brush.Stroke");
|
||||
var faint = GetBrush("Brush.TextFaint");
|
||||
var muted = GetBrush("Brush.TextMuted");
|
||||
var scale = PixelScale;
|
||||
var width = ActualWidth;
|
||||
for (var i = 0; i < ticks.Count; i++)
|
||||
{
|
||||
var label = CreateText(Format(ticks[i]), LabelSize, faint);
|
||||
var label = CreateText(Format(ticks[i]), LabelSize, muted);
|
||||
if (horizontal)
|
||||
{
|
||||
var x = PixelGrid.SnapLine(_area.Left + _area.Width * ticks[i] / max, pen.Thickness, scale);
|
||||
var x = PixelGrid.SnapLine(FromStart(_area.Left + _area.Width * ticks[i] / max, 0, width), pen.Thickness, scale);
|
||||
dc.DrawLine(pen, new Point(x, _area.Top), new Point(x, _area.Bottom));
|
||||
dc.DrawText(label, new Point(Math.Min(x - label.Width / 2, ActualWidth - label.Width), _area.Bottom + 2));
|
||||
dc.DrawText(label, new Point(Math.Clamp(x - label.Width / 2, 0, Math.Max(0, width - label.Width)), _area.Bottom + 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -266,15 +282,4 @@ public sealed class BarChart : DrawingElement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int HitTest(Point p)
|
||||
{
|
||||
var count = Items?.Count ?? 0;
|
||||
if (count == 0 || _area.IsEmpty || !(_pitch > 0)) return -1;
|
||||
var index = Orientation == Orientation.Horizontal
|
||||
? (int)Math.Floor((p.Y - _area.Top) / _pitch)
|
||||
: (int)Math.Floor((p.X - _area.Left) / _pitch);
|
||||
var inside = Orientation == Orientation.Horizontal ? p.X >= 0 && p.X <= ActualWidth : p.Y >= 0 && p.Y <= ActualHeight;
|
||||
return inside && index >= 0 && index < count ? index : -1;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Controls;
|
||||
@@ -12,9 +14,17 @@ namespace Titano.Ui.Visuals;
|
||||
/// Base of the retained-mode visuals. Brushes are looked up by theme resource key and re-resolved when the token
|
||||
/// dictionary is swapped (frozen pens are cached per theme); text is laid out with the UI font at the element's
|
||||
/// DPI; an optional overlay layer (playhead, hover) is redrawn without re-rendering the static content drawn in
|
||||
/// <see cref="UIElement.OnRender"/>. Time axes and images never mirror, so the element is always left-to-right;
|
||||
/// words (categories, legends, summaries) still read in the UI language's direction (<see cref="CreateLabel"/>) and
|
||||
/// legends start on its side. Screen readers see a named image (<see cref="DrawingElementAutomationPeer"/>).
|
||||
/// <see cref="UIElement.OnRender"/>. The element itself is always left-to-right, so time axes and images never
|
||||
/// mirror; words (categories, legends, summaries) still read in the UI language's direction
|
||||
/// (<see cref="CreateLabel"/>), legends start on its side, and a category chart places its bars from that side
|
||||
/// (<see cref="FromStart"/>). Screen readers see a named image (<see cref="DrawingElementAutomationPeer"/>).
|
||||
/// <para>
|
||||
/// A chart of discrete items (bars, segments, cells) describes them through <see cref="ItemCount"/>,
|
||||
/// <see cref="ItemAt"/>, <see cref="ItemBounds"/> and <see cref="ItemText"/>: hovering one reads it out and clicking
|
||||
/// it calls <see cref="Activate"/>. Only while a handler of its activation event is attached to the chart
|
||||
/// (<see cref="TrackActivation"/>) does an item show the hand cursor and the chart take the keyboard: the arrows
|
||||
/// choose an item (<see cref="Navigate"/>), Enter or Space activates it.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public abstract class DrawingElement : FrameworkElement
|
||||
{
|
||||
@@ -28,6 +38,8 @@ public abstract class DrawingElement : FrameworkElement
|
||||
private HoverReadout? _readout;
|
||||
private Typeface? _regular;
|
||||
private Typeface? _semiBold;
|
||||
private Delegate? _activationHandlers;
|
||||
private int _keyboardItem = -1;
|
||||
|
||||
/// <param name="hasOverlay">Creates the overlay layer drawn by <see cref="OnRenderOverlay"/>.</param>
|
||||
protected DrawingElement(bool hasOverlay = false)
|
||||
@@ -101,6 +113,51 @@ public abstract class DrawingElement : FrameworkElement
|
||||
/// </summary>
|
||||
protected internal virtual string? AutomationDescription => null;
|
||||
|
||||
/// <summary>The item the keyboard is on, read to screen readers as the image's status; null when none.</summary>
|
||||
internal string? KeyboardItemText => IsActivatable && _keyboardItem >= 0 && _keyboardItem < ItemCount ? ItemText(_keyboardItem) : null;
|
||||
|
||||
/// <summary>Whether a handler of the visual's activation event is attached to the visual itself (not to an ancestor).</summary>
|
||||
protected bool IsActivatable => _activationHandlers is not null;
|
||||
|
||||
/// <summary>Number of discrete items (bars, segments, cells); 0 for visuals without items.</summary>
|
||||
protected virtual int ItemCount => 0;
|
||||
|
||||
/// <summary>Item under <paramref name="point"/>, or −1.</summary>
|
||||
protected virtual int ItemAt(Point point) => -1;
|
||||
|
||||
/// <summary>Where <paramref name="item"/> was last drawn: the keyboard outline follows this rectangle.</summary>
|
||||
protected virtual Rect ItemBounds(int item) => Rect.Empty;
|
||||
|
||||
/// <summary>What the readout says for <paramref name="item"/>.</summary>
|
||||
protected virtual string? ItemText(int item) => null;
|
||||
|
||||
/// <summary>The item an arrow key moves to from <paramref name="item"/>; −1 when the key does not move.</summary>
|
||||
protected virtual int Navigate(int item, Key key) => -1;
|
||||
|
||||
/// <summary>Raises the visual's activation event for <paramref name="item"/>.</summary>
|
||||
protected virtual void Activate(int item)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Records a handler added to or removed from the activation event; call from the event's accessors.</summary>
|
||||
protected void TrackActivation(Delegate handler, bool added)
|
||||
{
|
||||
_activationHandlers = added ? Delegate.Combine(_activationHandlers, handler) : Delegate.Remove(_activationHandlers, handler);
|
||||
SetCurrentValue(FocusableProperty, IsActivatable);
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
/// <summary>The cursor the visual shows at <paramref name="point"/>: the hand over an item something activates, otherwise none of its own.</summary>
|
||||
internal Cursor? CursorAt(Point point) => IsActivatable && ItemAt(point) >= 0 ? Cursors.Hand : null;
|
||||
|
||||
/// <summary>Outlines the keyboard's item while the visual has keyboard focus (DESIGN §4: 2 px Accent); call last in OnRender.</summary>
|
||||
protected void DrawKeyboardItem(DrawingContext dc)
|
||||
{
|
||||
if (!IsKeyboardFocused || !IsActivatable || _keyboardItem < 0 || _keyboardItem >= ItemCount) return;
|
||||
var bounds = ItemBounds(_keyboardItem);
|
||||
if (!bounds.IsEmpty) dc.DrawRoundedRectangle(null, GetPen("Brush.Accent", 2), bounds, 4, 4);
|
||||
}
|
||||
|
||||
/// <summary>Single-line left-to-right text in the UI font (numbers, ticks, times), laid out for this element's DPI and text formatting mode.</summary>
|
||||
protected FormattedText CreateText(string text, double emSize, Brush brush, bool semiBold = false) =>
|
||||
Format(text, emSize, brush, semiBold, FlowDirection.LeftToRight);
|
||||
@@ -142,6 +199,7 @@ public abstract class DrawingElement : FrameworkElement
|
||||
/// <summary>Called when a data property or a watched collection changed; the default re-measures and redraws.</summary>
|
||||
protected virtual void OnDataChanged()
|
||||
{
|
||||
_keyboardItem = Math.Min(_keyboardItem, ItemCount - 1);
|
||||
InvalidateMeasure();
|
||||
InvalidateVisual();
|
||||
}
|
||||
@@ -163,6 +221,90 @@ public abstract class DrawingElement : FrameworkElement
|
||||
OnThemeChanged();
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (ItemCount == 0) return;
|
||||
var p = e.GetPosition(this);
|
||||
var item = ItemAt(p);
|
||||
Readout.Show(item >= 0 ? ItemText(item) : null, p);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
if (ItemCount > 0) Readout.Hide();
|
||||
}
|
||||
|
||||
protected override void OnQueryCursor(QueryCursorEventArgs e)
|
||||
{
|
||||
base.OnQueryCursor(e);
|
||||
if (e.Handled || CursorAt(e.GetPosition(this)) is not { } cursor) return;
|
||||
e.Cursor = cursor;
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
if (e.Handled || ItemCount == 0) return;
|
||||
var item = ItemAt(e.GetPosition(this));
|
||||
if (item < 0) return;
|
||||
_keyboardItem = item;
|
||||
Activate(item);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
var count = ItemCount;
|
||||
if (e.Handled || !IsActivatable || count == 0) return;
|
||||
var current = Math.Clamp(_keyboardItem, 0, count - 1);
|
||||
if (e.Key is Key.Enter or Key.Space)
|
||||
{
|
||||
MoveKeyboardTo(current);
|
||||
Activate(current);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
var next = e.Key switch
|
||||
{
|
||||
Key.Home => 0,
|
||||
Key.End => count - 1,
|
||||
_ => Navigate(current, e.Key),
|
||||
};
|
||||
if (next < 0) return;
|
||||
MoveKeyboardTo(Math.Min(next, count - 1));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
|
||||
{
|
||||
base.OnGotKeyboardFocus(e);
|
||||
if (IsActivatable && ItemCount > 0 && ReferenceEquals(e.NewFocus, this)) MoveKeyboardTo(Math.Clamp(_keyboardItem, 0, ItemCount - 1));
|
||||
}
|
||||
|
||||
protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
|
||||
{
|
||||
base.OnLostKeyboardFocus(e);
|
||||
if (!IsActivatable) return;
|
||||
Readout.Hide();
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
/// <summary>Puts the keyboard on <paramref name="item"/>: outlined, read out next to it and announced as the image's status.</summary>
|
||||
private void MoveKeyboardTo(int item)
|
||||
{
|
||||
var before = KeyboardItemText;
|
||||
_keyboardItem = item;
|
||||
InvalidateVisual();
|
||||
var bounds = ItemBounds(item);
|
||||
if (!bounds.IsEmpty) Readout.Show(ItemText(item), bounds.BottomLeft);
|
||||
UIElementAutomationPeer.FromElement(this)?.RaisePropertyChangedEvent(AutomationElementIdentifiers.ItemStatusProperty, before ?? string.Empty,
|
||||
KeyboardItemText ?? string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>Fills the whole element with a transparent brush so empty areas still receive the mouse.</summary>
|
||||
protected void DrawHitArea(DrawingContext dc) => dc.DrawRectangle(Brushes.Transparent, null, new Rect(RenderSize));
|
||||
|
||||
@@ -281,4 +423,11 @@ public class DrawingElementAutomationPeer(DrawingElement owner) : FrameworkEleme
|
||||
var name = base.GetNameCore();
|
||||
return string.IsNullOrEmpty(name) ? ((DrawingElement)Owner).AutomationDescription ?? string.Empty : name;
|
||||
}
|
||||
|
||||
/// <summary>The item the keyboard is on, unless AutomationProperties.ItemStatus says otherwise.</summary>
|
||||
protected override string GetItemStatusCore()
|
||||
{
|
||||
var status = base.GetItemStatusCore();
|
||||
return string.IsNullOrEmpty(status) ? ((DrawingElement)Owner).KeyboardItemText ?? string.Empty : status;
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,11 @@ namespace Titano.Ui.Visuals;
|
||||
|
||||
/// <summary>
|
||||
/// Density grid (Archive: photos per month, one row per year × 12 months). Each value is a square cell in the
|
||||
/// brush colour whose opacity grows with the value; NaN cells ("no data", e.g. future months) use the card fill.
|
||||
/// Column labels sit above, row labels on the left, an optional min–max scale below. Hovering reads out the cell
|
||||
/// (its tooltip or "row column · value"); clicking raises <see cref="CellActivatedEvent"/>.
|
||||
/// brush colour whose opacity grows with the value; NaN cells ("no data", e.g. future months) take the stroke tone,
|
||||
/// which differs from the card and panel fills in both themes. Column labels sit above, row labels on the left, an
|
||||
/// optional min–max scale below; months run left to right in every language. Hovering reads out the cell (its
|
||||
/// tooltip or "row column · value"); clicking raises <see cref="CellActivatedEvent"/>, and a handler attached to the
|
||||
/// grid also gives it the hand cursor and the keyboard.
|
||||
/// </summary>
|
||||
public sealed class HeatmapStrip : DrawingElement
|
||||
{
|
||||
@@ -49,7 +51,6 @@ public sealed class HeatmapStrip : DrawingElement
|
||||
private const double LabelSize = 11;
|
||||
|
||||
private CellGridLayout _grid;
|
||||
private bool _hovering;
|
||||
|
||||
/// <summary>One row per year (label + 12 monthly values).</summary>
|
||||
public IReadOnlyList<ChartRow>? Rows { get => (IReadOnlyList<ChartRow>?)GetValue(RowsProperty); set => SetValue(RowsProperty, value); }
|
||||
@@ -75,10 +76,19 @@ public sealed class HeatmapStrip : DrawingElement
|
||||
/// <summary>Culture-aware value formatting (scale ends and readouts).</summary>
|
||||
public Func<double, string>? ValueFormatter { get => (Func<double, string>?)GetValue(ValueFormatterProperty); set => SetValue(ValueFormatterProperty, value); }
|
||||
|
||||
/// <summary>Raised when a cell is clicked, or chosen with the keyboard and Enter; attach it to the grid itself to make the cells interactive.</summary>
|
||||
public event ChartItemEventHandler CellActivated
|
||||
{
|
||||
add => AddHandler(CellActivatedEvent, value);
|
||||
remove => RemoveHandler(CellActivatedEvent, value);
|
||||
add
|
||||
{
|
||||
AddHandler(CellActivatedEvent, value);
|
||||
TrackActivation(value, added: true);
|
||||
}
|
||||
remove
|
||||
{
|
||||
RemoveHandler(CellActivatedEvent, value);
|
||||
TrackActivation(value, added: false);
|
||||
}
|
||||
}
|
||||
|
||||
private int RowCount => Rows?.Count ?? 0;
|
||||
@@ -95,6 +105,9 @@ public sealed class HeatmapStrip : DrawingElement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Cells in reading order: row by row, <see cref="ColumnCount"/> per row.</summary>
|
||||
protected override int ItemCount => RowCount * ColumnCount;
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
if (RowCount == 0 || ColumnCount == 0) return new Size(0, 0);
|
||||
@@ -107,26 +120,26 @@ public sealed class HeatmapStrip : DrawingElement
|
||||
DrawHitArea(dc);
|
||||
if (Rows is not { Count: > 0 } rows || ColumnCount == 0) return;
|
||||
_grid = Layout(ActualWidth, ActualHeight - ScaleHeight());
|
||||
var faint = GetBrush("Brush.TextFaint");
|
||||
var muted = GetBrush("Brush.TextMuted");
|
||||
var max = ScaleMaximum(rows);
|
||||
|
||||
if (ColumnLabels is { } columns)
|
||||
{
|
||||
for (var c = 0; c < columns.Count; c++)
|
||||
{
|
||||
var label = CreateLabel(columns[c], LabelSize, faint);
|
||||
var label = CreateLabel(columns[c], LabelSize, muted);
|
||||
var (x, _) = _grid.CellOrigin(0, c);
|
||||
DrawTextAt(dc, label, new Point(x + (_grid.CellSize - label.Width) / 2, 0));
|
||||
}
|
||||
}
|
||||
|
||||
var fill = GetBrush(BrushKey);
|
||||
var empty = GetBrush("Brush.Card");
|
||||
var empty = GetBrush("Brush.Stroke");
|
||||
var radius = Math.Min(2, _grid.CellSize / 4);
|
||||
for (var r = 0; r < rows.Count; r++)
|
||||
{
|
||||
var row = rows[r];
|
||||
var label = CreateLabel(row.Label, LabelSize, faint);
|
||||
var label = CreateLabel(row.Label, LabelSize, muted);
|
||||
var (_, y) = _grid.CellOrigin(r, 0);
|
||||
DrawTextAt(dc, label, new Point(_grid.Left - 8 - label.Width, y + (_grid.CellSize - label.Height) / 2));
|
||||
for (var c = 0; c < _grid.Columns; c++)
|
||||
@@ -145,39 +158,39 @@ public sealed class HeatmapStrip : DrawingElement
|
||||
}
|
||||
}
|
||||
if (ShowScale) DrawScale(dc, fill, max);
|
||||
DrawKeyboardItem(dc);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
protected override int ItemAt(Point point) =>
|
||||
_grid.TryHit(point.X, point.Y, out var row, out var column) && row < RowCount && column < ColumnCount ? row * ColumnCount + column : -1;
|
||||
|
||||
protected override Rect ItemBounds(int item)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
var p = e.GetPosition(this);
|
||||
_hovering = _grid.TryHit(p.X, p.Y, out var row, out var column) && row < RowCount;
|
||||
Readout.Show(_hovering ? ReadoutText(row, column) : null, p);
|
||||
if (_grid.CellSize <= 0 || ColumnCount == 0) return Rect.Empty;
|
||||
var (x, y) = _grid.CellOrigin(item / ColumnCount, item % ColumnCount);
|
||||
var cell = new Rect(x, y, _grid.CellSize, _grid.CellSize);
|
||||
cell.Inflate(2, 2);
|
||||
return cell;
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(MouseEventArgs e)
|
||||
protected override string? ItemText(int item) => ColumnCount == 0 ? null : ReadoutText(item / ColumnCount, item % ColumnCount);
|
||||
|
||||
/// <summary>Left/Right move along a year (months left to right in every language), Up/Down between years.</summary>
|
||||
protected override int Navigate(int item, Key key)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_hovering = false;
|
||||
Readout.Hide();
|
||||
var columns = ColumnCount;
|
||||
var (row, column) = (item / columns, item % columns);
|
||||
return key switch
|
||||
{
|
||||
Key.Left => row * columns + Math.Max(0, column - 1),
|
||||
Key.Right => row * columns + Math.Min(columns - 1, column + 1),
|
||||
Key.Up => Math.Max(0, row - 1) * columns + column,
|
||||
Key.Down => Math.Min(RowCount - 1, row + 1) * columns + column,
|
||||
_ => -1,
|
||||
};
|
||||
}
|
||||
|
||||
protected override void OnQueryCursor(QueryCursorEventArgs e)
|
||||
{
|
||||
base.OnQueryCursor(e);
|
||||
if (e.Handled || !_hovering) return;
|
||||
e.Cursor = Cursors.Hand;
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
var p = e.GetPosition(this);
|
||||
if (!_grid.TryHit(p.X, p.Y, out var row, out var column) || row >= RowCount) return;
|
||||
RaiseEvent(new ChartItemEventArgs(CellActivatedEvent, row, column));
|
||||
e.Handled = true;
|
||||
}
|
||||
protected override void Activate(int item) => RaiseEvent(new ChartItemEventArgs(CellActivatedEvent, item / ColumnCount, item % ColumnCount));
|
||||
|
||||
private string Format(double value) => (ValueFormatter ?? DefaultFormat)(value);
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ public sealed class SeriesChart : DrawingElement
|
||||
var labelWidth = 0.0;
|
||||
if (ShowYLabels)
|
||||
{
|
||||
var labelBrush = GetBrush("Brush.TextFaint");
|
||||
var labelBrush = GetBrush("Brush.TextMuted");
|
||||
for (var i = 0; i < ticks.Count; i++)
|
||||
{
|
||||
labels[i] = CreateText(format(ticks[i]), LabelSize, labelBrush);
|
||||
@@ -328,7 +328,7 @@ public sealed class SeriesChart : DrawingElement
|
||||
{
|
||||
if (_count < 2) return;
|
||||
var ticks = NiceScale.Inner(0, _count - 1, Math.Max(2, (int)(_plot.Width / 90)));
|
||||
var brush = GetBrush("Brush.TextFaint");
|
||||
var brush = GetBrush("Brush.TextMuted");
|
||||
var lastRight = double.NegativeInfinity;
|
||||
for (var i = 0; i < ticks.Count; i++)
|
||||
{
|
||||
|
||||
@@ -8,8 +8,9 @@ namespace Titano.Ui.Visuals;
|
||||
/// <summary>
|
||||
/// One bar split into proportional segments (by camera, by format) with a wrapping legend underneath
|
||||
/// ("■ label share"). Segments share one theme colour and fade by rank (items may set their own brush), so no new
|
||||
/// colours are introduced; 2-px gaps separate them. Hovering a segment or legend entry reads it out; clicking
|
||||
/// raises <see cref="ItemActivatedEvent"/>.
|
||||
/// colours are introduced; 2-px gaps separate them. The first segment and the legend start on the reading side, so
|
||||
/// both mirror in a right-to-left language. Hovering a segment or legend entry reads it out; clicking raises
|
||||
/// <see cref="ItemActivatedEvent"/>, and a handler attached to the bar also gives it the hand cursor and the keyboard.
|
||||
/// </summary>
|
||||
public sealed class StackedBar : DrawingElement
|
||||
{
|
||||
@@ -42,7 +43,6 @@ public sealed class StackedBar : DrawingElement
|
||||
|
||||
private readonly List<Rect> _segments = [];
|
||||
private readonly List<Rect> _entries = [];
|
||||
private int _hover = -1;
|
||||
|
||||
/// <summary>Parts in display order (largest first reads best).</summary>
|
||||
public IReadOnlyList<ChartItem>? Items { get => (IReadOnlyList<ChartItem>?)GetValue(ItemsProperty); set => SetValue(ItemsProperty, value); }
|
||||
@@ -56,15 +56,26 @@ public sealed class StackedBar : DrawingElement
|
||||
/// <summary>Formats a share 0…1 for the legend (default: culture percent without decimals).</summary>
|
||||
public Func<double, string>? ShareFormatter { get => (Func<double, string>?)GetValue(ShareFormatterProperty); set => SetValue(ShareFormatterProperty, value); }
|
||||
|
||||
/// <summary>Raised when a segment or its legend entry is clicked, or chosen with the keyboard and Enter; attach it to the bar itself to make it interactive.</summary>
|
||||
public event ChartItemEventHandler ItemActivated
|
||||
{
|
||||
add => AddHandler(ItemActivatedEvent, value);
|
||||
remove => RemoveHandler(ItemActivatedEvent, value);
|
||||
add
|
||||
{
|
||||
AddHandler(ItemActivatedEvent, value);
|
||||
TrackActivation(value, added: true);
|
||||
}
|
||||
remove
|
||||
{
|
||||
RemoveHandler(ItemActivatedEvent, value);
|
||||
TrackActivation(value, added: false);
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override string? AutomationDescription =>
|
||||
Items is { Count: > 0 } items ? string.Join(Environment.NewLine, Enumerable.Range(0, items.Count).Select(ReadoutText)) : null;
|
||||
|
||||
protected override int ItemCount => Items?.Count ?? 0;
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
if (Items is not { Count: > 0 } items) return new Size(0, 0);
|
||||
@@ -72,12 +83,6 @@ public sealed class StackedBar : DrawingElement
|
||||
return new Size(0, BarHeight + (lines > 0 ? LegendGap + lines * LegendLine : 0));
|
||||
}
|
||||
|
||||
protected override void OnDataChanged()
|
||||
{
|
||||
_hover = -1;
|
||||
base.OnDataChanged();
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc)
|
||||
{
|
||||
DrawHitArea(dc);
|
||||
@@ -94,48 +99,48 @@ public sealed class StackedBar : DrawingElement
|
||||
for (var i = 0; i < items.Count; i++)
|
||||
{
|
||||
var share = total > 0 ? Math.Max(0, items[i].Value) / total : 0;
|
||||
var segment = new Rect(x, 0, available * share, BarHeight);
|
||||
var segmentWidth = available * share;
|
||||
var segment = new Rect(FromStart(x, segmentWidth, width), 0, segmentWidth, BarHeight);
|
||||
_segments.Add(segment);
|
||||
dc.PushOpacity(OpacityOf(i, items));
|
||||
dc.DrawRectangle(GetBrush(items[i].BrushKey ?? BrushKey), null, segment);
|
||||
dc.Pop();
|
||||
x = segment.Right + SegmentGap;
|
||||
x += segmentWidth + SegmentGap;
|
||||
}
|
||||
dc.Pop();
|
||||
if (ShowLegend) LayoutLegend(items, width, dc);
|
||||
DrawKeyboardItem(dc);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
/// <summary>A segment, or its legend entry; a click in the gap between two segments counts for the nearer one.</summary>
|
||||
protected override int ItemAt(Point point)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
var p = e.GetPosition(this);
|
||||
_hover = HitTest(p);
|
||||
Readout.Show(_hover >= 0 ? ReadoutText(_hover) : null, p);
|
||||
for (var i = 0; i < _segments.Count; i++)
|
||||
if (point.Y >= 0 && point.Y <= BarHeight && point.X >= _segments[i].Left - SegmentGap / 2 && point.X <= _segments[i].Right + SegmentGap / 2) return i;
|
||||
for (var i = 0; i < _entries.Count; i++)
|
||||
if (_entries[i].Contains(point)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(MouseEventArgs e)
|
||||
protected override Rect ItemBounds(int item)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
_hover = -1;
|
||||
Readout.Hide();
|
||||
if (item >= _segments.Count) return Rect.Empty;
|
||||
var segment = _segments[item];
|
||||
segment.Inflate(2, 2);
|
||||
return segment;
|
||||
}
|
||||
|
||||
protected override void OnQueryCursor(QueryCursorEventArgs e)
|
||||
{
|
||||
base.OnQueryCursor(e);
|
||||
if (e.Handled || _hover < 0) return;
|
||||
e.Cursor = Cursors.Hand;
|
||||
e.Handled = true;
|
||||
}
|
||||
protected override string? ItemText(int item) => Items is { } items && item < items.Count ? ReadoutText(item) : null;
|
||||
|
||||
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
/// <summary>Left and Right move to the segment drawn on that side (the bar mirrors in a right-to-left language).</summary>
|
||||
protected override int Navigate(int item, Key key) => key switch
|
||||
{
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
var index = HitTest(e.GetPosition(this));
|
||||
if (index < 0) return;
|
||||
RaiseEvent(new ChartItemEventArgs(ItemActivatedEvent, index, -1));
|
||||
e.Handled = true;
|
||||
}
|
||||
Key.Left => Loc.IsRightToLeft ? item + 1 : Math.Max(0, item - 1),
|
||||
Key.Right => Loc.IsRightToLeft ? Math.Max(0, item - 1) : item + 1,
|
||||
_ => -1,
|
||||
};
|
||||
|
||||
protected override void Activate(int item) => RaiseEvent(new ChartItemEventArgs(ItemActivatedEvent, item, -1));
|
||||
|
||||
private static double Total(IReadOnlyList<ChartItem> items)
|
||||
{
|
||||
@@ -188,15 +193,6 @@ public sealed class StackedBar : DrawingElement
|
||||
return line + 1;
|
||||
}
|
||||
|
||||
private int HitTest(Point p)
|
||||
{
|
||||
for (var i = 0; i < _segments.Count; i++)
|
||||
if (p.Y >= 0 && p.Y <= BarHeight && p.X >= _segments[i].Left && p.X <= _segments[i].Right + SegmentGap) return i;
|
||||
for (var i = 0; i < _entries.Count; i++)
|
||||
if (_entries[i].Contains(p)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private string ReadoutText(int index)
|
||||
{
|
||||
var items = Items!;
|
||||
|
||||
@@ -107,10 +107,10 @@ public sealed class TimelineBands : DrawingElement
|
||||
if (max <= 0) max = 1;
|
||||
|
||||
var text = GetBrush("Brush.Text");
|
||||
var faint = GetBrush("Brush.TextFaint");
|
||||
var muted = GetBrush("Brush.TextMuted");
|
||||
var fill = GetBrush(BrushKey);
|
||||
var divider = GetHairline("Brush.Stroke");
|
||||
var captionHeight = Math.Ceiling(CreateText("0", LabelSize, faint).Height);
|
||||
var captionHeight = Math.Ceiling(CreateText("0", LabelSize, muted).Height);
|
||||
var barWidth = Math.Max(1, Math.Min(pitch * 0.6, 28));
|
||||
|
||||
for (var b = 0; b < bands.Count; b++)
|
||||
@@ -132,7 +132,7 @@ public sealed class TimelineBands : DrawingElement
|
||||
}
|
||||
if (SlotLabels is { } labels && s < labels.Count)
|
||||
{
|
||||
var caption = CreateLabel(labels[s], LabelSize, faint);
|
||||
var caption = CreateLabel(labels[s], LabelSize, muted);
|
||||
DrawTextAt(dc, caption, new Point(cx - caption.Width / 2, baseline + 4));
|
||||
}
|
||||
if (b == CurrentBand && s == CurrentSlot)
|
||||
|
||||
Reference in new issue
Block a user