Skip to content

Commit

Permalink
Allow anchors outsides groups
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Aug 11, 2024
1 parent 035a667 commit 961760f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/draw/grouping.typ
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,24 @@
)
},)

/// 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.
/// Creates a new anchor.
///
/// ```typc example
/// // Create group
/// // Inside a group
/// group(name: "g", {
/// circle((0,0))
/// anchor("x", (.4, .1))
/// circle("x", radius: .2)
/// })
/// circle("g.x", radius: .1)
/// ```
/// ```typc example
/// // At the root scope
/// anchor("x", (1, 1))
/// // ...
/// circle("x", radius: .1)
/// ```
///
/// - name (str): The name of the anchor
/// - position (coordinate): The position of the anchor
Expand All @@ -357,10 +364,6 @@

coordinate.resolve-system(position)
return (ctx => {
assert(
ctx.groups.len() > 0,
message: "Anchor '" + name + "' created outside of group!",
)
let (ctx, position) = coordinate.resolve(ctx, position)
position = util.apply-transform(ctx.transform, position)
return (
Expand Down
Binary file added tests/anchor/root/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions tests/anchor/root/test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#set page(width: auto, height: auto)
#import "/src/lib.typ": *
#import "/tests/helper.typ": *

#test-case({
import draw: *

anchor("test", (1, 1))
circle((1,1))

translate((3,1))
circle("test", radius: .5, stroke: green)
circle((1,1), radius: .5, stroke: red)
})

0 comments on commit 961760f

Please sign in to comment.