| 1 | #nullable enable |
| 2 | using Avalonia; |
| 3 | using Avalonia.Styling; |
| 4 | using CascadeIDE.Views.SkiaKit; |
| 5 | using SkiaSharp; |
| 6 | |
| 7 | namespace CascadeIDE.Views.Chat; |
| 8 | |
| 9 | internal readonly record struct SkiaChatTheme( |
| 10 | SKColor Surface, |
| 11 | SKColor BubbleAssistant, |
| 12 | SKColor BubbleUser, |
| 13 | SKColor Border, |
| 14 | SKColor HoverBorder, |
| 15 | SKColor SelectedBorder, |
| 16 | SKColor Role, |
| 17 | SKColor Content, |
| 18 | SKColor EmptyHint, |
| 19 | SKColor MutedContent, |
| 20 | SKColor FooterMuted) : ISkiaKitPaintTheme |
| 21 | { |
| 22 | public static SkiaChatTheme DarkFallback => new( |
| 23 | Surface: new SKColor(30, 30, 30), |
| 24 | BubbleAssistant: new SKColor(37, 37, 38), |
| 25 | BubbleUser: new SKColor(42, 48, 58), |
| 26 | Border: new SKColor(63, 63, 65), |
| 27 | HoverBorder: new SKColor(126, 196, 255), |
| 28 | SelectedBorder: new SKColor(196, 146, 255), |
| 29 | Role: new SKColor(181, 196, 230), |
| 30 | Content: new SKColor(223, 228, 236), |
| 31 | EmptyHint: new SKColor(160, 160, 160), |
| 32 | MutedContent: new SKColor(196, 202, 214), |
| 33 | FooterMuted: new SKColor(181, 196, 230)); |
| 34 | |
| 35 | public static SkiaChatTheme Resolve(StyledElement element) |
| 36 | { |
| 37 | var theme = DarkFallback; |
| 38 | if (SkiaKitColor.TrySkColor(element, SkiaKitThemeBridge.Keys.BubbleBackground, out var bubble)) |
| 39 | theme = theme with { BubbleAssistant = bubble }; |
| 40 | if (SkiaKitColor.TrySkColor(element, SkiaKitThemeBridge.Keys.PanelBackground, out var panelBg)) |
| 41 | theme = theme with { Surface = panelBg }; |
| 42 | else if (SkiaKitColor.TrySkColor(element, SkiaKitThemeBridge.Keys.BubbleBackground, out bubble)) |
| 43 | theme = theme with { Surface = SkiaKitColor.Darken(bubble, 0.92f) }; |
| 44 | |
| 45 | if (SkiaKitColor.TrySkColor(element, SkiaKitThemeBridge.Keys.LabelForeground, out var label)) |
| 46 | theme = theme with { Role = label }; |
| 47 | if (SkiaKitColor.TrySkColor(element, SkiaKitThemeBridge.Keys.ContentForeground, out var body)) |
| 48 | theme = theme with { Content = body }; |
| 49 | if (SkiaKitColor.TrySkColor(element, SkiaKitThemeBridge.Keys.ColumnBorder, out var edge)) |
| 50 | { |
| 51 | theme = theme with { Border = edge }; |
| 52 | theme = theme with { BubbleUser = SkiaKitColor.Blend(theme.BubbleAssistant, edge, 0.42f) }; |
| 53 | } |
| 54 | |
| 55 | if (SkiaKitColor.TrySkColor(element, SkiaKitThemeBridge.Keys.Accent, out var accent)) |
| 56 | { |
| 57 | theme = theme with { HoverBorder = accent }; |
| 58 | theme = theme with |
| 59 | { |
| 60 | SelectedBorder = SkiaKitColor.Blend(accent, new SKColor(255, 255, 255), 0.35f) |
| 61 | }; |
| 62 | } |
| 63 | |
| 64 | var muted = SkiaKitColor.Blend(theme.Content, theme.Role, 0.72f); |
| 65 | var footer = SkiaKitColor.Blend(theme.Content, theme.Role, 0.58f); |
| 66 | return theme with |
| 67 | { |
| 68 | MutedContent = muted, |
| 69 | FooterMuted = footer, |
| 70 | EmptyHint = footer |
| 71 | }; |
| 72 | } |
| 73 | } |
| 74 | |