codly.bubble
A pointed callout bubble rendered next to a source line, with independent defaults for its paint, dimensions, spacing, and pointer.
Signature
// A codly pointed callout bubble.
codly.bubble(
body,
gap: 0.5em,
pointer-align: "center",
pointer-size: 0.4em,
pointer-height: auto,
pointer-width: auto,
pointer-offset: 0pt,
align: center,
fill: luma(245),
stroke: 0.6pt + luma(80),
inset: (x: 0.5em, y: 0.3em),
outset: 0pt,
radius: 2pt,
width: auto,
line: int,
pointer: int,
placement: "below"
)
codly.bubble is the generated element type for pointed callouts. Its body is positional; line and pointer are required named fields when representing the element directly. In normal use, create bubbles by setting pointer on a callouts entry.
Fields
| Field | Type | Default / required | Meaning |
|---|---|---|---|
body |
content |
Required, positional | Content displayed inside the bubble. |
gap |
length | dictionary |
0.5em |
Minimum horizontal and vertical separation between bubbles. A length sets both axes; omitted dictionary axes use 0.5em. |
pointer-align |
"start" | "center" | "end" |
"center" |
Preferred alignment of the bubble around its source character, clamped to the available row. |
pointer-size |
length |
0.4em |
Default arrow height and half-base width. |
pointer-height |
length | auto |
auto |
Arrow height; auto uses pointer-size. |
pointer-width |
length | auto |
auto |
Full arrow base width; auto uses twice pointer-size. |
pointer-offset |
length |
0pt |
Horizontal tip shift from the source character; positive moves right, negative moves left. Clamped to the bubble without moving its body. |
align |
alignment |
center |
Alignment of content inside the bubble, independent of grid cell alignment. |
fill |
none | paint |
luma(245) |
Fill shared by the bubble body and pointer. |
stroke |
none | stroke |
0.6pt + luma(80) |
Stroke around the single bubble and pointer outline. |
inset |
length | dictionary |
(x: 0.5em, y: 0.3em) |
Padding inside the bubble body. |
outset |
length | dictionary |
0pt |
Additional painted extent around the padded body, reserved in the row. |
radius |
length |
2pt |
Corner radius of the bubble body. |
width |
length | ratio | auto |
auto |
Preferred padded body width; auto fits the content within the available row. |
line |
int |
Required, named | One-based source line to which the bubble is attached. |
pointer |
int |
Required, named | One-based source character anchor; zero selects the line start. |
placement |
"above" | "below" |
"below" |
Whether the bubble appears above or below its source line. |
Behavior
The bubble and arrow use one outline and fill. Content wraps at the available width. Negative dimensions, pointer sizes, insets, and outsets are rejected. Styling defaults set on codly.bubble are inherited by generated bubbles; explicit codly.callout settings and then entry-level bubble settings take precedence. A callout with pointer: none does not produce a bubble.
Rules
codly.bubble-set_(..args) sets styling defaults for generated bubbles. codly.bubble-show_(it, ..args) installs a show rule for generated bubbles; its first argument is replacement content or a callback.
Example: Basic Usage
#import "@preview/codly:2.0.0" as codly
#show: codly.bubble-set_(fill: aqua.lighten(75%), radius: 6pt, width: 125pt)
#codly.new(
```js
let total = subtotal + tax
```,
callouts: ((
line: 1,
pointer: pointer,
body: [The final amount includes tax.],
),),
)
Edit & run on your device
The controls supply the example variables. Their definitions are hidden here; Copy code includes the current values and your edits.
Example: Custom Show Rule
#import "@preview/codly:2.0.0" as codly
#show: codly.bubble-show_(it => {
let fields = codly.e.fields(it)
box(stroke: red, inset: 2pt, fields.body)
})
#codly.new(
```js
let total = subtotal + tax
```,
callouts: ((
line: 1,
pointer: 17,
body: [The final amount includes tax.],
),),
)
Edit & run on your device
The highlighted source and output update after you stop typing. Copy code includes your edits.