app: redesign the stats panel and settings (D8)
agent-review agent review: pass

The panel is now a dashboard: a one-row header with range and provider
controls, a tile per limit window with pace, forecasts, today's share
of the week and the daily budget, per-day week charts with even-pace and
budget lines, token stat tiles with one composition legend, hourly and
daily charts side by side, limit history, and top-8 breakdowns. Colours
follow fixed provider and status tokens instead of the OS accent;
numbers are compact to three significant digits. Settings are grouped
into cards with a sticky footer. Developer feedback on v1.

Refs #5
This commit is contained in:
Florian Schmidt
2026-10-14 22:59:24 +02:00
parent a20d0ab9dc
commit 73f79eb6ac
11 changed files with 1013 additions and 226 deletions
+131
View File
@@ -0,0 +1,131 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Templates;
using Avalonia.Markup.Xaml.MarkupExtensions;
using Avalonia.Themes.Fluent;
using FinalToken.Core;
namespace FinalToken.App;
public static class Ui
{
public static IBrush Colour(string role, bool dark) => Brush.Parse(role switch
{
"Page" => dark ? "#0d0d0d" : "#f9f9f7",
"Surface" => dark ? "#1a1a19" : "#fcfcfb",
"Border" => dark ? "#1affffff" : "#1a0b0b0b",
"Ink" => dark ? "#f0efec" : "#0b0b0b",
"Secondary" => dark ? "#c3c2b7" : "#52514e",
"Grid" => dark ? "#2c2c2a" : "#e1e0d9",
"Axis" => dark ? "#383835" : "#c3c2b7",
"Selection" => dark ? "#383835" : "#e1e0d9",
"Claude" => dark ? "#d95926" : "#eb6834",
"Codex" => dark ? "#3987e5" : "#2a78d6",
"Cache" => dark ? "#5c5b57" : "#c3c2b7",
_ => "#898781"
});
public static bool Dark(StyledElement element) => element.ActualThemeVariant == ThemeVariant.Dark;
public static IBrush ProviderColour(Provider provider, bool dark) => Colour(provider.ToString(), dark);
public static void Theme(Window window)
{
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
{
var resources = new ResourceDictionary();
foreach (var role in new[] { "Page", "Surface", "Border", "Ink", "Secondary", "Muted", "Grid", "Axis", "Selection", "Claude", "Codex", "Cache" })
resources[role] = Colour(role, theme == ThemeVariant.Dark);
window.Resources.ThemeDictionaries[theme] = resources;
}
window.Bind(TemplatedControl.BackgroundProperty, window.GetResourceObservable("Page"));
window.Bind(TemplatedControl.ForegroundProperty, window.GetResourceObservable("Ink"));
window.FontSize = 13;
var segments = new Style(s => s.OfType<ToggleButton>().Class("segment"));
segments.Setters.Add(new Setter(TemplatedControl.BackgroundProperty, new DynamicResourceExtension("Surface")));
segments.Setters.Add(new Setter(TemplatedControl.ForegroundProperty, new DynamicResourceExtension("Ink")));
segments.Setters.Add(new Setter(TemplatedControl.TemplateProperty, new FuncControlTemplate<ToggleButton>((button, _) =>
{
var presenter = new ContentPresenter { HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center };
presenter.Bind(ContentPresenter.ContentProperty, button.GetObservable(ContentControl.ContentProperty));
presenter.Bind(ContentPresenter.ForegroundProperty, button.GetObservable(TemplatedControl.ForegroundProperty));
presenter.Bind(ContentPresenter.FontWeightProperty, button.GetObservable(TemplatedControl.FontWeightProperty));
var border = new Border { Child = presenter, Padding = new Thickness(8, 6), CornerRadius = new CornerRadius(4) };
border.Bind(Border.BackgroundProperty, button.GetObservable(TemplatedControl.BackgroundProperty));
return border;
})));
window.Styles.Add(segments);
var selected = new Style(s => s.OfType<ToggleButton>().Class("segment").Class(":checked"));
selected.Setters.Add(new Setter(TemplatedControl.BackgroundProperty, new DynamicResourceExtension("Selection")));
selected.Setters.Add(new Setter(TemplatedControl.FontWeightProperty, FontWeight.SemiBold)); window.Styles.Add(selected);
var checks = new Style(s => s.OfType<CheckBox>());
checks.Setters.Add(new Setter(TemplatedControl.TemplateProperty, new FuncControlTemplate<CheckBox>((check, _) =>
{
var glyph = Text("✓", 14); glyph.Name = "NeutralCheckGlyph"; glyph.HorizontalAlignment = HorizontalAlignment.Center;
var box = new Border { Name = "NeutralCheckSurface", Child = glyph, Width = 20, Height = 20, CornerRadius = new CornerRadius(4),
BorderThickness = new Thickness(1), VerticalAlignment = VerticalAlignment.Center };
box.Bind(Border.BackgroundProperty, box.GetResourceObservable("Selection")); box.Bind(Border.BorderBrushProperty, box.GetResourceObservable("Axis"));
glyph.IsVisible = check.IsChecked == true; check.IsCheckedChanged += (_, _) => glyph.IsVisible = check.IsChecked == true;
var label = new ContentPresenter { Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center };
label.Bind(ContentPresenter.ContentProperty, check.GetObservable(ContentControl.ContentProperty));
label.Bind(ContentPresenter.ForegroundProperty, label.GetResourceObservable("Ink"));
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("20,*"), MinHeight = 32 };
grid.Children.Add(box); Grid.SetColumn(label, 1); grid.Children.Add(label); return grid;
})));
window.Styles.Add(checks);
}
// Explicit palettes keep every remaining Fluent control independent of the OS accent.
public static FluentTheme NeutralTheme()
{
var theme = new FluentTheme();
theme.Palettes[ThemeVariant.Dark] = new ColorPaletteResources { Accent = Color.Parse("#383835") };
theme.Palettes[ThemeVariant.Light] = new ColorPaletteResources { Accent = Color.Parse("#e1e0d9") };
return theme;
}
public static TextBlock Text(string text, double size = 13, string role = "Ink")
{
var block = new TextBlock { Text = text, FontSize = size, TextWrapping = TextWrapping.Wrap };
block.Bind(TextBlock.ForegroundProperty, block.GetResourceObservable(role));
return block;
}
public static TextBlock Mark(string text, IBrush colour, double size = 12) => new() { Text = text, FontSize = size, Foreground = colour };
public static TextBlock TableNumber(string text, double size = 13, string role = "Ink")
{
var block = Text(text, size, role); block.FontFeatures = FontFeatureCollection.Parse("tnum"); return block;
}
public static StackPanel Stack(params Control[] children)
{
var stack = new StackPanel { Spacing = 8 };
foreach (var child in children) stack.Children.Add(child);
return stack;
}
public static Border Card(Control content)
{
var card = new Border { Child = content, Padding = new Thickness(16), CornerRadius = new CornerRadius(10), BorderThickness = new Thickness(1) };
card.Bind(Border.BackgroundProperty, card.GetResourceObservable("Surface"));
card.Bind(Border.BorderBrushProperty, card.GetResourceObservable("Border"));
return card;
}
public static Button Button(string text, Action action)
{
var button = new Button { Content = text, Padding = new Thickness(12, 6) };
button.Click += (_, _) => action();
return button;
}
public static Control Columns(IEnumerable<Control> children, bool wide) => Columns(children, wide ? 2 : 1);
public static Control Columns(IEnumerable<Control> children, int columns)
{
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions(string.Join(',', Enumerable.Repeat("*", columns))), ColumnSpacing = 16, RowSpacing = 16 };
var index = 0;
foreach (var child in children)
{
child.VerticalAlignment = VerticalAlignment.Top;
if (index % columns == 0) grid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
Grid.SetColumn(child, index % columns); Grid.SetRow(child, index / columns);
grid.Children.Add(child); index++;
}
return grid;
}
}