Skip to content

Commit b334fef

Browse files
Allow anchors outsides groups (#679)
* Allow anchors outsides groups * Update grouping.typ Change back text.
1 parent 74bd0d4 commit b334fef

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/draw/grouping.typ

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,24 @@
337337
)
338338
},)
339339

340-
/// Creates a new anchor for the current group. This element can only be used inside a group otherwise it will panic. The new anchor will be accessible from inside the group by using just the anchor's name as a coordinate.
340+
/// Creates a new anchor for the current group. The new anchor will be accessible from inside the group by using just the anchor's name as a coordinate.
341341
///
342342
/// ```typc example
343-
/// // Create group
343+
/// // Inside a group
344344
/// group(name: "g", {
345345
/// circle((0,0))
346346
/// anchor("x", (.4, .1))
347347
/// circle("x", radius: .2)
348348
/// })
349349
/// circle("g.x", radius: .1)
350350
/// ```
351+
352+
/// ```typc example
353+
/// // At the root scope
354+
/// anchor("x", (1, 1))
355+
/// // ...
356+
/// circle("x", radius: .1)
357+
/// ```
351358
///
352359
/// - name (str): The name of the anchor
353360
/// - position (coordinate): The position of the anchor
@@ -357,10 +364,6 @@
357364

358365
coordinate.resolve-system(position)
359366
return (ctx => {
360-
assert(
361-
ctx.groups.len() > 0,
362-
message: "Anchor '" + name + "' created outside of group!",
363-
)
364367
let (ctx, position) = coordinate.resolve(ctx, position)
365368
position = util.apply-transform(ctx.transform, position)
366369
return (

tests/anchor/root/ref/1.png

3.25 KB
Loading

tests/anchor/root/test.typ

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#set page(width: auto, height: auto)
2+
#import "/src/lib.typ": *
3+
#import "/tests/helper.typ": *
4+
5+
#test-case({
6+
import draw: *
7+
8+
anchor("test", (1, 1))
9+
circle((1,1))
10+
11+
translate((3,1))
12+
circle("test", radius: .5, stroke: green)
13+
circle((1,1), radius: .5, stroke: red)
14+
})

0 commit comments

Comments
 (0)