Forge
csharpdeeb25a2
1#nullable enable
2
3using SkiaSharp;
4
5namespace CascadeIDE.Views.Chat.Skia;
6
7/// <summary>
8/// Prose + attach-chip в одной строке, когда хватает ширины (маркер не на отдельной строке).
9/// </summary>
10internal static class SkiaChatFeedInlineAttachLayout
11{
12 public const float Gap = 6f;
13
14 public static bool TryMeasurePair(
15 string proseText,
16 string chipLabel,
17 string? anchorShortId,
18 float bodyColumnWidth,
19 in SkiaChatFeedLayout layout,
20 in SkiaChatBubbleSpec proseSpec,
21 out float proseBlockWidth,
22 out float rowHeight)
23 {
24 proseBlockWidth = 0f;
25 rowHeight = 0f;
26 if (string.IsNullOrEmpty(proseText)
27 || proseText.Contains('\n', StringComparison.Ordinal)
28 || proseText.Contains('\r', StringComparison.Ordinal))
29 {
30 return false;
31 }
32
33 using var font = SkiaChatFeedFontResolver.CreateFont(layout.ProseFamily, layout.ProseFontSize);
34 var proseIntrinsicW = font.MeasureText(proseText);
35 proseBlockWidth = proseIntrinsicW + layout.TextInset * 2f;
36
37 var narrowMaxChars = layout.MaxCharsForWidth(proseBlockWidth);
38 var narrowCtx = new SkiaChatMeasureContext(narrowMaxChars, proseBlockWidth);
39 var metrics = SkiaChatBubbleRenderer.Measure(narrowCtx, proseSpec);
40 if (metrics.ContentLines.Count > 1)
41 return false;
42
43 var proseH = SkiaChatBubbleRenderer.MeasureHeight(proseSpec, metrics);
44 if (metrics.RichTextBody is { } rich
45 && rich.BodyHeight > layout.ProseLineHeight * 1.35f)
46 {
47 return false;
48 }
49
50 if (proseH > layout.ProseLineHeight * 1.35f)
51 return false;
52
53 var chipH = SkiaIntercomAttachLinkChip.MeasureHeight(layout.ForwardHost, layout.AttachChipFontSize);
54 var chipW = SkiaIntercomAttachLinkChip.MeasureIntrinsicWidth(
55 chipLabel,
56 anchorShortId,
57 layout.AttachChipFontSize,
58 layout.ChipFamily,
59 layout.ChipIdFamily);
60 if (proseBlockWidth + Gap + chipW > bodyColumnWidth + 0.5f)
61 return false;
62
63 rowHeight = Math.Max(proseH, chipH);
64 return true;
65 }
66
67 public static float ChipTop(float rowTop, float rowHeight, float chipHeight) =>
68 rowTop + (rowHeight - chipHeight) * 0.5f;
69}
70
View only · write via MCP/CIDE