cogentcore / core

A free and open source framework for building powerful, fast, and elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the Web with a single pure Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.31k stars 71 forks source link

Clean up the tree.Node interface and remove tree.Slice #975

Closed kkoreilly closed 2 weeks ago

kkoreilly commented 2 weeks ago

This PR restructures the tree.Node interface to only contain methods that actually need to be overridden by higher-level types. This vastly simplifies the tree code and allows for proper field-based access with full names for things such as Name, This, Parent, Children, and Properties. This resolves a major issue that has plagued the codebase for six years, wherein many fields are stuck with terrible names like Nm, Ths, Par, Kids, and Props to avoid naming conflicts with methods required for an interface.

Also, this PR removes the highly problematic tree.Slice type and replaces it with standard []Node objects powered by modular global functions instead of the previous bloated approach that manually redefined every last aspect of slice functionality (which was more necessary previously due to the lack of a standard library generic slices package, but is completely irrelevant now).

Furthermore, these tree slice changes forced a long overdue rewrite of tree JSON i/o support, which makes the system much more rational, consistent internally and with other packages, easy to use, and space-efficient. I also added omitempty struct tags to various fields and stopped indenting JSON in various places, resulting in even more massive size reductions of JSON files.

Finally, over the course of these changes, I was able to clean up various other poorly structured things and create better abstractions like the new slicesx package. I am also planning to rewrite the core.Widget interface and other interfaces such as those contained in svg and xyz under this new paradigm in new PRs soon.