gocui: code cleanups

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-26 14:25:48 -05:00
parent d67c7b2635
commit 38c161f39e
3 changed files with 29 additions and 9 deletions

View File

@ -48,8 +48,12 @@ func (w *cuiWidget) addWidget() {
w.showView()
return
case toolkit.Tab:
w.setTabWH()
w.showView()
UnsetCurrent(me.rootNode)
me.rootNode.hideWidgets()
w.isCurrent = true
w.parent.isCurrent = true
w.placeWidgets()
w.showWidgets()
return
case toolkit.Box:
w.isFake = true

View File

@ -19,6 +19,27 @@ func UnsetCurrent(w *cuiWidget) {
}
}
func updateCurrentTabs() {
me.rootNode.nextW = 0
me.rootNode.nextH = 0
me.rootNode.redoTabs(true)
}
// shows the widgets in a tab
func setCurrent(w *cuiWidget) {
if w.widgetType != toolkit.Tab {
return
}
me.current = w
UnsetCurrent(me.rootNode)
me.rootNode.hideWidgets()
w.isCurrent = true
w.parent.isCurrent = true
updateCurrentTabs()
w.placeWidgets()
w.showWidgets()
}
func (w *cuiWidget) doWidgetClick() {
switch w.widgetType {
case toolkit.Root:
@ -50,13 +71,7 @@ func (w *cuiWidget) doWidgetClick() {
w.showWidgets()
// THIS IS THE BEGINING OF THE LAYOUT
case toolkit.Tab:
UnsetCurrent(me.rootNode)
me.rootNode.hideWidgets()
w.isCurrent = true
w.parent.isCurrent = true
w.placeWidgets()
w.showWidgets()
setCurrent(w)
case toolkit.Group:
w.placeWidgets()
w.toggleTree()

View File

@ -24,6 +24,7 @@ type config struct {
baseGui *gocui.Gui // the main gocui handle
rootNode *cuiWidget // the base of the binary tree. it should have id == 0
ctrlDown *cuiWidget // shown if you click the mouse when the ctrl key is pressed
current *cuiWidget // this is the current tab or window to show
// this is the channel we send user events like
// mouse clicks or keyboard events back to the program