From ab1386e72116c9064239371c7642eee32c6d7dd9 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sat, 9 Nov 2024 14:41:44 +0100 Subject: [PATCH] added comment wrapping if width is restricted --- src/sequence.typ | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/sequence.typ b/src/sequence.typ index 089e6b5..4c20ae1 100644 --- a/src/sequence.typ +++ b/src/sequence.typ @@ -100,19 +100,27 @@ y -= Y-SPACE + let i1 = pars-i.at(elmt.p1) + let i2 = pars-i.at(elmt.p2) + let width = calc.abs(x-pos.at(i1) - x-pos.at(i2)) + let h = 0 + let comment = if elmt.comment == none {none} else { + let w = calc.min(width * 1pt, measure(elmt.comment).width) + box( + width: if i1 == i2 {auto} else {w}, + elmt.comment + ) + } // Reserve space for comment - if elmt.comment != none { - h = calc.max(h, measure(box(elmt.comment)).height / 1pt + 6) + if comment != none { + h = calc.max(h, measure(comment).height / 1pt + 6) } if "linked-note" in elmt { h = calc.max(h, note.get-size(elmt.linked-note).height / 2) } y -= h - let i1 = pars-i.at(elmt.p1) - let i2 = pars-i.at(elmt.p2) - let start-info = ( i: i1, x: x-pos.at(i1), @@ -244,7 +252,7 @@ (x2, end-info.y) ) - if elmt.comment != none { + if comment != none { comment-anchor = ( start: if x-mid < x1 {"south-east"} else {"south-west"}, end: if x-mid < x1 {"south-west"} else {"south-east"}, @@ -268,7 +276,7 @@ (x2, end-info.y) ) - if elmt.comment != none { + if comment != none { let start-pt = pts.first() let end-pt = pts.last() if elmt.start-tip != "" { @@ -348,10 +356,10 @@ shapes += draw.line(..pts, ..style) - if elmt.comment != none { + if comment != none { shapes += draw.content( comment-pt, - elmt.comment, + comment, anchor: comment-anchor, angle: comment-angle, padding: 3pt