Forge
csharpdeeb25a2
1#nullable enable
2using SkiaSharp;
3
4namespace CascadeIDE.Views.Chat.Skia;
5
6/// <summary>Универсальная Skia-сущность на базе <see cref="SkiaChatBubbleSpec"/> (без дублирования Measure/Draw).</summary>
7internal sealed class SkiaChatBubbleEntity : ISkiaChatEntity
8{
9 private readonly SkiaChatBubbleSpec _spec;
10 private readonly Func<SkiaChatHit?> _createHit;
11
12 public SkiaChatBubbleEntity(SkiaChatBubbleSpec spec, Func<SkiaChatHit?> createHit)
13 {
14 _spec = spec;
15 _createHit = createHit;
16 }
17
18 public SkiaChatMeasuredLayout Measure(SkiaChatMeasureContext context)
19 {
20 var metrics = SkiaChatBubbleRenderer.Measure(context, _spec);
21 return new SkiaChatMeasuredLayout(
22 SkiaChatBubbleRenderer.MeasureHeight(_spec, metrics),
23 _spec.GapAfter,
24 Bubble: metrics);
25 }
26
27 public void Draw(SkiaChatDrawContext context, float top, in SkiaChatMeasuredLayout layout)
28 {
29 var rect = new SKRect(context.ContentLeft, top, context.ContentLeft + context.ContentWidth, top + layout.Height);
30 SkiaChatBubbleRenderer.Draw(context, rect, _spec, layout.Bubble!.Value);
31 }
32
33 public SkiaChatHit? CreateHit(in SkiaChatMeasuredLayout layout) => _createHit();
34}
35
View only · write via MCP/CIDE