ui/debug.go
Noah Petherbridge 4ba563d48d Supervisor, Frame Pack and Misc Fixes
* Button: do not call MoveTo inside of Compute().
* Label: do not call MoveTo inside of Compute().
* MainWindow: add OnLoop callback function support so you can run custom code
  each loop and react to the event.State before the UI updates.
* Supervisor: locate widgets using AbsolutePosition() instead of w.Point()
  to play nice with Frame and Window packed widgets.
* Widget interface: rename Adopt() to SetParent() which makes more sense for
  what the function actually does.
* Window: set itself as the parent of the body Frame so that the Supervisor
  can locate widgets anywhere inside a window's frames.

Frame packing fixes:

* Widgets with Expand:true grow their space with ResizeAuto to preserve the
  FixedSize() boolean, instead of being hard-resized to fill the Frame.
* Widgets that Fill their space are resized with ResizeAuto too.

Outstanding bugs:

* Labels don't expand (window title bars, etc.)
2019-12-29 00:00:03 -08:00

37 lines
722 B
Go

package ui
import (
"fmt"
"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)
size = node.Size()
width = size.W
height = size.H
fixedSize = node.FixedSize()
lines = []string{
fmt.Sprintf("%s%s P:%s S:%dx%d (fixedSize: %+v)",
prefix, node.ID(), node.Point(), width, height, fixedSize,
),
}
)
for _, child := range node.Children() {
lines = append(lines, crawl(depth+1, child)...)
}
return lines
}
return crawl(0, root)
}