gocui: try to make struct defaults work
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
22e0033c69
commit
a8b4c45eb7
19
tab.go
19
tab.go
|
@ -10,20 +10,23 @@ import (
|
|||
func (n *Node) NewTab(text string) *Node {
|
||||
// check to make sure n is actually a window
|
||||
|
||||
|
||||
if (n.WidgetType != toolkit.Window) {
|
||||
// figure out what the actual window is
|
||||
log(logError, "NewTab() is being requested on something that isn't a Window. node =", n)
|
||||
log(logError, "NewTab() parent", n.parent)
|
||||
return n.parent.NewTab(text)
|
||||
/*
|
||||
if (n.parent.WidgetType == toolkit.Window) {
|
||||
} else {
|
||||
if (n.parent.WidgetType == toolkit.Window) {
|
||||
return n.parent.NewTab(text)
|
||||
if (n.parent == nil) {
|
||||
// TODO: find a window. any window. never give up. never die.
|
||||
log(logError, "NewTab() TODO: make a window here", n)
|
||||
panic("NewTab did not get passed a window")
|
||||
}
|
||||
*/
|
||||
log(logError, "NewTab() parent =", n.parent)
|
||||
if (n.parent.WidgetType == toolkit.Root) {
|
||||
// also broken
|
||||
log(logError, "NewTab() TODO: make a window here", n)
|
||||
panic("NewTab did not get passed a window")
|
||||
}
|
||||
// go up the binary tree until we find a window widget to add a tab too
|
||||
return n.parent.NewTab(text)
|
||||
}
|
||||
newNode := n.newNode(text, toolkit.Tab, nil)
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ func (w *cuiWidget) addWidget() {
|
|||
case toolkit.Window:
|
||||
w.setTabWH()
|
||||
w.drawView()
|
||||
// w.frame = false
|
||||
return
|
||||
case toolkit.Tab:
|
||||
w.setTabWH()
|
||||
|
|
|
@ -30,6 +30,8 @@ func makeWidget(a *toolkit.Action) *cuiWidget {
|
|||
w.id = a.WidgetId
|
||||
// set the name used by gocui to the id
|
||||
w.cuiName = strconv.Itoa(w.id)
|
||||
// set the gocui view.Frame = true by default
|
||||
w.frame = true
|
||||
|
||||
if w.widgetType == toolkit.Root {
|
||||
log(logInfo, "setupWidget() FOUND ROOT w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId)
|
||||
|
|
|
@ -13,7 +13,10 @@ import (
|
|||
// to this toolkit from the wit/gui golang package
|
||||
func init() {
|
||||
log(logInfo, "Init() of awesome-gocui")
|
||||
Set(&me, "default")
|
||||
var test config
|
||||
Set(&test, "default")
|
||||
log(logNow, "Init() me.rawW", me.rawW)
|
||||
// exit("test init()")
|
||||
me.defaultBehavior = true
|
||||
|
||||
me.groupPadding = 4
|
||||
|
|
|
@ -16,6 +16,7 @@ func moveMsg(g *gocui.Gui) {
|
|||
movingMsg = true
|
||||
}
|
||||
g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH, 0)
|
||||
g.SetViewOnBottom("msg")
|
||||
}
|
||||
|
||||
func showMsg(g *gocui.Gui, v *gocui.View) error {
|
||||
|
@ -53,5 +54,6 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) {
|
|||
v.SelFgColor = gocui.ColorBlack
|
||||
fmt.Fprintln(v, "figure out how to capture STDOUT to here\n" + stringFromMouseClick)
|
||||
g.SetViewOnBottom("msg")
|
||||
// g.SetViewOnBottom(v.Name())
|
||||
return
|
||||
}
|
||||
|
|
|
@ -131,6 +131,7 @@ type cuiWidget struct {
|
|||
|
||||
tainted bool
|
||||
v *gocui.View
|
||||
frame bool
|
||||
|
||||
// writeMutex protects locks the write process
|
||||
writeMutex sync.Mutex
|
||||
|
@ -161,6 +162,7 @@ func (w *cuiWidget) Write(p []byte) (n int, err error) {
|
|||
|
||||
func Set(ptr interface{}, tag string) error {
|
||||
if reflect.TypeOf(ptr).Kind() != reflect.Ptr {
|
||||
log("Set() Not a pointer", ptr, "with tag =", tag)
|
||||
return fmt.Errorf("Not a pointer")
|
||||
}
|
||||
|
||||
|
@ -168,9 +170,12 @@ func Set(ptr interface{}, tag string) error {
|
|||
t := v.Type()
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
log("Set() i =", i, t.Field(i))
|
||||
if defaultVal := t.Field(i).Tag.Get(tag); defaultVal != "-" {
|
||||
log("Set() tried something")
|
||||
if err := setField(v.Field(i), defaultVal); err != nil {
|
||||
return err
|
||||
log("Set() failed", err)
|
||||
// return err
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -181,7 +186,7 @@ func Set(ptr interface{}, tag string) error {
|
|||
func setField(field reflect.Value, defaultVal string) error {
|
||||
|
||||
if !field.CanSet() {
|
||||
log("Can't set value\n")
|
||||
log("setField() Can't set value", field, defaultVal)
|
||||
return fmt.Errorf("Can't set value\n")
|
||||
}
|
||||
|
||||
|
|
|
@ -72,8 +72,48 @@ func (w *cuiWidget) setTabWH() {
|
|||
w.showWidgetPlacement(logNow, "setTabWH:")
|
||||
}
|
||||
|
||||
func (w *cuiWidget) setLabel() {
|
||||
// set the start and size of the tab gocui button
|
||||
t := len(w.text)
|
||||
w.gocuiSize.width = t + me.buttonPadding
|
||||
w.gocuiSize.height = 2
|
||||
w.gocuiSize.w0 = me.rootNode.nextW
|
||||
w.gocuiSize.h0 = me.rootNode.nextH
|
||||
|
||||
// move the rootNode width over for the next window or tab
|
||||
me.rootNode.nextW += w.gocuiSize.width + me.padW
|
||||
|
||||
w.startW = me.rawW
|
||||
w.startH = me.rawH
|
||||
w.nextW = me.rawW
|
||||
w.nextH = me.rawH
|
||||
|
||||
w.setWH()
|
||||
w.showWidgetPlacement(logNow, "setLabel:")
|
||||
}
|
||||
|
||||
func (w *cuiWidget) redoTabs(draw bool) {
|
||||
if ((w.widgetType == toolkit.Window) || (w.widgetType == toolkit.Tab)) {
|
||||
if (w.widgetType == toolkit.Window) {
|
||||
var tabs bool = false
|
||||
// figure out if the window is just a bunch of tabs
|
||||
for _, child := range w.children {
|
||||
if (child.widgetType == toolkit.Tab) {
|
||||
tabs = true
|
||||
}
|
||||
}
|
||||
if (tabs) {
|
||||
// window is tabs. Don't show it as a standard button
|
||||
w.frame = false
|
||||
w.setLabel()
|
||||
} else {
|
||||
w.frame = true
|
||||
w.setTabWH()
|
||||
}
|
||||
|
||||
w.deleteView()
|
||||
w.drawView()
|
||||
}
|
||||
if (w.widgetType == toolkit.Tab) {
|
||||
w.deleteView()
|
||||
w.drawView()
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/awesome-gocui/gocui"
|
||||
// "git.wit.org/wit/gui/toolkit"
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
func splitLines(s string) []string {
|
||||
|
@ -85,6 +85,9 @@ func (w *cuiWidget) drawView() {
|
|||
me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
|
||||
|
||||
w.v.Wrap = true
|
||||
if (w.widgetType == toolkit.Window) {
|
||||
w.v.Frame = w.frame
|
||||
}
|
||||
fmt.Fprintln(w.v, w.text)
|
||||
|
||||
w.setDefaultWidgetColor()
|
||||
|
|
Loading…
Reference in New Issue