using Avalonia.Controls; using Avalonia.Layout; using Avalonia.Media; using Nonemm.Session; namespace Nonemm.App.Windows; /// What the callsign being typed could be, a column per source. The columns /// stay apart because they answer different questions, and merged into one list /// they would all read as equally reliable. public sealed partial class CheckWindow : RefreshableWindow { private readonly AppSession session; private readonly Func typed; public CheckWindow(AppSession session, Func typed) { this.session = session; this.typed = typed; InitializeComponent(); Refresh(); } public override void Refresh() { Columns.Children.Clear(); if (session.Check is null) { return; } int at = 0; foreach (CheckColumn column in session.Check.Columns(typed())) { Control panel = BuildColumn(column); Grid.SetColumn(panel, at++); Columns.Children.Add(panel); } } private static Control BuildColumn(CheckColumn column) { StackPanel panel = new() { Margin = new Avalonia.Thickness(0, 0, 8, 0) }; panel.Children.Add(new TextBlock { Text = $"{Heading(column.Source)} {Count(column)}", FontSize = 11, Opacity = 0.7, Margin = new Avalonia.Thickness(0, 0, 0, 4), }); foreach (CheckCandidate candidate in column.Candidates) { panel.Children.Add(new TextBlock { Text = candidate.Call, FontFamily = new FontFamily("monospace"), FontSize = 14, Foreground = Verdicts.Colour(candidate.Verdict), HorizontalAlignment = HorizontalAlignment.Left, }); } return new ScrollViewer { Content = panel }; } /// Before anything is typed the heading says how many calls the source /// holds; once it is offering candidates it says how many. private static string Count(CheckColumn column) => column.Candidates.Count > 0 ? column.Candidates.Count.ToString() : $"({column.Held})"; private static string Heading(CheckSource source) => source switch { CheckSource.Log => "Log", CheckSource.Database => "Master", _ => "Bandmap", }; }