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

View File

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

View File

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

View File

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

View File

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