added comment wrapping if width is restricted

This commit is contained in:
Louis Heredero 2024-11-09 14:41:44 +01:00
parent 1f155063a8
commit ab1386e721
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7

View File

@ -100,19 +100,27 @@
y -= Y-SPACE 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 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 // Reserve space for comment
if elmt.comment != none { if comment != none {
h = calc.max(h, measure(box(elmt.comment)).height / 1pt + 6) h = calc.max(h, measure(comment).height / 1pt + 6)
} }
if "linked-note" in elmt { if "linked-note" in elmt {
h = calc.max(h, note.get-size(elmt.linked-note).height / 2) h = calc.max(h, note.get-size(elmt.linked-note).height / 2)
} }
y -= h y -= h
let i1 = pars-i.at(elmt.p1)
let i2 = pars-i.at(elmt.p2)
let start-info = ( let start-info = (
i: i1, i: i1,
x: x-pos.at(i1), x: x-pos.at(i1),
@ -244,7 +252,7 @@
(x2, end-info.y) (x2, end-info.y)
) )
if elmt.comment != none { if comment != none {
comment-anchor = ( comment-anchor = (
start: if x-mid < x1 {"south-east"} else {"south-west"}, start: if x-mid < x1 {"south-east"} else {"south-west"},
end: if x-mid < x1 {"south-west"} else {"south-east"}, end: if x-mid < x1 {"south-west"} else {"south-east"},
@ -268,7 +276,7 @@
(x2, end-info.y) (x2, end-info.y)
) )
if elmt.comment != none { if comment != none {
let start-pt = pts.first() let start-pt = pts.first()
let end-pt = pts.last() let end-pt = pts.last()
if elmt.start-tip != "" { if elmt.start-tip != "" {
@ -348,10 +356,10 @@
shapes += draw.line(..pts, ..style) shapes += draw.line(..pts, ..style)
if elmt.comment != none { if comment != none {
shapes += draw.content( shapes += draw.content(
comment-pt, comment-pt,
elmt.comment, comment,
anchor: comment-anchor, anchor: comment-anchor,
angle: comment-angle, angle: comment-angle,
padding: 3pt padding: 3pt