Compare commits

4 Commits

5 changed files with 104 additions and 57 deletions

View File

@ -1,32 +1,54 @@
#import "/src/cetz.typ": draw
#import "/src/core/utils.typ": normalize-measure
#import "/src/consts.typ": *
#import "/src/core/utils.typ": normalize-measure, normalize-units
#let name = "actor"
#let render(x, y, p, bottom) = {
let m = measure(p.display-name)
let m = normalize-measure(p.display-name)
let style = p.resolved-style
let w2 = ACTOR-WIDTH / 2
let head-r = ACTOR-WIDTH / 4
let height = ACTOR-WIDTH * 2
let spacing = normalize-units(style.spacing)
let width = normalize-units(style.width)
let height = width * 2
let w2 = width / 2
let head-r = width / 4
let arms-y = height * 0.375
let y0 = if bottom {
y - m.height / 1pt - SYM-GAP
y - m.height - spacing
} else {
y + m.height / 1pt + height + SYM-GAP
y + m.height + height + spacing
}
// Head
draw.circle(
(x, y0 - head-r),
radius: head-r,
fill: style.fill,
stroke: style.stroke
)
draw.line((x, y0 - head-r * 2), (x, y0 - height + w2), stroke: black + .5pt)
draw.line((x - w2, y0 - arms-y), (x + w2, y0 - arms-y), stroke: black + .5pt)
draw.line((x - w2, y0 - height), (x, y0 - height + w2), (x + w2, y0 - height), stroke: black + .5pt)
// Body
draw.line(
(x, y0 - head-r * 2),
(x, y0 - height + w2),
stroke: style.stroke
)
// Arms
draw.line(
(x - w2, y0 - arms-y),
(x + w2, y0 - arms-y),
stroke: style.stroke
)
// Legs
draw.line(
(x - w2, y0 - height),
(x, y0 - height + w2),
(x + w2, y0 - height),
stroke: style.stroke
)
draw.content(
(x, y),
p.display-name,
@ -37,12 +59,17 @@
#let get-size(par) = {
let m = normalize-measure(par.display-name)
//ACTOR-WIDTH * 1pt
//ACTOR-WIDTH * 2pt + SYM-GAP * 1pt + h
let width = normalize-units(par.resolved-style.width)
let height = width * 2
let spacing = normalize-units(par.resolved-style.spacing)
return m
return (
width: calc.max(m.width, width),
height: height + spacing + m.height
)
}
#let default-style = (
:
width: 20pt,
spacing: 5pt
)

View File

@ -1,22 +1,23 @@
#import "/src/cetz.typ": draw
#import "/src/core/utils.typ": normalize-measure
#import "/src/consts.typ": *
#import "/src/core/utils.typ": normalize-measure, normalize-units
#let name = "boundary"
#let render(x, y, p, bottom) = {
let m = measure(p.display-name)
let m = normalize-measure(p.display-name)
let style = p.resolved-style
let circle-r = BOUNDARY-HEIGHT / 2
let height = normalize-units(style.height)
let spacing = normalize-units(style.spacing)
let circle-r = height / 2
let y0 = if bottom {
y - m.height / 1pt - SYM-GAP
y - m.height - spacing
} else {
y + m.height / 1pt + BOUNDARY-HEIGHT + SYM-GAP
y + m.height + height + spacing
}
let x0 = x - BOUNDARY-HEIGHT
let x0 = x - height
let y1 = y0 - circle-r
let y2 = y0 - BOUNDARY-HEIGHT
let y2 = y0 - height
draw.circle(
(x + circle-r, y1),
@ -42,12 +43,17 @@
#let get-size(par) = {
let m = normalize-measure(par.display-name)
// BOUNDARY-HEIGHT * 2pt
// BOUNDARY-HEIGHT * 1pt + SYM-GAP * 1pt + h
let height = normalize-units(par.resolved-style.height)
let width = height * 2
let spacing = normalize-units(par.resolved-style.spacing)
return m
return (
width: calc.max(m.width, width),
height: height + spacing + m.height
)
}
#let default-style = (
:
height: 20pt,
spacing: 5pt
)

View File

@ -1,18 +1,19 @@
#import "/src/cetz.typ": draw
#import "/src/core/utils.typ": normalize-measure
#import "/src/consts.typ": *
#import "/src/core/utils.typ": normalize-measure, normalize-units
#let name = "control"
#let render(x, y, p, bottom) = {
let m = measure(p.display-name)
let m = normalize-measure(p.display-name)
let style = p.resolved-style
let r = CONTROL-HEIGHT / 2
let size = normalize-units(style.size)
let spacing = normalize-units(style.spacing)
let r = size / 2
let y0 = if bottom {
y - m.height / 1pt - SYM-GAP
y - m.height - spacing
} else {
y + m.height / 1pt + CONTROL-HEIGHT + SYM-GAP
y + m.height + size + spacing
}
draw.circle(
@ -22,7 +23,12 @@
stroke: style.stroke
)
let s = stroke(style.stroke)
draw.mark((x, y0), (x - r / 2, y0), symbol: "stealth", fill: s.paint)
draw.mark(
(x, y0), (x - r / 2, y0),
symbol: "stealth",
fill: s.paint,
stroke: s.paint
)
draw.content(
(x, y),
p.display-name,
@ -33,12 +39,16 @@
#let get-size(par) = {
let m = normalize-measure(par.display-name)
// CONTROL-HEIGHT * 1pt
// CONTROL-HEIGHT * 1pt + SYM-GAP * 1pt + h
let size = normalize-units(par.resolved-style.size)
let spacing = normalize-units(par.resolved-style.spacing)
return m
return (
width: calc.max(m.width, size),
height: size + spacing + m.height
)
}
#let default-style = (
:
size: 20pt,
spacing: 5pt
)

View File

@ -1,32 +1,40 @@
#import "/src/cetz.typ": draw
#import "/src/core/utils.typ": normalize-measure
#import "/src/consts.typ": *
#import "/src/core/utils.typ": normalize-measure, normalize-units
#let name = "custom"
#let render(x, y, p, bottom) = {
let m = measure(p.display-name)
let style = p.resolved-style
let image-m = measure(style.custom-image)
let y0 = if bottom {y - m.height / 1pt - SYM-GAP} else {y + m.height / 1pt + image-m.height / 1pt + SYM-GAP}
draw.content((x - image-m.width / 2pt, y0), style.custom-image, anchor: "north-west")
let shape = align(
center,
stack(
dir: ttb,
spacing: normalize-units(style.spacing) * 1pt,
style.image,
p.display-name
)
)
let anchor = if bottom {"north"} else {"base"}
draw.content(
(x, y),
p.display-name,
anchor: if bottom {"north"} else {"base"}
shape,
anchor: anchor
)
}
#let get-size(par) = {
let m = normalize-measure(par.display-name)
let name-m = normalize-measure(par.display-name)
let img-m = normalize-measure(par.resolved-style.image)
let spacing = normalize-units(par.resolved-style.spacing)
// measure(style.custom-image).width
// measure(style.custom-image).height + SYM-GAP * 1pt + h
return m
return (
width: calc.max(name-m.width, img-m.width),
height: name-m.height + spacing + img-m.height
)
}
#let default-style = (
:
image: none,
spacing: 5pt
)

View File

@ -13,11 +13,7 @@
fill: style.fill,
stroke: style.stroke
)
let anchor = if bottom {
"north"
} else {
"base"
}
let anchor = if bottom {"north"} else {"base"}
draw.content(
(x, y),
name,