gocui: more correct logic

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-26 14:52:54 -05:00
parent 38c161f39e
commit ce7e51bafa
2 changed files with 39 additions and 29 deletions

View File

@ -44,16 +44,18 @@ func (w *cuiWidget) addWidget() {
w.setFake() w.setFake()
return return
case toolkit.Window: case toolkit.Window:
w.setTabWH() me.current = w
w.showView() updateCurrentTabs()
setCurrentWindow(w)
return return
case toolkit.Tab: case toolkit.Tab:
UnsetCurrent(me.rootNode) // if this is the first tab, set it to the current one and stay here
me.rootNode.hideWidgets() if (me.current != nil) {
w.isCurrent = true // there is already a current tab. just redraw the tabs
w.parent.isCurrent = true updateCurrentTabs()
w.placeWidgets() return
w.showWidgets() }
setCurrentTab(w)
return return
case toolkit.Box: case toolkit.Box:
w.isFake = true w.isFake = true

View File

@ -25,8 +25,34 @@ func updateCurrentTabs() {
me.rootNode.redoTabs(true) me.rootNode.redoTabs(true)
} }
// shows the widgets in a window
func setCurrentWindow(w *cuiWidget) {
if w.widgetType != toolkit.Window {
return
}
UnsetCurrent(me.rootNode)
me.rootNode.hideWidgets()
// THIS IS THE BEGINING OF THE LAYOUT
me.rootNode.nextW = 0
me.rootNode.nextH = 0
w.isCurrent = true
if w.hasTabs {
// set isCurrent = true on the first tab
for _, child := range w.children {
child.isCurrent = true
break
}
}
me.rootNode.redoTabs(true)
w.placeWidgets()
w.showWidgets()
}
// shows the widgets in a tab // shows the widgets in a tab
func setCurrent(w *cuiWidget) { func setCurrentTab(w *cuiWidget) {
if w.widgetType != toolkit.Tab { if w.widgetType != toolkit.Tab {
return return
} }
@ -51,27 +77,9 @@ func (w *cuiWidget) doWidgetClick() {
// me.rootNode.redoColor(true) // me.rootNode.redoColor(true)
me.rootNode.dumpTree(true) me.rootNode.dumpTree(true)
case toolkit.Window: case toolkit.Window:
UnsetCurrent(me.rootNode) setCurrentWindow(w)
me.rootNode.hideWidgets()
me.rootNode.nextW = 0
me.rootNode.nextH = 0
w.isCurrent = true
if w.hasTabs {
// set isCurrent = true on the first tab
for _, child := range w.children {
child.isCurrent = true
break
}
}
me.rootNode.redoTabs(true)
w.placeWidgets()
w.showWidgets()
// THIS IS THE BEGINING OF THE LAYOUT
case toolkit.Tab: case toolkit.Tab:
setCurrent(w) setCurrentTab(w)
case toolkit.Group: case toolkit.Group:
w.placeWidgets() w.placeWidgets()
w.toggleTree() w.toggleTree()