gocui: tracking windows and tabs separately
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
ea37ba6823
commit
064f3ca748
|
@ -21,10 +21,17 @@ func (w *cuiWidget) doWidgetClick() {
|
||||||
me.rootNode.redoColor(true)
|
me.rootNode.redoColor(true)
|
||||||
case toolkit.Window:
|
case toolkit.Window:
|
||||||
me.rootNode.hideWidgets()
|
me.rootNode.hideWidgets()
|
||||||
|
if w.hasTabs {
|
||||||
|
// w.isCurrent = false
|
||||||
|
w.isCurrent = true
|
||||||
|
} else {
|
||||||
|
w.isCurrent = true
|
||||||
|
}
|
||||||
w.placeWidgets()
|
w.placeWidgets()
|
||||||
w.showWidgets()
|
w.showWidgets()
|
||||||
case toolkit.Tab:
|
case toolkit.Tab:
|
||||||
me.rootNode.hideWidgets()
|
me.rootNode.hideWidgets()
|
||||||
|
w.isCurrent = true
|
||||||
w.placeWidgets()
|
w.placeWidgets()
|
||||||
w.showWidgets()
|
w.showWidgets()
|
||||||
case toolkit.Group:
|
case toolkit.Group:
|
||||||
|
|
|
@ -55,8 +55,8 @@ type config struct {
|
||||||
TabPadW int `default:"4" dense:"0"`
|
TabPadW int `default:"4" dense:"0"`
|
||||||
|
|
||||||
// how far down to start Window or Tab headings
|
// how far down to start Window or Tab headings
|
||||||
WindowW int `default:"20" dense:"0"`
|
WindowW int `default:"8" dense:"0"`
|
||||||
WindowH int `default:"0" dense:"0"`
|
WindowH int `default:"-1"`
|
||||||
TabW int `default:"2" dense:"0"`
|
TabW int `default:"2" dense:"0"`
|
||||||
TabH int `default:"2" dense:"0"`
|
TabH int `default:"2" dense:"0"`
|
||||||
|
|
||||||
|
@ -118,10 +118,12 @@ type cuiWidget struct {
|
||||||
|
|
||||||
vals []string // dropdown menu options
|
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'
|
isFake bool // widget types like 'box' are 'false'
|
||||||
|
|
||||||
// where the widget's real corner is
|
// where the widget's real corner is
|
||||||
|
// should we always compute this?
|
||||||
startW int
|
startW int
|
||||||
startH int
|
startH int
|
||||||
|
|
||||||
|
@ -168,6 +170,25 @@ type cuiWidget struct {
|
||||||
children []*cuiWidget
|
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:
|
// from the gocui devs:
|
||||||
// Write appends a byte slice into the view's internal buffer. Because
|
// Write appends a byte slice into the view's internal buffer. Because
|
||||||
// View implements the io.Writer interface, it can be passed as parameter
|
// View implements the io.Writer interface, it can be passed as parameter
|
||||||
|
|
|
@ -8,11 +8,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (w *cuiWidget) hideWidgets() {
|
func (w *cuiWidget) hideWidgets() {
|
||||||
|
w.isCurrent = false
|
||||||
switch w.widgetType {
|
switch w.widgetType {
|
||||||
case toolkit.Root:
|
case toolkit.Root:
|
||||||
case toolkit.Flag:
|
case toolkit.Flag:
|
||||||
case toolkit.Window:
|
case toolkit.Window:
|
||||||
case toolkit.Tab:
|
// case toolkit.Tab:
|
||||||
case toolkit.Box:
|
case toolkit.Box:
|
||||||
case toolkit.Grid:
|
case toolkit.Grid:
|
||||||
default:
|
default:
|
||||||
|
@ -47,24 +48,22 @@ func (w *cuiWidget) showWidgets() {
|
||||||
if (w.isFake) {
|
if (w.isFake) {
|
||||||
// don't display by default
|
// don't display by default
|
||||||
} else {
|
} else {
|
||||||
w.drawView()
|
if w.IsCurrent() {
|
||||||
|
w.showWidgetPlacement(logNow, "current:")
|
||||||
|
w.drawView()
|
||||||
|
} else {
|
||||||
|
w.showWidgetPlacement(logNow, "not:")
|
||||||
|
// w.drawView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, child := range w.children {
|
for _, child := range w.children {
|
||||||
child.showWidgets()
|
child.showWidgets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *cuiWidget) setTabWH() {
|
func (w *cuiWidget) setWindowWH() {
|
||||||
// set the start and size of the tab gocui button
|
w.gocuiSize.w0 = me.rootNode.nextW
|
||||||
if w.frame {
|
w.gocuiSize.h0 = me.WindowH
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
t := len(w.text)
|
t := len(w.text)
|
||||||
w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW
|
w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW
|
||||||
|
@ -73,16 +72,32 @@ func (w *cuiWidget) setTabWH() {
|
||||||
w.realWidth = w.gocuiSize.Width()
|
w.realWidth = w.gocuiSize.Width()
|
||||||
w.realHeight = w.gocuiSize.Height()
|
w.realHeight = w.gocuiSize.Height()
|
||||||
|
|
||||||
if w.frame {
|
// move the rootNode width over for the next window
|
||||||
w.realWidth += me.FramePadW
|
me.rootNode.nextW += w.realWidth + me.WindowPadW
|
||||||
w.realHeight += me.FramePadH
|
|
||||||
|
|
||||||
// move the rootNode width over for the next tab
|
w.nextW = 4
|
||||||
me.rootNode.nextW += w.realWidth + me.TabPadW
|
w.nextH = 2
|
||||||
} else {
|
|
||||||
// move the rootNode width over for the next window
|
w.showWidgetPlacement(logNow, "setWindowWH:")
|
||||||
me.rootNode.nextW += w.realWidth + me.WindowPadW
|
}
|
||||||
}
|
|
||||||
|
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:")
|
w.showWidgetPlacement(logNow, "setTabWH:")
|
||||||
}
|
}
|
||||||
|
@ -99,10 +114,12 @@ func (w *cuiWidget) redoTabs(draw bool) {
|
||||||
if (tabs) {
|
if (tabs) {
|
||||||
// window is tabs. Don't show it as a standard button
|
// window is tabs. Don't show it as a standard button
|
||||||
w.frame = false
|
w.frame = false
|
||||||
|
w.hasTabs = true
|
||||||
} else {
|
} else {
|
||||||
w.frame = true
|
w.frame = true
|
||||||
|
w.hasTabs = false
|
||||||
}
|
}
|
||||||
w.setTabWH()
|
w.setWindowWH()
|
||||||
w.deleteView()
|
w.deleteView()
|
||||||
w.drawView()
|
w.drawView()
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,11 @@ func (w *cuiWidget) drawView() {
|
||||||
w.v.Wrap = true
|
w.v.Wrap = true
|
||||||
if (w.widgetType == toolkit.Window) {
|
if (w.widgetType == toolkit.Window) {
|
||||||
w.v.Frame = w.frame
|
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()
|
w.setDefaultWidgetColor()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue