forked from HEL/chronos
		
	restructured code in separated files
This commit is contained in:
		
							
								
								
									
										152
									
								
								src/sequence.typ
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										152
									
								
								src/sequence.typ
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,152 @@ | ||||
| #import "consts.typ": * | ||||
| #import "@preview/cetz:0.2.2": draw | ||||
|  | ||||
| #let _seq( | ||||
|   p1, | ||||
|   p2, | ||||
|   comment: none, | ||||
|   dashed: false, | ||||
|   tip: "default", | ||||
|   color: black, | ||||
|   flip: false, | ||||
|   enable-dst: false, | ||||
|   disable-dst: false, | ||||
|   destroy-dst: false, | ||||
|   disable-src: false, | ||||
|   destroy-src: false, | ||||
| ) = { | ||||
|   return (( | ||||
|     type: "seq", | ||||
|     p1: p1, | ||||
|     p2: p2, | ||||
|     comment: comment, | ||||
|     dashed: dashed, | ||||
|     tip: tip, | ||||
|     color: color, | ||||
|     flip: flip, | ||||
|     enable-dst: enable-dst, | ||||
|     disable-dst: disable-dst, | ||||
|     destroy-dst: destroy-dst, | ||||
|     disable-src: disable-src, | ||||
|     destroy-src: destroy-src, | ||||
|   ),) | ||||
| } | ||||
|  | ||||
| #let render(pars-i, x-pos, elmt, y, lifelines) = { | ||||
|   let shapes = () | ||||
|  | ||||
|   let i1 = pars-i.at(elmt.p1) | ||||
|   let i2 = pars-i.at(elmt.p2) | ||||
|  | ||||
|   if elmt.comment != none { | ||||
|     y -= measure(box(elmt.comment)).height / 1pt + 6 | ||||
|   } | ||||
|  | ||||
|   if elmt.disable-src { | ||||
|     let src-line = lifelines.at(i1) | ||||
|     src-line.level -= 1 | ||||
|     src-line.lines.push(("disable", y, auto)) | ||||
|     lifelines.at(i1) = src-line | ||||
|   } | ||||
|   if elmt.destroy-src { | ||||
|     let src-line = lifelines.at(i1) | ||||
|     src-line.level -= 1 | ||||
|     src-line.lines.push(("destroy", y, auto)) | ||||
|     lifelines.at(i1) = src-line | ||||
|   } | ||||
|  | ||||
|   let ll-lvl1 = lifelines.at(i1).level * LIFELINE-W / 2 | ||||
|  | ||||
|   if elmt.disable-dst { | ||||
|     let dst-line = lifelines.at(i2) | ||||
|     dst-line.level -= 1 | ||||
|     dst-line.lines.push(("disable", y, auto)) | ||||
|     lifelines.at(i2) = dst-line | ||||
|   } | ||||
|   if elmt.destroy-dst { | ||||
|     let dst-line = lifelines.at(i2) | ||||
|     dst-line.level -= 1 | ||||
|     dst-line.lines.push(("destroy", y, auto)) | ||||
|     lifelines.at(i2) = dst-line | ||||
|   } | ||||
|   if elmt.enable-dst { | ||||
|     let dst-line = lifelines.at(i2) | ||||
|     dst-line.level += 1 | ||||
|     lifelines.at(i2) = dst-line | ||||
|   } | ||||
|  | ||||
|   let x1 = x-pos.at(i1) | ||||
|   let x2 = x-pos.at(i2) | ||||
|  | ||||
|   let ll-lvl2 = lifelines.at(i2).level * LIFELINE-W / 2 | ||||
|  | ||||
|   let f = if elmt.flip {-1} else {1} | ||||
|   if i1 <= i2 { | ||||
|     x1 += ll-lvl1 * f | ||||
|     x2 -= ll-lvl2 * f | ||||
|   } else { | ||||
|     x1 -= ll-lvl1 * f | ||||
|     x2 += ll-lvl2 * f | ||||
|   } | ||||
|  | ||||
|   let style = ( | ||||
|     mark: (end: "straight"), | ||||
|     stroke: ( | ||||
|       dash: if elmt.dashed {"dashed"} else {"solid"}, | ||||
|       paint: elmt.color | ||||
|     ) | ||||
|   ) | ||||
|  | ||||
|   if elmt.p1 == elmt.p2 { | ||||
|     let x3 = x1 - ll-lvl1 + ll-lvl2 | ||||
|  | ||||
|     x2 = if elmt.flip {x1 - 20} else {x1 + 20} | ||||
|  | ||||
|     if elmt.comment != none { | ||||
|       shapes += draw.content( | ||||
|         (x1, y), | ||||
|         elmt.comment, | ||||
|         anchor: if elmt.flip {"south-east"} else {"south-west"}, | ||||
|         padding: 3pt | ||||
|       ) | ||||
|     } | ||||
|  | ||||
|     shapes += draw.line( | ||||
|       (x1, y), | ||||
|       (x2, y), | ||||
|       (x2, y - 10), | ||||
|       (x3, y - 10), | ||||
|       ..style | ||||
|     ) | ||||
|     y -= 10 | ||||
|  | ||||
|   } else { | ||||
|     if elmt.comment != none { | ||||
|       let x = calc.min(x1, x2) | ||||
|       if x2 < x1 { | ||||
|         x += COMMENT-PAD | ||||
|       } | ||||
|       shapes += draw.content( | ||||
|         (x, y), | ||||
|         elmt.comment, | ||||
|         anchor: "south-west", | ||||
|         padding: 3pt | ||||
|       ) | ||||
|     } | ||||
|  | ||||
|     shapes += draw.line( | ||||
|       (x1, y), | ||||
|       (x2, y), | ||||
|       ..style | ||||
|     ) | ||||
|   } | ||||
|   if elmt.enable-dst { | ||||
|     let dst-line = lifelines.at(i2) | ||||
|     dst-line.lines.push(("enable", y, auto)) | ||||
|     lifelines.at(i2) = dst-line | ||||
|   } | ||||
|   y -= Y-SPACE | ||||
|  | ||||
|   let r = (y, lifelines, shapes) | ||||
|   return r | ||||
| } | ||||
		Reference in New Issue
	
	Block a user