知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
chore(windows): restyle the app on the Mac's design instead of Windows 11 patterns
wqugurua0e054ff9681
diff --git a/windows/src/Cicada/Dialogs.cs b/windows/src/Cicada/Dialogs.csindex cde48e0..3e4c352 100644--- a/windows/src/Cicada/Dialogs.cs+++ b/windows/src/Cicada/Dialogs.cs@@ -23,9 +23,9 @@ static class Dialogs/// A one-line answer: the new text (maybe empty), or null when cancelled.public static string? Prompt(Window owner, string title, string value, string? hint, string ok){- var box = new TextBox { Text = value, FontSize = 14, MinHeight = 32, VerticalContentAlignment = VerticalAlignment.Center };+ var box = new TextBox { Text = value };System.Windows.Automation.AutomationProperties.SetName(box, title);- var content = new StackPanel { Children = { box } };+ var content = new StackPanel { Children = { Ui.Field(box) } };if (hint is not null) { var h = Ui.Helper(hint); h.Margin = new Thickness(0, 8, 0, 0); content.Children.Add(h); }return Show(owner, title, content, ok, danger: false, box);}@@ -47,21 +47,21 @@ static class Dialogsbuttons.ColumnDefinitions.Add(new ColumnDefinition());buttons.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(8) });buttons.ColumnDefinitions.Add(new ColumnDefinition());- Grid.SetColumn(cancel, 2);+ Grid.SetColumn(primary, 2);buttons.Children.Add(primary);- if (single) { primary.IsCancel = true; Grid.SetColumnSpan(primary, 3); } else buttons.Children.Add(cancel);- var heading = Ui.Text(title, 20, Palette.Ink, FontWeights.SemiBold);+ if (single) { primary.IsCancel = true; Grid.SetColumn(primary, 0); Grid.SetColumnSpan(primary, 3); } else buttons.Children.Add(cancel);+ var heading = Ui.Text(title, 20, Palette.Ink, FontWeights.Bold);content.Margin = new Thickness(0, 12, 0, 0);dialog.Content = new Border{- Margin = new Thickness(16), Background = Palette.Surface, BorderBrush = Palette.ControlStroke, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(8),+ Margin = new Thickness(16), Background = Palette.Surface, BorderBrush = Palette.Line, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(16),Effect = new System.Windows.Media.Effects.DropShadowEffect { BlurRadius = 32, ShadowDepth = 8, Opacity = 0.25 },Child = new StackPanel{Children ={new Border { Padding = new Thickness(24, 24, 24, 24), Child = new StackPanel { Children = { heading, content } } },- new Border { Background = Palette.Mica, BorderBrush = Palette.Stroke, BorderThickness = new Thickness(0, 1, 0, 0), CornerRadius = new CornerRadius(0, 0, 8, 8), Padding = new Thickness(24, 20, 24, 20), Child = buttons },+ new Border { Padding = new Thickness(24, 0, 24, 24), Child = buttons },},},};diff --git a/windows/src/Cicada/MainWindow.cs b/windows/src/Cicada/MainWindow.csindex 12409bf..45bd300 100644--- a/windows/src/Cicada/MainWindow.cs+++ b/windows/src/Cicada/MainWindow.cs@@ -33,7 +33,7 @@ static class Recordssealed class MainWindow : Window{readonly Controller app;- readonly TextBox search = new() { FontSize = 14, MinHeight = 34, VerticalContentAlignment = VerticalAlignment.Center, Padding = new Thickness(30, 0, 8, 0) };+ readonly TextBox search = new();readonly StackPanel list = new();readonly ContentControl detail = new();string? selected;@@ -48,7 +48,8 @@ sealed class MainWindow : Windowselected = select;Title = L("会议记录") + " · " + L("知了");Width = 1200; Height = Math.Min(780, SystemParameters.WorkArea.Height - 24); MinWidth = 960; MinHeight = 520;- Background = Palette.Mica; FontFamily = Palette.Font; Icon = AppIcon.Image;+ // One white sheet, as the Mac's main window: no cards, no second layer.+ Background = Palette.Surface; FontFamily = Palette.Font; Icon = AppIcon.Image;WindowStartupLocation = WindowStartupLocation.CenterScreen;var grid = new Grid();@@ -62,7 +63,14 @@ sealed class MainWindow : Windowglass.HorizontalAlignment = HorizontalAlignment.Left; glass.Margin = new Thickness(10, 0, 0, 0); glass.IsHitTestVisible = false;System.Windows.Automation.AutomationProperties.SetName(search, L("搜索标题、纪要和原话"));search.TextChanged += (_, _) => { placeholder.Visibility = search.Text.Length == 0 ? Visibility.Visible : Visibility.Collapsed; Fill(); };- var searchBox = new Grid { Margin = new Thickness(12, 8, 12, 8), Children = { search, glass, placeholder } };+ Ui.StyleField(search);+ search.Margin = new Thickness(22, 0, 0, 0);+ placeholder.Margin = new Thickness(22, 0, 0, 0);+ glass.Margin = new Thickness(0);+ var inside = new Grid { Children = { glass, search, placeholder } };+ var searchBox = Ui.FieldFrame(inside, search);+ searchBox.Background = Palette.Mica; searchBox.BorderThickness = new Thickness(0); searchBox.Height = 36;+ searchBox.Margin = new Thickness(16, 16, 16, 10);var left = new DockPanel();DockPanel.SetDock(searchBox, Dock.Top);@@ -71,8 +79,7 @@ sealed class MainWindow : Windowvar right = new Border{- Background = Palette.Surface, BorderBrush = Palette.Stroke, BorderThickness = new Thickness(1, 1, 0, 0),- CornerRadius = new CornerRadius(8, 0, 0, 0), Child = detail,+ Background = Palette.Surface, BorderBrush = Palette.Line, BorderThickness = new Thickness(1, 0, 0, 0), Child = detail,};Grid.SetColumn(right, 1);grid.Children.Add(left); grid.Children.Add(right);@@ -143,8 +150,8 @@ sealed class MainWindow : Windowvoid Paint(Button b){var on = (string)b.Tag == selected;- b.Background = on ? Palette.Surface : Brushes.Transparent;- b.Effect = on ? new System.Windows.Media.Effects.DropShadowEffect { BlurRadius = 3, ShadowDepth = 1, Opacity = 0.08 } : null;+ // The Mac's list: the chosen meeting on the ground's grey, no shadow.+ b.Background = on ? Palette.Mica : Brushes.Transparent;}/// A list row: white and raised when chosen, a grey wash under the mouse otherwise.@@ -152,7 +159,7 @@ sealed class MainWindow : Window{var t = new ControlTemplate(typeof(Button));var border = new FrameworkElementFactory(typeof(Border), "bg");- border.SetValue(Border.CornerRadiusProperty, new CornerRadius(6));+ border.SetValue(Border.CornerRadiusProperty, new CornerRadius(10));border.SetBinding(Border.BackgroundProperty, new System.Windows.Data.Binding("Background") { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent });border.SetBinding(Border.PaddingProperty, new System.Windows.Data.Binding("Padding") { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent });border.AppendChild(new FrameworkElementFactory(typeof(ContentPresenter)));@@ -160,7 +167,7 @@ sealed class MainWindow : Windowvar hover = new MultiTrigger();hover.Conditions.Add(new Condition(UIElement.IsMouseOverProperty, true));hover.Conditions.Add(new Condition(Control.BackgroundProperty, Brushes.Transparent));- hover.Setters.Add(new Setter(Border.BackgroundProperty, Palette.Selected, "bg"));+ hover.Setters.Add(new Setter(Border.BackgroundProperty, Palette.Page, "bg"));t.Triggers.Add(hover);return t;}@@ -185,7 +192,7 @@ sealed class MainWindow : Windowvar live = app.Listen.Listening && app.Listen.SessionId == s.Id;var top = new StackPanel { Margin = new Thickness(32, 24, 32, 0) };- var title = Ui.Text(SessionStore.DisplayTitle(s), 26, Palette.Ink, FontWeights.SemiBold);+ var title = Ui.Text(SessionStore.DisplayTitle(s), 26, Palette.Ink, FontWeights.Bold);top.Children.Add(Ui.Row(6, title, Ui.IconButton(Icons.Pencil, L("重命名"), () => Rename(s), Palette.Secondary, 32, 16)));var spoken = s.Lines.Select(l => l.SrcLang).FirstOrDefault(x => x is not null);var into = s.Lines.Select(l => l.DstLang).FirstOrDefault(x => x is not null);@@ -270,7 +277,7 @@ sealed class MainWindow : Windowvar s = new StackPanel();s.Children.Add(Ui.Text(title, 13, Palette.Body, FontWeights.SemiBold));foreach (var i in items) s.Children.Add(Gap(i, 10));- return new Border { Background = Palette.SurfaceAlt, BorderBrush = Palette.StrokeSoft, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(8), Padding = new Thickness(16, 14, 16, 14), Margin = new Thickness(0, 0, 0, 16), Child = s };+ return new Border { Background = Palette.Page, BorderBrush = Palette.Line, BorderThickness = new Thickness(0), CornerRadius = new CornerRadius(14), Padding = new Thickness(16, 14, 16, 14), Margin = new Thickness(0, 0, 0, 16), Child = s };}FrameworkElement Transcript(Session s, ScrollViewer scroll)diff --git a/windows/src/Cicada/NotesWindow.cs b/windows/src/Cicada/NotesWindow.csindex e6597d1..7f11067 100644--- a/windows/src/Cicada/NotesWindow.cs+++ b/windows/src/Cicada/NotesWindow.cs@@ -30,23 +30,21 @@ sealed class NotesWindow : Windowpublic NotesWindow(Controller app){this.app = app;- // A plain frameless window, framed by DWM (UseSystemFrame), not a transparent one: those are- // redrawn in software, and with a shadow that cost most of a CPU core while listening.+ // Transparent, so it can have the Mac's 16-point corners (Windows' own frame stops at 8). WPF+ // redraws such a window in software, so nothing here animates: the clock is the one redraw a+ // second, and the shadow is plain rings (Ui.Floating), not a blur.WindowStyle = WindowStyle.None;- System.Windows.Shell.WindowChrome.SetWindowChrome(this, new System.Windows.Shell.WindowChrome- {- CaptionHeight = 0, ResizeBorderThickness = new Thickness(6), GlassFrameThickness = new Thickness(0, 1, 0, 0), UseAeroCaptionButtons = false,- });+ AllowsTransparency = true;+ Background = Brushes.Transparent;Topmost = true;ShowInTaskbar = false;ShowActivated = false;- ResizeMode = ResizeMode.CanResize;+ ResizeMode = ResizeMode.CanResizeWithGrip;FontFamily = Palette.Font;Title = L("知了");SourceInitialized += (_, _) =>{Native.MakeNonActivating(this);- Native.UseSystemFrame(this, Subtitles);ApplyCaptureSetting();};// Drag from anywhere that isn't a control (buttons and links mark the press handled).@@ -57,7 +55,7 @@ sealed class NotesWindow : WindowSizeChanged += (_, e) =>{if (!Subtitles || !e.HeightChanged) return;- if (e.PreviousSize.Height <= 0 || !placedSubtitles) { Top = SystemParameters.WorkArea.Bottom - e.NewSize.Height - 16; placedSubtitles = true; }+ if (e.PreviousSize.Height <= 0 || !placedSubtitles) { Top = SystemParameters.WorkArea.Bottom - e.NewSize.Height - 16 + Ui.ShadowRoom; placedSubtitles = true; }else Top -= e.NewSize.Height - e.PreviousSize.Height;};Place();@@ -73,15 +71,15 @@ sealed class NotesWindow : Windowif (Subtitles){SizeToContent = SizeToContent.Height; MinHeight = 80; MinWidth = 480;- Width = Math.Min(900, area.Width - 48);- Left = area.Left + (area.Width - Width) / 2; Top = area.Bottom - Math.Max(ActualHeight, MinHeight) - 16;+ Width = Math.Min(900, area.Width - 48) + 2 * Ui.ShadowRoom;+ Left = area.Left + (area.Width - Width) / 2; Top = area.Bottom - Math.Max(ActualHeight, MinHeight) - 16 + Ui.ShadowRoom;placedSubtitles = ActualHeight > 0;}else{SizeToContent = SizeToContent.Manual; MinHeight = 360; MinWidth = 340;- Width = 400; Height = Math.Min(820, area.Height - 32);- Left = area.Right - Width - 16; Top = area.Top + 16;+ Width = 400 + 2 * Ui.ShadowRoom; Height = Math.Min(820, area.Height - 32) + 2 * Ui.ShadowRoom;+ Left = area.Right - Width - 16 + Ui.ShadowRoom; Top = area.Top + 16 - Ui.ShadowRoom;}}@@ -124,8 +122,6 @@ sealed class NotesWindow : WindowbuiltFor = mode; headerKey = tabsKey = barsKey = null;header = new ContentControl(); bars = new ContentControl(); live = new ContentControl(); tabs = new ContentControl(); footer = new ContentControl();scroll = new ScrollViewer { VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Padding = new Thickness(16, 14, 12, 16) };- Background = Subtitles ? Palette.Night : Palette.Surface;- if (IsLoaded) Native.UseSystemFrame(this, Subtitles);Content = Subtitles ? SubtitleFrame() : PanelFrame();}var key = $"{app.Listen.Listening}|{app.Settings.ShowInCapture}|{hiddenFromCapture}";@@ -160,7 +156,7 @@ sealed class NotesWindow : WindowDockPanel.SetDock(footer, Dock.Bottom);dock.Children.Add(footer);dock.Children.Add(scroll);- return dock;+ return Ui.Floating(dock, Palette.Surface);}FrameworkElement Header()@@ -255,7 +251,7 @@ sealed class NotesWindow : Windowstack.Children.Add(Gap(Ui.Row(6, Ui.LiveDot(4), Ui.Text(L("在听下一句"), 12, Palette.Tertiary, wrap: false)), 6, top: true));}// Room for a two-line translation, so the tabs below don't jump as lines come and go.- return new Border { Background = Palette.Mica, CornerRadius = new CornerRadius(8), Padding = new Thickness(14, 12, 14, 12), Margin = new Thickness(12, 0, 12, 0), Child = stack, MinHeight = 126 };+ return new Border { Background = Palette.Mica, CornerRadius = new CornerRadius(12), Padding = new Thickness(14, 12, 14, 12), Margin = new Thickness(12, 0, 12, 0), Child = stack, MinHeight = 126 };}FrameworkElement TabRow()@@ -398,7 +394,7 @@ sealed class NotesWindow : Windowgrid.Children.Add(live);grid.Children.Add(header);var handle = new Border { Width = 36, Height = 4, CornerRadius = new CornerRadius(2), Background = new SolidColorBrush(Color.FromArgb(0x38, 0xFF, 0xFF, 0xFF)), HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 0, 0, 6) };- return new Border { Padding = new Thickness(16, 6, 10, 14), Child = new StackPanel { Children = { handle, grid } } };+ return Ui.Floating(new Border { Padding = new Thickness(16, 6, 10, 14), Child = new StackPanel { Children = { handle, grid } } }, new SolidColorBrush(Color.FromArgb(0xF0, 0x15, 0x17, 0x1C)), 14, dark: true);}FrameworkElement SubtitleLine()diff --git a/windows/src/Cicada/Onboarding.cs b/windows/src/Cicada/Onboarding.csindex ae4f777..9483918 100644--- a/windows/src/Cicada/Onboarding.cs+++ b/windows/src/Cicada/Onboarding.cs@@ -18,7 +18,7 @@ sealed class Onboarding : Windowint step;SystemAudioTap? tap;readonly DispatcherTimer meter = new() { Interval = TimeSpan.FromMilliseconds(80) };- readonly double[] levels = new double[32];+ readonly double[] levels = new double[44];double level, peak;bool autoStart = true, playing;// Step 1: the key field and what we know about it@@ -31,8 +31,8 @@ sealed class Onboarding : Window{this.app = app;Title = L("设置知了");- Width = 720; Height = 560; ResizeMode = ResizeMode.NoResize;- Background = Palette.SurfaceAlt; FontFamily = Palette.Font; Icon = AppIcon.Image;+ Width = 760; Height = 640; ResizeMode = ResizeMode.NoResize;+ Background = Palette.Page; FontFamily = Palette.Font; Icon = AppIcon.Image;WindowStartupLocation = WindowStartupLocation.CenterScreen;var dock = new DockPanel();DockPanel.SetDock(stepper, Dock.Top);@@ -71,86 +71,144 @@ sealed class Onboarding : Windowfooter.Content = Footer();}+ // The Mac's setup layout (Onboarding.swift): the logo and a bar per step along the top, a big+ // bold heading with one grey line, the task in one white card, Back and Continue at the bottom.FrameworkElement Stepper(){- var row = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(40, 20, 40, 0) };+ var grid = new Grid { Margin = new Thickness(40, 28, 40, 0) };+ grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });string[] names = [L("接上 Ling"), L("系统声音"), L("试一下")];+ for (int i = 0; i < names.Length; i++) grid.ColumnDefinitions.Add(new ColumnDefinition());+ var logo = AppIcon.Small(40);+ logo.Margin = new Thickness(0, 0, 18, 0);+ grid.Children.Add(logo);for (int i = 0; i < names.Length; i++){- if (i > 0) row.Children.Add(new Border { Width = 32, Height = 1, Background = Palette.ControlStroke, Margin = new Thickness(10, 0, 10, 0), VerticalAlignment = VerticalAlignment.Center });- var done = i < step; var now = i == step;- var badge = new Grid { Width = 22, Height = 22 };- badge.Children.Add(new Ellipse { Fill = done ? Palette.Success : now ? Palette.Ink : Brushes.Transparent, Stroke = done || now ? null : Palette.Tertiary, StrokeThickness = 1 });- if (done) badge.Children.Add(Ui.Icon(Icons.Check, 12, Brushes.White, stroke: 2.4));- else { var n = Ui.Text($"{i + 1}", 12, now ? Brushes.White : Palette.Secondary, FontWeights.SemiBold, wrap: false); n.HorizontalAlignment = HorizontalAlignment.Center; n.VerticalAlignment = VerticalAlignment.Center; badge.Children.Add(n); }- row.Children.Add(Ui.Row(8, badge, Ui.Text(names[i], 13, now ? Palette.Ink : Palette.Secondary, now ? FontWeights.SemiBold : FontWeights.Normal, wrap: false)));+ var reached = i <= step;+ var bar = new Border { Height = 4, CornerRadius = new CornerRadius(2), Background = reached ? Palette.Ink : Palette.Line };+ var name = Ui.Text(names[i], 13, i == step ? Palette.Ink : Palette.Secondary, i == step ? FontWeights.Bold : FontWeights.Normal, wrap: false);+ name.Margin = new Thickness(0, 9, 0, 0);+ var col = new StackPanel { Margin = new Thickness(i == 0 ? 0 : 6, 6, 0, 0), Children = { bar, name } };+ Grid.SetColumn(col, i + 1);+ grid.Children.Add(col);}- return row;+ return grid;}FrameworkElement Page(string title, string text, params UIElement[] body){- var s = new StackPanel { Margin = new Thickness(40, 28, 40, 0) };- s.Children.Add(Ui.Text(title, 26, Palette.Ink, FontWeights.SemiBold));- var p = Ui.Text(text, 14, Palette.Body);- p.Margin = new Thickness(0, 8, 0, 0); p.LineHeight = 22;+ var s = new StackPanel { Margin = new Thickness(40, 36, 40, 0) };+ s.Children.Add(Ui.Text(title, 28, Palette.Ink, FontWeights.Bold));+ var p = Ui.Text(text, 15, Palette.Secondary);+ p.Margin = new Thickness(0, 10, 0, 0); p.LineHeight = 22;s.Children.Add(p);- foreach (var b in body) { if (b is FrameworkElement f) f.Margin = new Thickness(f.Margin.Left, f.Margin.Top + 18, f.Margin.Right, f.Margin.Bottom); s.Children.Add(b); }+ foreach (var b in body) { if (b is FrameworkElement f) f.Margin = new Thickness(f.Margin.Left, f.Margin.Top + 24, f.Margin.Right, f.Margin.Bottom); s.Children.Add(b); }return s;}+ /// The Mac's white step card: 18-point corners and a hairline.+ static Border StepCard(UIElement child) => new()+ {+ Background = Brushes.White, BorderBrush = Palette.Line, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(18),+ Padding = new Thickness(28, 24, 28, 24), Child = child,+ };++ /// A numbered row in a step card: a grey disc with the number, a bold line, a grey line.+ static FrameworkElement Numbered(int n, string title, string? detail, UIElement? right = null, UIElement? below = null)+ {+ var disc = new Grid { Width = 32, Height = 32, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(0, 0, 16, 0) };+ disc.Children.Add(new Ellipse { Fill = Palette.Mica });+ var num = Ui.Text($"{n}", 15, Palette.Ink, FontWeights.Bold, wrap: false); num.HorizontalAlignment = HorizontalAlignment.Center; num.VerticalAlignment = VerticalAlignment.Center;+ disc.Children.Add(num);+ var text = new StackPanel { VerticalAlignment = VerticalAlignment.Center };+ text.Children.Add(Ui.Text(title, 17, Palette.Ink, FontWeights.Bold));+ if (detail is not null) { var d = Ui.Text(detail, 13, Palette.Secondary); d.Margin = new Thickness(0, 3, 0, 0); text.Children.Add(d); }+ if (below is FrameworkElement b) { b.Margin = new Thickness(0, 12, 0, 0); text.Children.Add(b); }+ var dock = new DockPanel();+ DockPanel.SetDock(disc, Dock.Left);+ dock.Children.Add(disc);+ if (right is FrameworkElement r) { DockPanel.SetDock(r, Dock.Right); r.VerticalAlignment = VerticalAlignment.Center; r.Margin = new Thickness(16, 0, 0, 0); dock.Children.Add(r); }+ dock.Children.Add(text);+ return dock;+ }++ static FrameworkElement Divider() => new Border { Height = 1, Background = Palette.Line, Margin = new Thickness(0, 20, 0, 20) };+FrameworkElement Footer(){- var buttons = new StackPanel { Orientation = Orientation.Horizontal };- var back = Ui.Button(L("上一步"), () => Go(step - 1));- back.IsEnabled = step > 0;- buttons.Children.Add(back);+ var back = Ui.Button(L("上一步"), () => Go(step - 1), Ui.Kind.Subtle, height: 48);+ back.MinWidth = 0; back.HorizontalAlignment = HorizontalAlignment.Left;+ back.Visibility = step > 0 ? Visibility.Visible : Visibility.Hidden;var next = step switch{- 0 => Ui.Button(L("继续"), () => _ = SaveKey(), Ui.Kind.Primary),- 1 => Ui.Button(L("继续"), () => Go(2), peak >= 0.01 ? Ui.Kind.Primary : Ui.Kind.Standard),- _ => Ui.Button(L("完成"), () => Go(3), Ui.Kind.Primary),+ 0 => Ui.Button(L("继续"), () => _ = SaveKey(), Ui.Kind.Primary, height: 48),+ 1 => Ui.Button(L("继续"), () => Go(2), peak >= 0.01 ? Ui.Kind.Primary : Ui.Kind.Standard, height: 48),+ _ => Ui.Button(L("完成"), () => Go(3), Ui.Kind.Primary, height: 48),};- next.Margin = new Thickness(8, 0, 0, 0);+ next.MinWidth = 150; next.HorizontalAlignment = HorizontalAlignment.Right;next.IsEnabled = !checking;- buttons.Children.Add(next);- UIElement left = step == 1 ? Ui.Text(L("没有声音?先确认电脑没静音"), 13, Palette.Secondary, wrap: false) : new Border();- var row = Ui.Spread(left, buttons);- ((FrameworkElement)left).VerticalAlignment = VerticalAlignment.Center;- row.Margin = new Thickness(24, 18, 24, 18);- return new Border { Background = Palette.Subtle, BorderBrush = Palette.Stroke, BorderThickness = new Thickness(0, 1, 0, 0), Child = row };+ var right = new StackPanel { Orientation = Orientation.Horizontal };+ if (step == 1)+ {+ var hint = Ui.Text(L("没有声音?先确认电脑没静音"), 13, Palette.Secondary, wrap: false);+ hint.VerticalAlignment = VerticalAlignment.Center; hint.Margin = new Thickness(0, 0, 16, 0);+ right.Children.Add(hint);+ }+ right.Children.Add(next);+ var row = Ui.Spread(back, right);+ row.Margin = new Thickness(28, 16, 40, 28);+ return row;}// MARK: 1 · Ling keyFrameworkElement KeyStep(){- var open = Ui.Button(L("打开 Ling 开放平台"), () => Process.Start(new ProcessStartInfo("https://chat.ant-ling.com/platform/api") { UseShellExecute = true }), Ui.Kind.Standard, Icons.OpenExternal);- open.HorizontalAlignment = HorizontalAlignment.Left;+ var open = Ui.Button(L("打开 Ling 开放平台 ↗"), () => Process.Start(new ProcessStartInfo("https://chat.ant-ling.com/platform/api") { UseShellExecute = true }));+ open.HorizontalAlignment = HorizontalAlignment.Right;var reveal = Ui.IconButton(Icons.Eye, L("显示 key"), () =>{var show = keyText.Visibility != Visibility.Visible;keyText.Visibility = show ? Visibility.Visible : Visibility.Collapsed;keyBox.Visibility = show ? Visibility.Collapsed : Visibility.Visible;- }, Palette.Body, 36, 16);- reveal.Margin = new Thickness(4, 0, 0, 0);+ }, Palette.Secondary, 32, 16);Detach(keyBox); Detach(keyText); Detach(keyStatus);- var field = new Grid { Children = { keyBox, keyText } };- var paste = Ui.Button(L("粘贴"), () =>+ var hint = Ui.Text("sk-…", 14, Palette.Tertiary, wrap: false);+ hint.IsHitTestVisible = false; hint.VerticalAlignment = VerticalAlignment.Center;+ void Hint() => hint.Visibility = keyBox.Password.Length == 0 ? Visibility.Visible : Visibility.Collapsed;+ keyBox.PasswordChanged += (_, _) => Hint();+ Hint();+ var boxes = new Grid { Children = { keyBox, keyText, hint } };+ var inner = new DockPanel();+ DockPanel.SetDock(reveal, Dock.Right);+ inner.Children.Add(reveal); inner.Children.Add(boxes);+ Ui.StyleField(keyBox); Ui.StyleField(keyText);+ var field = Ui.FieldFrame(inner, keyBox);+ field.Padding = new Thickness(12, 0, 4, 0);+ var paste = Ui.Button(L("粘贴并检查"), () =>{try { if (Clipboard.ContainsText()) keyText.Text = Clipboard.GetText().Trim(); } catch { }_ = SaveKey();- });+ }, Ui.Kind.Primary, Icons.Copy, height: 40);var row = new DockPanel();DockPanel.SetDock(paste, Dock.Right);- DockPanel.SetDock(reveal, Dock.Right);- paste.Margin = new Thickness(4, 0, 0, 0);- row.Children.Add(paste); row.Children.Add(reveal); row.Children.Add(field);- var keyLabel = Ui.Text(L("Ling key"), 14, Palette.Ink, FontWeights.SemiBold);+ paste.Margin = new Thickness(10, 0, 0, 0);+ row.Children.Add(paste); row.Children.Add(field);if (app.Ling.HasKey && keyBox.Password.Length == 0) Status(true, AIKey.Masked(app.Key.Read() ?? "") + " · " + L("可以用"));- var privacy = Ui.Row(8, Ui.Icon(Icons.Shield, 16, Palette.Secondary), Ui.Text(L("只加密存在这台电脑上,只发给 Ling"), 13, Palette.Secondary));- return Page(L("接上 Ling"), L("识别、翻译和纪要都靠它。到 Ling 开放平台点“创建令牌”,复制 sk- 开头的那串,粘贴到下面。"),- open, Ui.Stack(6, keyLabel, row, keyStatus), privacy);+ var privacy = Ui.Row(8, Ui.Icon(Icons.Shield, 15, Palette.Secondary), Ui.Text(L("只加密存在这台电脑上,只发给 Ling"), 13, Palette.Secondary));+ keyStatus.Margin = new Thickness(0, 8, 0, 0);+ var second = new StackPanel { Children = { row, keyStatus, privacy } };+ privacy.Margin = new Thickness(0, 10, 0, 0);+ var card = StepCard(new StackPanel+ {+ Children =+ {+ Numbered(1, L("在 Ling 开放平台创建 key"), L("注册或登录后点“创建令牌”"), open),+ Divider(),+ Numbered(2, L("复制 sk- 开头的 key,回来粘贴"), null, below: second),+ },+ });+ return Page(L("接上 Ling,用上完整的知了"), L("识别、翻译和纪要都靠它,约 1 分钟。"), card);}static void Detach(FrameworkElement e) { if (e.Parent is Panel p) p.Children.Remove(e); else if (e.Parent is ContentControl c) c.Content = null; else if (e.Parent is Decorator d) d.Child = null; }@@ -207,11 +265,18 @@ sealed class Onboarding : Window}Detach(meterHost); Detach(heardHost);Meter();- var card = Ui.Card(Ui.Stack(14, Ui.Row(14, Ui.Icon(Icons.Speaker, 22, Palette.Body), meterHost), heardHost), new Thickness(20, 18, 20, 18));- var lines = new StackPanel();- if (AudioDevice.DefaultName() is { } device) lines.Children.Add(Ui.Text(LF("正在听:%@", device), 13, Palette.Secondary));- lines.Children.Add(Ui.Text(L("换成耳机或蓝牙音箱也能接着听。"), 13, Palette.Secondary));- return Page(L("系统声音"), L("知了听的是电脑播放出来的声音,不用麦克风,也不用授权。放一段视频或音乐试试。"), card, lines);+ var device = AudioDevice.DefaultName();+ var card = StepCard(new StackPanel+ {+ Children =+ {+ Ui.Row(14, Ui.Icon(Icons.Speaker, 22, Palette.Body), meterHost),+ new Border { Height = 14 }, heardHost,+ Divider(),+ Ui.Text(device is null ? L("换成耳机或蓝牙音箱也能接着听。") : $"{LF("正在听:%@", device)} · {L("换成耳机或蓝牙音箱也能接着听。")}", 13, Palette.Secondary),+ },+ });+ return Page(L("系统声音"), L("知了听的是电脑播放出来的声音,不用麦克风,也不用授权。放一段视频或音乐试试。"), card);}/// 32 bars of the last few seconds of loudness, newest on the right.@@ -223,7 +288,7 @@ sealed class Onboarding : Windowlevel = 0;var bars = new StackPanel { Orientation = Orientation.Horizontal, Height = 40 };foreach (var v in levels)- bars.Children.Add(new Rectangle { Width = 12, Height = 4 + v * 36, RadiusX = 2, RadiusY = 2, Margin = new Thickness(0, 0, 3, 0), VerticalAlignment = VerticalAlignment.Center, Fill = v > 0.08 ? Palette.Live : Palette.Stroke });+ bars.Children.Add(new Rectangle { Width = 3, Height = 4 + v * 36, RadiusX = 1.5, RadiusY = 1.5, Margin = new Thickness(0, 0, 9, 0), VerticalAlignment = VerticalAlignment.Center, Fill = v > 0.08 ? Palette.Live : Palette.Line });System.Windows.Automation.AutomationProperties.SetName(bars, L("系统声音"));meterHost.Content = bars;var heard = peak >= 0.01;@@ -245,15 +310,20 @@ sealed class Onboarding : WindowFrameworkElement SampleStep(){- var play = Ui.Button(playing ? L("正在播放…") : L("播放示例"), () => _ = PlaySample(), Ui.Kind.Accent, Icons.Play, 52, iconFill: true);+ var play = Ui.Button(playing ? L("正在播放…") : L("播放示例"), () => _ = PlaySample(), Ui.Kind.Accent, Icons.Play, 48, iconFill: true);play.IsEnabled = !playing;- play.HorizontalAlignment = HorizontalAlignment.Left;- var startup = new CheckBox { IsChecked = autoStart, Content = Ui.Text(L("开机时启动知了(在任务栏右下角待命)"), 14, Palette.Ink) };- startup.Click += (_, _) => autoStart = startup.IsChecked == true;- var howto = Ui.Text(LF("开会时点任务栏里的知了图标,或按 %@ 开始。", Hotkey.Label), 13, Palette.Secondary);- howto.Margin = new Thickness(28, 6, 0, 0);- return Page(L("试一下"), L("放一段 9 秒的英文示例会议,看字幕和纪要怎么出现。纪要窗口不会抢走焦点,也不会出现在屏幕共享里。"),- play, new StackPanel { Children = { startup, howto } });+ play.MinWidth = 160;+ var startup = Ui.Switch(autoStart, v => autoStart = v, L("开机时启动知了"));+ var card = StepCard(new StackPanel+ {+ Children =+ {+ Numbered(1, L("播放示例"), L("一段 9 秒的英文会议"), play),+ Divider(),+ Numbered(2, L("开机时启动知了"), LF("开会时点任务栏里的知了图标,或按 %@ 开始。", Hotkey.Label), startup),+ },+ });+ return Page(L("试一下"), L("看字幕和纪要怎么出现。纪要窗口不会抢走焦点,也不会出现在屏幕共享里。"), card);}async Task PlaySample()diff --git a/windows/src/Cicada/SettingsWindow.cs b/windows/src/Cicada/SettingsWindow.csindex 1b94998..ac2c373 100644--- a/windows/src/Cicada/SettingsWindow.cs+++ b/windows/src/Cicada/SettingsWindow.cs@@ -14,7 +14,7 @@ sealed class SettingsWindow : Windowreadonly ScrollViewer scroll = new() { VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Padding = new Thickness(16, 0, 32, 32) };readonly StackPanel nav = new() { Margin = new Thickness(12, 8, 12, 12) };readonly Dictionary<string, FrameworkElement> sections = [];- readonly PasswordBox keyBox = new() { FontSize = 14, MinHeight = 32, Width = 300, VerticalContentAlignment = VerticalAlignment.Center };+ readonly PasswordBox keyBox = new();bool editingKey;string current = "ling";@@ -23,7 +23,7 @@ sealed class SettingsWindow : Windowthis.app = app;Title = L("设置") + " · " + L("知了");Width = 1000; Height = Math.Min(760, SystemParameters.WorkArea.Height - 24); MinWidth = 760; MinHeight = 480;- Background = Palette.Mica; FontFamily = Palette.Font; Icon = AppIcon.Image;+ Background = Palette.Page; FontFamily = Palette.Font; Icon = AppIcon.Image;WindowStartupLocation = WindowStartupLocation.CenterScreen;System.Windows.Automation.AutomationProperties.SetName(keyBox, L("Ling key"));var grid = new Grid();@@ -44,7 +44,7 @@ sealed class SettingsWindow : Windowvar offset = scroll.VerticalOffset;sections.Clear();var page = new StackPanel { MaxWidth = 860, HorizontalAlignment = HorizontalAlignment.Stretch };- var title = Ui.Text(L("设置"), 28, Palette.Ink, FontWeights.SemiBold);+ var title = Ui.Text(L("设置"), 28, Palette.Ink, FontWeights.Bold);title.Margin = new Thickness(0, 4, 0, 8);page.Children.Add(title);Section(page, "ling", L("Ling"), KeyCard(), Group(Card(Icons.Notes, L("纪要和翻译用的模型"), L("3.1 更准;3.0 更快、更省。语音识别固定用 Ming。"),@@ -85,10 +85,9 @@ sealed class SettingsWindow : Window{var on = id == current;var content = new Grid();- var mark = new Border { Width = 3, Height = 16, CornerRadius = new CornerRadius(2), Background = on ? Palette.Ink : Brushes.Transparent, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(-12, 0, 0, 0) };- content.Children.Add(mark);+content.Children.Add(Ui.Row(12, Ui.Icon(icon, 18, Palette.Ink), Ui.Text(label, 14, Palette.Ink, on ? FontWeights.SemiBold : FontWeights.Normal, wrap: false)));- var b = new Button { HorizontalAlignment = HorizontalAlignment.Stretch, Content = content, Height = 40, Padding = new Thickness(12, 0, 12, 0), HorizontalContentAlignment = HorizontalAlignment.Left, Background = on ? Palette.Selected : Brushes.Transparent, BorderThickness = new Thickness(0), Cursor = System.Windows.Input.Cursors.Hand, Margin = new Thickness(0, 0, 0, 2) };+ var b = new Button { HorizontalAlignment = HorizontalAlignment.Stretch, Content = content, Height = 40, Padding = new Thickness(12, 0, 12, 0), HorizontalContentAlignment = HorizontalAlignment.Left, Background = on ? Palette.Line : Brushes.Transparent, BorderThickness = new Thickness(0), Cursor = System.Windows.Input.Cursors.Hand, Margin = new Thickness(0, 0, 0, 2) };b.Template = NavTemplate();b.Click += (_, _) =>{@@ -105,7 +104,7 @@ sealed class SettingsWindow : Window{var t = new ControlTemplate(typeof(Button));var border = new FrameworkElementFactory(typeof(Border), "bg");- border.SetValue(Border.CornerRadiusProperty, new CornerRadius(6));+ border.SetValue(Border.CornerRadiusProperty, new CornerRadius(10));border.SetBinding(Border.BackgroundProperty, new System.Windows.Data.Binding("Background") { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent });border.SetBinding(Border.PaddingProperty, new System.Windows.Data.Binding("Padding") { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent });var content = new FrameworkElementFactory(typeof(ContentPresenter));@@ -115,14 +114,14 @@ sealed class SettingsWindow : Windowvar hover = new MultiTrigger();hover.Conditions.Add(new Condition(UIElement.IsMouseOverProperty, true));hover.Conditions.Add(new Condition(Control.BackgroundProperty, Brushes.Transparent));- hover.Setters.Add(new Setter(Border.BackgroundProperty, Palette.Subtle, "bg"));+ hover.Setters.Add(new Setter(Border.BackgroundProperty, Palette.Mica, "bg"));t.Triggers.Add(hover);return t;}void Section(StackPanel page, string id, string title, params FrameworkElement[] groups){- var h = Ui.Text(title, 14, Palette.Ink, FontWeights.SemiBold);+ var h = Ui.Text(title, 13, Palette.Secondary, FontWeights.Bold);h.Margin = new Thickness(0, 20, 0, 8);sections[id] = h;page.Children.Add(h);@@ -135,7 +134,7 @@ sealed class SettingsWindow : Windowvar s = new StackPanel();for (int i = 0; i < cards.Length; i++)s.Children.Add(new Border { BorderBrush = Palette.StrokeSoft, BorderThickness = new Thickness(0, i == 0 ? 0 : 1, 0, 0), Child = cards[i] });- return new Border { Background = Palette.Surface, BorderBrush = Palette.Stroke, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(6), Child = s };+ return new Border { Background = Palette.Surface, BorderBrush = Palette.Line, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(16), Child = s, Padding = new Thickness(4, 2, 4, 2) };}/// One setting: icon, name, one grey line, and its control on the right.@@ -216,7 +215,9 @@ sealed class SettingsWindow : Windowif (editingKey){if (keyBox.Parent is Panel p) p.Children.Remove(keyBox);- control = Ui.Row(8, keyBox, Ui.Button(L("保存"), () => _ = SaveKey(), Ui.Kind.Primary, height: 32), Ui.Button(L("取消"), () => { editingKey = false; Render(); }, height: 32));+ if (keyBox.Parent is Border old) old.Child = null;+ var field = Ui.Field(keyBox); field.Width = 300; field.Height = 34;+ control = Ui.Row(8, field, Ui.Button(L("保存"), () => _ = SaveKey(), Ui.Kind.Primary, height: 34), Ui.Button(L("取消"), () => { editingKey = false; Render(); }, height: 34));}else{diff --git a/windows/src/Cicada/SpeakBar.cs b/windows/src/Cicada/SpeakBar.csindex b93e20f..142fb00 100644--- a/windows/src/Cicada/SpeakBar.cs+++ b/windows/src/Cicada/SpeakBar.cs@@ -18,16 +18,14 @@ sealed class SpeakBar : Windowpublic SpeakBar(Controller app){this.app = app;- WindowStyle = WindowStyle.None; Background = Palette.Night; Topmost = true; ShowInTaskbar = false; ShowActivated = false;- ResizeMode = ResizeMode.NoResize; SizeToContent = SizeToContent.Height; Width = 560; FontFamily = Palette.Font; Title = L("知了");- System.Windows.Shell.WindowChrome.SetWindowChrome(this, new System.Windows.Shell.WindowChrome { CaptionHeight = 0, ResizeBorderThickness = new Thickness(0), GlassFrameThickness = new Thickness(0, 1, 0, 0), UseAeroCaptionButtons = false });+ WindowStyle = WindowStyle.None; AllowsTransparency = true; Background = Brushes.Transparent; Topmost = true; ShowInTaskbar = false; ShowActivated = false;+ ResizeMode = ResizeMode.NoResize; SizeToContent = SizeToContent.Height; Width = 560 + 2 * Ui.ShadowRoom; FontFamily = Palette.Font; Title = L("知了");SourceInitialized += (_, _) =>{Native.MakeNonActivating(this);- Native.UseSystemFrame(this, dark: true);Native.SetCaptureVisible(this, app.Settings.ShowInCapture);};- Content = new Border { Padding = new Thickness(18, 12, 18, 14), Child = body };+ Content = Ui.Floating(new Border { Padding = new Thickness(18, 12, 18, 14), Child = body }, new SolidColorBrush(Color.FromArgb(0xF0, 0x15, 0x17, 0x1C)), 14, dark: true);SizeChanged += (_, _) => Place();hide.Tick += (_, _) => { hide.Stop(); Hide(); };}@@ -37,7 +35,7 @@ sealed class SpeakBar : Windowvar area = SystemParameters.WorkArea;Left = area.Left + (area.Width - ActualWidth) / 2;var above = app.Settings.View == "subtitles" && app.NotesVisible ? 150 : 16;- Top = area.Bottom - ActualHeight - above;+ Top = area.Bottom - ActualHeight - above + Ui.ShadowRoom;}public void Refresh()diff --git a/windows/src/Cicada/TrayFlyout.cs b/windows/src/Cicada/TrayFlyout.csindex 9c0147b..a9f7767 100644--- a/windows/src/Cicada/TrayFlyout.cs+++ b/windows/src/Cicada/TrayFlyout.cs@@ -18,13 +18,11 @@ sealed class TrayFlyout : Windowpublic TrayFlyout(Controller app){this.app = app;- // Framed by DWM like the notes panel: rounded, shadowed, and cheap to redraw each second.- WindowStyle = WindowStyle.None; Background = Palette.SurfaceAlt;- System.Windows.Shell.WindowChrome.SetWindowChrome(this, new System.Windows.Shell.WindowChrome { CaptionHeight = 0, ResizeBorderThickness = new Thickness(0), GlassFrameThickness = new Thickness(0, 1, 0, 0), UseAeroCaptionButtons = false });- SourceInitialized += (_, _) => Native.UseSystemFrame(this);+ // The Mac panel's 16-point corners and soft shadow (Ui.Floating), so a transparent window.+ WindowStyle = WindowStyle.None; AllowsTransparency = true; Background = Brushes.Transparent;Topmost = true; ShowInTaskbar = false; ResizeMode = ResizeMode.NoResize;- Width = 380; SizeToContent = SizeToContent.Height; FontFamily = Palette.Font; Title = L("知了");- Content = body;+ Width = 380 + 2 * Ui.ShadowRoom; SizeToContent = SizeToContent.Height; FontFamily = Palette.Font; Title = L("知了");+ Content = Ui.Floating(body, Palette.Page);Deactivated += (_, _) => { Hide(); hiddenAt = DateTime.UtcNow; };KeyDown += (_, e) => { if (e.Key == System.Windows.Input.Key.Escape) Hide(); };SizeChanged += (_, _) => Anchor();@@ -47,8 +45,8 @@ sealed class TrayFlyout : Windowvoid Anchor(){var area = SystemParameters.WorkArea;- Left = area.Right - ActualWidth - 12;- Top = area.Bottom - ActualHeight - 12;+ Left = area.Right - ActualWidth - 12 + Ui.ShadowRoom;+ Top = area.Bottom - ActualHeight - 12 + Ui.ShadowRoom;}public void Refresh() => body.Content = Build();diff --git a/windows/src/Cicada/Ui.cs b/windows/src/Cicada/Ui.csindex 1f2d753..e40d6c0 100644--- a/windows/src/Cicada/Ui.cs+++ b/windows/src/Cicada/Ui.cs@@ -20,6 +20,7 @@ static class Palettepublic static readonly SolidColorBrush Subtle = B(0xF0F1F3);public static readonly SolidColorBrush Selected = B(0xE6E8EB);public static readonly SolidColorBrush Stroke = B(0xE3E5E8);+ public static readonly SolidColorBrush Line = B(0xE4E6EA);public static readonly SolidColorBrush StrokeSoft = B(0xEEF0F2);public static readonly SolidColorBrush ControlStroke = B(0xD5D8DD);public static readonly SolidColorBrush Ink = B(0x15171C);@@ -32,12 +33,17 @@ static class Palettepublic static readonly SolidColorBrush AccentText = B(0xA8370F);public static readonly SolidColorBrush Success = B(0x0F7B3F);public static readonly SolidColorBrush Danger = B(0xC42B1C);- public static readonly SolidColorBrush ErrorBg = B(0xFDF0EE);+ public static readonly SolidColorBrush ErrorBg = B(0xFDECEA);public static readonly SolidColorBrush ErrorStroke = B(0xF3CBC4);public static readonly SolidColorBrush WarnBg = B(0xFFF6E5);public static readonly SolidColorBrush WarnStroke = B(0xF1DDB0);public static readonly SolidColorBrush WarnIcon = B(0x9D5D00);public static readonly SolidColorBrush Night = B(0x15171C);+ public static readonly SolidColorBrush Toggle = B(0xD9DBE0);+ public static readonly SolidColorBrush FieldLine = B(0xD1D4D9);+ /// The Mac's ground for windows (onboarding, settings), a shade lighter than the panels' fill.+ public static readonly SolidColorBrush Page = B(0xF7F8FA);+ /// The Mac's pale error and warning washes.public static readonly SolidColorBrush NightText = B(0xB4B9C2);/// 说话人 1, 2, 3… cycling after four (the Mac's SpeakerColor): not the accent (live, and 你),/// distinct in lightness, all ≥ 4.5:1 on white.@@ -87,7 +93,8 @@ static class UiFontFamily = Palette.Font,};- public static TextBlock Heading(string text, double size = 15) => Text(text, size, Palette.Ink, FontWeights.SemiBold);+ // The Mac's headings are bold, not semibold: they carry the page.+ public static TextBlock Heading(string text, double size = 15) => Text(text, size, Palette.Ink, FontWeights.Bold);public static TextBlock Helper(string text) => Text(text, 12, Palette.Secondary);/// A 20×20 stroke icon, or a filled one, scaled to `size`.@@ -135,32 +142,32 @@ static class Uipublic enum Kind { Standard, Primary, Accent, Subtle, Danger, Pale }- /// Windows 11 buttons: Standard (white, hairline), Primary (ink), Accent (live orange, for- /// 开始听 only), Subtle (no fill until hover), Danger (red, for delete), Pale (the 结束 pill).+ /// The Mac's buttons (Views.swift › SoftButton and friends): Standard is a soft grey fill with no+ /// border, Primary ink, Accent live orange (开始听 only), Subtle no fill until hover, Danger red,+ /// Pale the 结束 pill. Corners 10, or 12 on the big ones; labels semibold.public static Button Button(string label, Action onClick, Kind kind = Kind.Standard, string? icon = null, double height = 36, bool iconFill = false){- var (bg, fg, border) = kind switch+ var (bg, fg) = kind switch{- Kind.Primary => (Palette.Ink, Brushes.White, Brushes.Transparent),- Kind.Accent => (Palette.AccentFill, Brushes.White, Brushes.Transparent),- Kind.Danger => (Palette.Danger, Brushes.White, Brushes.Transparent),- Kind.Pale => (Palette.AccentPale, Palette.AccentText, Brushes.Transparent),- Kind.Subtle => ((Brush)Brushes.Transparent, (Brush)Palette.Ink, (Brush)Brushes.Transparent),- _ => (Palette.Surface, Palette.Ink, Palette.ControlStroke),+ Kind.Primary => (Palette.Ink, Brushes.White),+ Kind.Accent => (Palette.AccentFill, Brushes.White),+ Kind.Danger => (Palette.Danger, Brushes.White),+ Kind.Pale => (Palette.AccentPale, Palette.AccentText),+ Kind.Subtle => ((Brush)Brushes.Transparent, (Brush)Palette.Ink),+ _ => (Palette.Mica, Palette.Ink),};var content = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center };- if (icon is not null) content.Children.Add(Icon(icon, kind == Kind.Accent && height >= 48 ? 20 : 16, fg, iconFill));- var text = new TextBlock { Text = label, FontSize = height >= 48 ? 16 : 14, FontWeight = kind is Kind.Standard or Kind.Subtle ? FontWeights.Normal : FontWeights.SemiBold, FontFamily = Palette.Font, VerticalAlignment = VerticalAlignment.Center, Foreground = fg };+ if (icon is not null) content.Children.Add(Icon(icon, height >= 48 ? 20 : 16, fg, iconFill));+ var text = new TextBlock { Text = label, FontSize = height >= 48 ? 16 : 14, FontWeight = kind == Kind.Subtle ? FontWeights.Normal : FontWeights.SemiBold, FontFamily = Palette.Font, VerticalAlignment = VerticalAlignment.Center, Foreground = fg };if (icon is not null) text.Margin = new Thickness(8, 0, 0, 0);content.Children.Add(text);var b = new Button{- Content = content, Foreground = fg, Background = bg, BorderBrush = border, BorderThickness = new Thickness(kind == Kind.Standard ? 1 : 0),- Height = height, Padding = new Thickness(14, 0, 14, 0), Cursor = Cursors.Hand, MinWidth = height >= 36 ? 80 : 0,- // The Fluent theme left-aligns buttons; ours fill their slot unless a caller says otherwise.+ Content = content, Foreground = fg, Background = bg, BorderThickness = new Thickness(0),+ Height = height, Padding = new Thickness(16, 0, 16, 0), Cursor = Cursors.Hand, MinWidth = height >= 36 ? 72 : 0,HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Center,};- b.Template = Template(kind is Kind.Standard or Kind.Subtle);+ b.Template = Template(kind is Kind.Standard or Kind.Subtle, radius: height >= 44 ? 12 : 10, soft: kind == Kind.Standard);b.Click += (_, _) => onClick();AutomationName(b, label);return b;@@ -174,7 +181,7 @@ static class UiContent = Icon(icon, iconSize, color ?? Palette.Body, fill), Width = size, Height = size, Background = Brushes.Transparent,BorderThickness = new Thickness(0), Cursor = Cursors.Hand, ToolTip = name,};- b.Template = Template(plain: true, onDark: onDark);+ b.Template = Template(plain: true, onDark: onDark, radius: 10);b.Click += (_, _) => onClick();AutomationName(b, name);return b;@@ -183,11 +190,11 @@ static class Uistatic void AutomationName(UIElement e, string name) => System.Windows.Automation.AutomationProperties.SetName(e, name);/// Rounded, no Windows 7 chrome. Plain buttons get a grey wash on hover; filled ones dim a little.- static ControlTemplate Template(bool plain, bool onDark = false, Type? target = null)+ static ControlTemplate Template(bool plain, bool onDark = false, Type? target = null, double radius = 10, bool soft = false){var t = new ControlTemplate(target ?? typeof(Button));var border = new FrameworkElementFactory(typeof(Border), "bg");- border.SetValue(Border.CornerRadiusProperty, new CornerRadius(4));+ border.SetValue(Border.CornerRadiusProperty, new CornerRadius(radius));border.SetBinding(Border.BackgroundProperty, new System.Windows.Data.Binding("Background") { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent });border.SetBinding(Border.BorderBrushProperty, new System.Windows.Data.Binding("BorderBrush") { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent });border.SetBinding(Border.BorderThicknessProperty, new System.Windows.Data.Binding("BorderThickness") { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent });@@ -201,9 +208,10 @@ static class Uivar pressed = new Trigger { Property = ButtonBase.IsPressedProperty, Value = true };if (plain){- var wash = onDark ? new SolidColorBrush(Color.FromArgb(0x26, 0xFF, 0xFF, 0xFF)) : (Brush)Palette.Subtle;+ // A soft button darkens to the line grey; a subtle one gets the ground's fill.+ var wash = onDark ? new SolidColorBrush(Color.FromArgb(0x26, 0xFF, 0xFF, 0xFF)) : soft ? Palette.Line : (Brush)Palette.Mica;hover.Setters.Add(new Setter(Border.BackgroundProperty, wash, "bg"));- pressed.Setters.Add(new Setter(Border.BackgroundProperty, onDark ? new SolidColorBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0xFF)) : Palette.Selected, "bg"));+ pressed.Setters.Add(new Setter(Border.BackgroundProperty, onDark ? new SolidColorBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0xFF)) : Palette.Line, "bg"));}else{@@ -256,14 +264,41 @@ static class Ui/// A small pill: 对方可见 and the like.public static Border Badge(string text, Brush? bg = null, Brush? fg = null) => new(){- Background = bg ?? Palette.AccentPale, CornerRadius = new CornerRadius(10), Padding = new Thickness(8, 2, 8, 3), VerticalAlignment = VerticalAlignment.Center,+ Background = bg ?? Palette.AccentPale, CornerRadius = new CornerRadius(9), Padding = new Thickness(9, 3, 9, 4), VerticalAlignment = VerticalAlignment.Center,Child = Text(text, 12, fg ?? Palette.AccentText, FontWeights.SemiBold, wrap: false),};+ /// Room around a floating window's card for its shadow.+ public const double ShadowRoom = 14;++ /// A floating window's surface as on the Mac: 16-point corners and a soft shadow. The shadow is+ /// a few translucent rings, not a blur effect: a blur is redrawn in software on every change.+ public static FrameworkElement Floating(UIElement content, Brush background, double radius = 16, bool dark = false)+ {+ var grid = new Grid { Margin = new Thickness(ShadowRoom - 6, ShadowRoom - 4, ShadowRoom - 6, ShadowRoom - 8) };+ double[] alphas = dark ? [0.05, 0.07, 0.10, 0.14] : [0.015, 0.025, 0.04, 0.06];+ for (int i = 0; i < alphas.Length; i++)+ {+ var spread = alphas.Length - i;+ grid.Children.Add(new Border+ {+ CornerRadius = new CornerRadius(radius + spread), Margin = new Thickness(-spread + 6, -spread + 4 + 1, -spread + 6, -spread + 8 - 3),+ Background = new SolidColorBrush(Color.FromArgb((byte)(alphas[i] * 255), 0, 0, 0)),+ });+ }+ grid.Children.Add(new Border+ {+ Background = background, CornerRadius = new CornerRadius(radius), Margin = new Thickness(6, 4, 6, 8),+ BorderBrush = dark ? new SolidColorBrush(Color.FromArgb(0x14, 0xFF, 0xFF, 0xFF)) : Palette.Line, BorderThickness = new Thickness(1),+ Child = content,+ });+ return grid;+ }+public static Border Card(UIElement child, Thickness? padding = null, Brush? bg = null) => new(){- Background = bg ?? Palette.Surface, BorderBrush = Palette.Stroke, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(8),- Padding = padding ?? new Thickness(16), Child = child,+ Background = bg ?? Palette.Surface, BorderBrush = Palette.Line, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(16),+ Padding = padding ?? new Thickness(20), Child = child,};public enum Severity { Error, Warning }@@ -288,37 +323,33 @@ static class Uidock.Children.Add(text);return new Border{- Background = error ? Palette.ErrorBg : Palette.WarnBg, BorderBrush = error ? Palette.ErrorStroke : Palette.WarnStroke,- BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(6), Padding = new Thickness(14, 12, 12, 12), Child = dock,+ Background = error ? Palette.ErrorBg : Palette.WarnBg, BorderThickness = new Thickness(0),+ CornerRadius = new CornerRadius(12), Padding = new Thickness(14, 12, 12, 12), Child = dock,};}- /// The Windows 11 toggle switch (role switch), with 开/关 beside it as Settings does.+ /// The Mac's switch: an ink track when on, a grey one when off, a white knob; no 开/关 beside it.public static FrameworkElement Switch(bool on, Action<bool> changed, string name){- var state = Text(on ? L("开") : L("关"), 13, Palette.Body, wrap: false);- var knob = new Ellipse { Width = 12, Height = 12 };- var track = new Border { Width = 40, Height = 20, CornerRadius = new CornerRadius(10), BorderThickness = new Thickness(1), Child = knob, Padding = new Thickness(3, 0, 3, 0) };+ var knob = new Ellipse { Width = 18, Height = 18, Fill = Brushes.White, Effect = new System.Windows.Media.Effects.DropShadowEffect { BlurRadius = 3, ShadowDepth = 1, Opacity = 0.25 } };+ var track = new Border { Width = 38, Height = 22, CornerRadius = new CornerRadius(11), Child = knob, Padding = new Thickness(2) };void Paint(bool v){- track.Background = v ? Palette.Ink : Palette.Surface;- track.BorderBrush = v ? Palette.Ink : Palette.Secondary;- knob.Fill = v ? Brushes.White : Palette.Secondary;+ track.Background = v ? Palette.Ink : Palette.Toggle;knob.HorizontalAlignment = v ? HorizontalAlignment.Right : HorizontalAlignment.Left;- state.Text = v ? L("开") : L("关");}Paint(on);- var toggle = new ToggleButton { IsChecked = on, Content = track, Background = Brushes.Transparent, BorderThickness = new Thickness(0), Cursor = Cursors.Hand, Padding = new Thickness(0) };- toggle.Template = Template(plain: false, target: typeof(ToggleButton));+ var toggle = new ToggleButton { IsChecked = on, Content = track, Background = Brushes.Transparent, BorderThickness = new Thickness(0), Cursor = Cursors.Hand, Padding = new Thickness(0), VerticalAlignment = VerticalAlignment.Center };+ toggle.Template = Template(plain: false, target: typeof(ToggleButton), radius: 11);toggle.Click += (_, _) => { var v = toggle.IsChecked == true; Paint(v); changed(v); };AutomationName(toggle, name);- return Row(12, state, toggle);+ return toggle;}/// A segmented control: one choice of a few, the chosen one raised on a grey track.public static FrameworkElement Segmented(IEnumerable<(string value, string label)> options, string selected, Action<string> changed){- var track = new Border { Background = Palette.Subtle, CornerRadius = new CornerRadius(6), Padding = new Thickness(2) };+ var track = new Border { Background = Palette.Mica, CornerRadius = new CornerRadius(10), Padding = new Thickness(3) };var row = new StackPanel { Orientation = Orientation.Horizontal };track.Child = row;var buttons = new List<(Button b, string v)>();@@ -328,15 +359,15 @@ static class Ui{var on = value == v;b.Background = on ? Palette.Surface : Brushes.Transparent;- b.Effect = on ? new System.Windows.Media.Effects.DropShadowEffect { BlurRadius = 3, ShadowDepth = 1, Opacity = 0.15 } : null;+ b.Effect = on ? new System.Windows.Media.Effects.DropShadowEffect { BlurRadius = 4, ShadowDepth = 1, Opacity = 0.10 } : null;((TextBlock)b.Content).FontWeight = on ? FontWeights.SemiBold : FontWeights.Normal;((TextBlock)b.Content).Foreground = on ? Palette.Ink : Palette.Body;}}foreach (var (value, label) in options){- var b = new Button { Content = Text(label, 13, Palette.Body, wrap: false), Height = 30, Padding = new Thickness(12, 0, 12, 0), BorderThickness = new Thickness(0), Cursor = Cursors.Hand };- b.Template = Template(plain: false);+ var b = new Button { Content = Text(label, 13, Palette.Body, wrap: false), Height = 30, Padding = new Thickness(14, 0, 14, 0), BorderThickness = new Thickness(0), Cursor = Cursors.Hand };+ b.Template = Template(plain: false, radius: 8);b.Click += (_, _) => { Paint(value); changed(value); };buttons.Add((b, value));row.Children.Add(b);@@ -363,16 +394,68 @@ static class Uireturn row;}- public static ComboBox Choice(IEnumerable<(string value, string label)> options, string selected, Action<string> changed, double width = 200)+ /// A pop-up button, as the Mac's pickers: the chosen value on a soft fill with a chevron, and a+ /// menu of the choices, the chosen one checked. (Windows' own combo box looks out of place here.)+ public static Button Choice(IEnumerable<(string value, string label)> options, string selected, Action<string> changed, double width = 200){- var box = new ComboBox { Width = width, FontFamily = Palette.Font, FontSize = 13, VerticalAlignment = VerticalAlignment.Center };- foreach (var (value, label) in options)+ var list = options.ToList();+ var label = Text(list.FirstOrDefault(o => o.value == selected).label ?? "", 14, Palette.Ink, FontWeights.SemiBold, wrap: false);+ var chevron = Icon(Icons.Chevron, 14, Palette.Secondary, stroke: 1.8);+ var dock = new DockPanel { LastChildFill = true };+ DockPanel.SetDock(chevron, Dock.Right);+ chevron.Margin = new Thickness(8, 0, 0, 0);+ label.HorizontalAlignment = HorizontalAlignment.Left;+ dock.Children.Add(chevron); dock.Children.Add(label);+ var b = new Button+ {+ Content = dock, Width = width, Height = 34, Padding = new Thickness(12, 0, 10, 0), Background = Palette.Mica, BorderThickness = new Thickness(0),+ Cursor = Cursors.Hand, HorizontalContentAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center,+ };+ b.Template = Template(plain: true, radius: 10, soft: true);+ var current = selected;+ b.Click += (_, _) =>{- var item = new ComboBoxItem { Content = label, Tag = value };- box.Items.Add(item);- if (value == selected) box.SelectedItem = item;+ var menu = new ContextMenu { PlacementTarget = b, Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom, FontFamily = Palette.Font, MinWidth = width };+ foreach (var (value, text) in list)+ {+ var item = new MenuItem { Header = text, IsCheckable = true, IsChecked = value == current };+ item.Click += (_, _) => { current = value; label.Text = text; changed(value); };+ menu.Items.Add(item);+ }+ menu.IsOpen = true;+ };+ AutomationName(b, label.Text);+ return b;+ }++ /// A text field as on the Mac: white, 10-point corners, a light line, generous padding.+ public static Border Field(Control box) => FieldFrame(StyleField(box), box);++ /// The frame alone, around anything (a field with a button inside it); `focus` lights it.+ public static Border FieldFrame(UIElement child, Control? focus = null)+ {+ var border = new Border { Background = Brushes.White, BorderBrush = Palette.FieldLine, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(10), Height = 40, Padding = new Thickness(12, 0, 12, 0), Child = child };+ if (focus is not null)+ {+ focus.GotKeyboardFocus += (_, _) => border.BorderBrush = Palette.Ink;+ focus.LostKeyboardFocus += (_, _) => border.BorderBrush = Palette.FieldLine;}- box.SelectionChanged += (_, _) => { if (box.SelectedItem is ComboBoxItem { Tag: string v }) changed(v); };+ return border;+ }++ /// The text control itself, without Windows' frame.+ public static Control StyleField(Control box)+ {+ box.BorderThickness = new Thickness(0);+ box.Background = Brushes.Transparent;+ box.FontSize = 14;+ box.FontFamily = Palette.Font;+ box.Padding = new Thickness(0);+ box.VerticalContentAlignment = VerticalAlignment.Center;+ box.FocusVisualStyle = null;+ var host = new FrameworkElementFactory(typeof(ScrollViewer), "PART_ContentHost");+ host.SetValue(ScrollViewer.VerticalAlignmentProperty, VerticalAlignment.Center);+ box.Template = new ControlTemplate(box.GetType()) { VisualTree = host };return box;}@@ -401,5 +484,18 @@ static class AppIconcatch { return null; }}- public static Image Small(double size = 16) => new() { Source = Image, Width = size, Height = size, VerticalAlignment = VerticalAlignment.Center };+ /// The icon at `size`, from the .ico's largest frame (its first is 16 px and blurs when scaled up).+ public static Image Small(double size = 16) { var i = new Image { Source = size > 20 ? Large ?? Image : Image, Width = size, Height = size, VerticalAlignment = VerticalAlignment.Center }; RenderOptions.SetBitmapScalingMode(i, BitmapScalingMode.HighQuality); return i; }++ static readonly System.Windows.Media.Imaging.BitmapSource? Large = LoadLarge();++ static System.Windows.Media.Imaging.BitmapSource? LoadLarge()+ {+ try+ {+ var d = System.Windows.Media.Imaging.BitmapDecoder.Create(new Uri("pack://application:,,,/cicada.ico"), System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad);+ return d.Frames.OrderByDescending(f => f.PixelWidth).First();+ }+ catch { return null; }+ }}