2022-10-17 00:38:27 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2024-01-03 18:15:54 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
|
2024-01-03 18:54:08 -06:00
|
|
|
"go.wit.com/gui/toolkits"
|
2022-10-17 00:38:27 -05:00
|
|
|
)
|
|
|
|
|
2022-10-19 13:23:22 -05:00
|
|
|
// This function should make a new node with the parent and
|
|
|
|
// the 'tab' as a child
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
func (n *Node) NewTab(text string) *Node {
|
2023-04-23 14:18:34 -05:00
|
|
|
// check to make sure n is actually a window
|
|
|
|
|
|
|
|
if (n.WidgetType != toolkit.Window) {
|
|
|
|
// figure out what the actual window is
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Warn("NewTab() is being requested on something that isn't a Window. node =", n)
|
2023-04-24 14:17:43 -05:00
|
|
|
if (n.parent == nil) {
|
2023-04-23 14:18:34 -05:00
|
|
|
// TODO: find a window. any window. never give up. never die.
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Warn("NewTab() TODO: make a window here", n)
|
2023-04-23 14:18:34 -05:00
|
|
|
panic("NewTab did not get passed a window")
|
|
|
|
}
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Warn("NewTab() parent =", n.parent)
|
2023-04-24 14:17:43 -05:00
|
|
|
if (n.parent.WidgetType == toolkit.Root) {
|
|
|
|
// also broken
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Warn("NewTab() TODO: make or find a window here", n)
|
2023-05-09 18:34:09 -05:00
|
|
|
panic("NewTab() did not get passed a window")
|
2023-04-24 14:17:43 -05:00
|
|
|
}
|
|
|
|
// go up the binary tree until we find a window widget to add a tab too
|
|
|
|
return n.parent.NewTab(text)
|
2023-04-23 14:18:34 -05:00
|
|
|
}
|
2023-05-09 20:25:37 -05:00
|
|
|
newNode := n.newNode(text, toolkit.Tab)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-05-09 18:50:16 -05:00
|
|
|
a := newAction(newNode, toolkit.Add)
|
2023-05-09 18:53:31 -05:00
|
|
|
sendAction(a)
|
2023-03-23 12:35:12 -05:00
|
|
|
|
2023-05-09 18:50:16 -05:00
|
|
|
// by default, create a box inside the tab
|
|
|
|
// TODO: allow this to be configurable
|
2023-12-14 10:36:56 -06:00
|
|
|
newBox := newNode.NewBox(text + " box", true)
|
2023-05-09 18:50:16 -05:00
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
return newBox
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|