summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-26 14:52:54 -0500
committerJeff Carr <[email protected]>2023-04-26 14:52:54 -0500
commit8cb2100c2844af0307b27c2fac3185dcce410bf4 (patch)
treee4a73b6bf1b86d589e4078aa40e814011c69f5b0
parentd4b0b8b6b6e3141114ebb448438922192c725763 (diff)
gocui: more correct logic
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--toolkit/gocui/add.go18
-rw-r--r--toolkit/gocui/click.go50
2 files changed, 39 insertions, 29 deletions
diff --git a/toolkit/gocui/add.go b/toolkit/gocui/add.go
index 856b871..c649da5 100644
--- a/toolkit/gocui/add.go
+++ b/toolkit/gocui/add.go
@@ -44,16 +44,18 @@ func (w *cuiWidget) addWidget() {
w.setFake()
return
case toolkit.Window:
- w.setTabWH()
- w.showView()
+ me.current = w
+ updateCurrentTabs()
+ setCurrentWindow(w)
return
case toolkit.Tab:
- UnsetCurrent(me.rootNode)
- me.rootNode.hideWidgets()
- w.isCurrent = true
- w.parent.isCurrent = true
- w.placeWidgets()
- w.showWidgets()
+ // if this is the first tab, set it to the current one and stay here
+ if (me.current != nil) {
+ // there is already a current tab. just redraw the tabs
+ updateCurrentTabs()
+ return
+ }
+ setCurrentTab(w)
return
case toolkit.Box:
w.isFake = true
diff --git a/toolkit/gocui/click.go b/toolkit/gocui/click.go
index d0c5d90..f0f325e 100644
--- a/toolkit/gocui/click.go
+++ b/toolkit/gocui/click.go
@@ -25,8 +25,34 @@ func updateCurrentTabs() {
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
-func setCurrent(w *cuiWidget) {
+func setCurrentTab(w *cuiWidget) {
if w.widgetType != toolkit.Tab {
return
}
@@ -51,27 +77,9 @@ func (w *cuiWidget) doWidgetClick() {
// me.rootNode.redoColor(true)
me.rootNode.dumpTree(true)
case toolkit.Window:
- UnsetCurrent(me.rootNode)
- 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
+ setCurrentWindow(w)
case toolkit.Tab:
- setCurrent(w)
+ setCurrentTab(w)
case toolkit.Group:
w.placeWidgets()
w.toggleTree()