Fletcher: how to apply inset for certain nested objects only?

Hi, I am trying to create a fletcher diagram. It includes a box which encloses two other boxes. These boxes should be inset from the enclosing box at 1em. Now I want to also set some text at the top-left corner of the enclosing box. This text should not be inset.
Is there a solution to this?

This is what I have come up with:

#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge
#diagram(
  node-stroke: 0.5pt,
  spacing: 1em,
  node(enclose: (<2>, <3>), inset: 1em, align(top+left,
  text(size:8pt)[A short description]), name: <1>),
  node((0,4), [Some box], name: <2>),
  edge("-|>"),
  node((0,5), [Some other box], name: <3>),
)

#let node = node.with(shape: rect, corner-radius: 4pt)
#diagram(
  node-stroke: 0.5pt,
  spacing: 1em,
  node(enclose: (<2>, <3>), inset: 1em, name: <1>),
  node((rel: (0, 0), to: <1.north-west>), align(left, text(size:8pt)[A
  description]), inset: 0.1em),
  node((0,4), [Some box], name: <2>),
  edge("-|>"),
  node((0,5), [Some other box], name: <3>),
)

But you can see, both are not ideal. Basically I want the description to just be placed at the top-left of the enclosing box, with no inset.

You could add an additional node that encloses the node <1> with the inset set to 0. I have no idea whether this is actually the best approach though, I have not spent a lot of time working with fletcher so far.

#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge
#let node = node.with(shape: rect, corner-radius: 4pt)

#diagram(
  node-stroke: 0.5pt,
  spacing: 1em,
  node(
    enclose: (<1>,),
    inset: 0em,
    stroke: none,
    align(
      top + left,
      text(size: 8pt)[A short description],
    ),
  ),
  node(
    enclose: (<2>, <3>),
    inset: 1em,
    name: <1>
  ),
  node((0,4), [Some box], name: <2>),
  edge("-|>"),
  node((0,5), [Some other box], name: <3>),
)

A second option would be to use place() instead of align() with the negative inset of the enclosing node applied to dx and dy.

#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge
#let node = node.with(shape: rect, corner-radius: 4pt)

#diagram(
  node-stroke: 0.5pt,
  spacing: 1em,
  node(
    enclose: (<2>, <3>),
    inset: 1em,
    place(
      dx: -1em,
      dy: -1em,
      top + left,
      text(size: 8pt)[A short description],
    ),
    name: <1>
  ),
  node((0,4), [Some box], name: <2>),
  edge("-|>"),
  node((0,5), [Some other box], name: <3>),
)

First of: Thank you very much for your help!

Do you know if there is a way to specify the anchor point of the node I am placing? Then, one could simply use my second approach and specify its anchor to be top-left as well. This would place the box perfectly on the enclosing box.

I used the second proposed solution, as it let me adjust some smaller spacing to the stroke of the enclosing node.
Thank you very much for your help!

Another way is to add negative padding around the text label of the enclosing node.

#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge

#diagram(
  node-stroke: 0.5pt,
  spacing: 1em,
  let label = pad(-1em, text(size:8pt)[A short description]),
  node(enclose: (<2>, <3>), inset: 1.3em, align(top+left, label), name: <1>),
  node((0,4), [Some box], name: <2>),
  edge("-|>"),
  node((0,5), [Some other box], name: <3>),
)

1 Like