diff --git a/toolkit/gocui/click.go b/toolkit/gocui/click.go index 21a964c..6f9aa06 100644 --- a/toolkit/gocui/click.go +++ b/toolkit/gocui/click.go @@ -21,10 +21,17 @@ func (w *cuiWidget) doWidgetClick() { me.rootNode.redoColor(true) case toolkit.Window: me.rootNode.hideWidgets() + if w.hasTabs { + // w.isCurrent = false + w.isCurrent = true + } else { + w.isCurrent = true + } w.placeWidgets() w.showWidgets() case toolkit.Tab: me.rootNode.hideWidgets() + w.isCurrent = true w.placeWidgets() w.showWidgets() case toolkit.Group: diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go index a772d8a..7972cfd 100644 --- a/toolkit/gocui/structs.go +++ b/toolkit/gocui/structs.go @@ -55,8 +55,8 @@ type config struct { TabPadW int `default:"4" dense:"0"` // how far down to start Window or Tab headings - WindowW int `default:"20" dense:"0"` - WindowH int `default:"0" dense:"0"` + WindowW int `default:"8" dense:"0"` + WindowH int `default:"-1"` TabW int `default:"2" dense:"0"` TabH int `default:"2" dense:"0"` @@ -118,10 +118,12 @@ type cuiWidget struct { vals []string // dropdown menu options - // visable bool // track if it's currently supposed to be shown + isCurrent bool // is this the currently displayed Window or Tab? + hasTabs bool // does the window have tabs? isFake bool // widget types like 'box' are 'false' // where the widget's real corner is + // should we always compute this? startW int startH int @@ -168,6 +170,25 @@ type cuiWidget struct { children []*cuiWidget } +func (w *cuiWidget) IsCurrent() bool { + if (w.widgetType == toolkit.Tab) { + return w.isCurrent + } + if (w.widgetType == toolkit.Window) { + return w.isCurrent + } + if (w.widgetType == toolkit.Root) { + return false + } + return w.parent.IsCurrent() +} + +func (w *cuiWidget) StartW() { +} + +func (w *cuiWidget) StartH() { +} + // from the gocui devs: // Write appends a byte slice into the view's internal buffer. Because // View implements the io.Writer interface, it can be passed as parameter diff --git a/toolkit/gocui/tab.go b/toolkit/gocui/tab.go index dc0566c..32f3fce 100644 --- a/toolkit/gocui/tab.go +++ b/toolkit/gocui/tab.go @@ -8,11 +8,12 @@ import ( ) func (w *cuiWidget) hideWidgets() { + w.isCurrent = false switch w.widgetType { case toolkit.Root: case toolkit.Flag: case toolkit.Window: - case toolkit.Tab: + // case toolkit.Tab: case toolkit.Box: case toolkit.Grid: default: @@ -47,24 +48,22 @@ func (w *cuiWidget) showWidgets() { if (w.isFake) { // don't display by default } else { - w.drawView() + if w.IsCurrent() { + w.showWidgetPlacement(logNow, "current:") + w.drawView() + } else { + w.showWidgetPlacement(logNow, "not:") + // w.drawView() + } } for _, child := range w.children { child.showWidgets() } } -func (w *cuiWidget) setTabWH() { - // set the start and size of the tab gocui button - if w.frame { - // this means it should work like a tab - w.gocuiSize.w0 = me.rootNode.nextW - w.gocuiSize.h0 = me.TabH - } else { - // this means it should just be a window label - w.gocuiSize.w0 = me.rootNode.nextW - w.gocuiSize.h0 = me.WindowH - } +func (w *cuiWidget) setWindowWH() { + w.gocuiSize.w0 = me.rootNode.nextW + w.gocuiSize.h0 = me.WindowH t := len(w.text) w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW @@ -73,16 +72,32 @@ func (w *cuiWidget) setTabWH() { w.realWidth = w.gocuiSize.Width() w.realHeight = w.gocuiSize.Height() - if w.frame { - w.realWidth += me.FramePadW - w.realHeight += me.FramePadH + // move the rootNode width over for the next window + me.rootNode.nextW += w.realWidth + me.WindowPadW - // move the rootNode width over for the next tab - me.rootNode.nextW += w.realWidth + me.TabPadW - } else { - // move the rootNode width over for the next window - me.rootNode.nextW += w.realWidth + me.WindowPadW - } + w.nextW = 4 + w.nextH = 2 + + w.showWidgetPlacement(logNow, "setWindowWH:") +} + +func (w *cuiWidget) setTabWH() { + // set the start and size of the tab gocui button + + w.gocuiSize.w0 = w.parent.nextW + w.gocuiSize.h0 = me.TabH + + t := len(w.text) + w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW + w.gocuiSize.h1 = w.gocuiSize.h0 + me.DefaultHeight + me.PadH + + w.realWidth = w.gocuiSize.Width() + w.realHeight = w.gocuiSize.Height() + + w.realWidth += me.FramePadW + w.realHeight += me.FramePadH + + w.parent.nextW += w.realWidth + me.TabPadW w.showWidgetPlacement(logNow, "setTabWH:") } @@ -99,10 +114,12 @@ func (w *cuiWidget) redoTabs(draw bool) { if (tabs) { // window is tabs. Don't show it as a standard button w.frame = false + w.hasTabs = true } else { w.frame = true + w.hasTabs = false } - w.setTabWH() + w.setWindowWH() w.deleteView() w.drawView() } diff --git a/toolkit/gocui/view.go b/toolkit/gocui/view.go index f348321..d830c98 100644 --- a/toolkit/gocui/view.go +++ b/toolkit/gocui/view.go @@ -86,8 +86,11 @@ func (w *cuiWidget) drawView() { w.v.Wrap = true if (w.widgetType == toolkit.Window) { w.v.Frame = w.frame + w.v.Clear() + fmt.Fprint(w.v, w.text) + } else { + fmt.Fprintln(w.v, w.text) } - fmt.Fprintln(w.v, w.text) w.setDefaultWidgetColor() }