Noah Petherbridge
a316bafb12
Move all Doodle source code into the src/ subpackage and move the publicly shareable stuff into lib/, for example lib/ui and lib/render. This cleans up the git root and helps make the Doodle UI library more easily publishable as a separate open source project. Currently both lib/ui and lib/render import one or two things from doodle/src that need to be broken apart.
24 lines
488 B
Go
24 lines
488 B
Go
package ui
|
|
|
|
import "strings"
|
|
|
|
// WidgetTree returns a string representing the tree of widgets starting
|
|
// at a given widget.
|
|
func WidgetTree(root Widget) []string {
|
|
var crawl func(int, Widget) []string
|
|
crawl = func(depth int, node Widget) []string {
|
|
var (
|
|
prefix = strings.Repeat(" ", depth)
|
|
lines = []string{prefix + node.ID()}
|
|
)
|
|
|
|
for _, child := range node.Children() {
|
|
lines = append(lines, crawl(depth+1, child)...)
|
|
}
|
|
|
|
return lines
|
|
}
|
|
|
|
return crawl(0, root)
|
|
}
|