Noah Petherbridge
07cefb6499
* New and completed widgets: Menu, MenuButton and MenuBar. * MenuButton is a kind of Button that opens a popup Menu when clicked. * MenuBar is a container of buttons designed to be attached to the top of an application window ("File, Edit, View, Help") * Supervisor manages the popup menus with its new concept of a Modal Widget. Modal widgets take exclusive event priority for all mouse and key events. The pop-up menu is a modal window, which means you must click an option inside the menu OR clicking outside the menu will close it and eat your click event (widgets outside the modal don't receive events, but the modal itself gets an event that you've done this).
45 lines
924 B
Go
45 lines
924 B
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// PrintWidgetTree prints a widget tree to console.
|
|
func PrintWidgetTree(root Widget) {
|
|
fmt.Printf("--- Widget Tree of %s ---\n", root)
|
|
for _, row := range WidgetTree(root) {
|
|
fmt.Println(row)
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
}
|