Skip to content

Allow anchors outsides groups #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 for the current group. The new anchor will be accessible from inside the group by using just the anchor's name as a coordinate.
///
/// ```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)
})
Loading