Skip to content

Add tests, safer rewrite#1

Merged
detri merged 6 commits intomasterfrom
testing-and-workflow
Jul 19, 2025
Merged

Add tests, safer rewrite#1
detri merged 6 commits intomasterfrom
testing-and-workflow

Conversation

@detri
Copy link
Copy Markdown
Owner

@detri detri commented Jul 19, 2025

  • Swap to a safer pattern for Node ownership, where the Layout will act as the sole factory and owner of Nodes/Contexts and clean them up for you.

  • Note about design choices regarding lifetimes: The Layout must outlive Nodes unless destroyNode has been called, in which case all instances of Node with the same internal reference become invalid, and using them becomes undefined behavior. You can still easily use invalid references without care if your UI changes the tree structure at runtime! For example, ChildRanges are intended to be ephemeral, and you should not add or remove children while iterating. Hanging on to references to nodes you may delete later is a bad idea and an easy way to encounter an assertion, or worse, a crash. Have a plan to clean them up if you remove them - Yoga is intended to be used as a C-like API, so some diligence is still required (but not as much). View "Node" instances as dumb pointers that act like references and "Layout" as the source of truth for node and context lifetimes that will clean up created nodes and their contexts for you.

  • This PR also adds a GTest suite, which consist mostly of sanity checks, since this library doesn't add much besides safer context access and more convenient cleanup.

  • Update docs to reflect API changes

@detri detri self-assigned this Jul 19, 2025
@detri detri added the enhancement New feature or request label Jul 19, 2025
@detri detri merged commit 35dc584 into master Jul 19, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant