diff --git a/common.go b/common.go index 2218f9b..3943f61 100644 --- a/common.go +++ b/common.go @@ -39,30 +39,26 @@ func (n *Node) Add(str string) { var a toolkit.Action a.ActionType = toolkit.Add a.S = str - // a.Widget = &n.widget - // action(&a) newaction(&a, n, nil) } func (n *Node) AddText(str string) { log(debugChange, "AddText() value =", str) + n.Text = str var a toolkit.Action a.ActionType = toolkit.AddText a.S = str - // a.Widget = &n.widget - // action(&a) newaction(&a, n, nil) } -func (n *Node) SetText(str string) { - log(debugChange, "SetText() value =", str) +func (n *Node) SetText(text string) { + log(debugChange, "SetText() value =", text) + n.Text = text var a toolkit.Action a.ActionType = toolkit.SetText - a.S = str - // a.Widget = &n.widget - // action(&a) + a.S = text newaction(&a, n, nil) } @@ -84,17 +80,18 @@ func (n *Node) Set(val any) { switch v := val.(type) { case bool: + n.B = val.(bool) a.B = val.(bool) case string: + n.Text = val.(string) a.S = val.(string) case int: + n.I = val.(int) a.I = val.(int) default: log(debugError, "Set() unknown type =", v, "a =", a) } - // a.Widget = &n.widget - // action(&a) newaction(&a, n, nil) } @@ -104,8 +101,7 @@ func (n *Node) AppendText(str string) { tmp := n.widget.S + str log(debugChange, "AppendText() value =", tmp) a.S = tmp - // a.Widget = &n.widget - // action(&a) + n.Text = tmp newaction(&a, n, nil) } @@ -182,6 +178,9 @@ func (n *Node) Unpad() { newaction(&a, n, nil) } +// is this better? +// me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard() + func (n *Node) New2() *Node { var newWin *Node newWin = NewWindow() diff --git a/node.go b/node.go index b0bad5c..d4be30b 100644 --- a/node.go +++ b/node.go @@ -43,6 +43,7 @@ func (n *Node) New(title string, t toolkit.WidgetType, custom func()) *Node { func addNode(title string) *Node { n := new(Node) n.Name = title + n.Text = title n.widget.Name = title n.id = Config.counter n.widget.Id = n.id diff --git a/toolkit/democui/debug.go b/toolkit/democui/debug.go index bb2a06d..28afa0d 100644 --- a/toolkit/democui/debug.go +++ b/toolkit/democui/debug.go @@ -88,26 +88,14 @@ func dumpWidgets(g *gocui.Gui, v *gocui.View) { } } -func adjustWidgets() { - for i := 0; i <= me.highest; i++ { - w := me.widgets[i] - if (w == nil) { - continue - } - p := me.widgets[w.parentId] - if (p != nil) { - w.setParentLogical(p) - } - } -} - func (w *cuiWidget) showWidgetPlacement(b bool, s string) { log(b, "dump()", s, fmt.Sprintf("(wId,pId)=(%3d,%3d)", w.id, w.parentId), fmt.Sprintf("real()=(%3d,%3d,%3d,%3d)", w.realSize.w0, w.realSize.h0, w.realSize.w1, w.realSize.h1), "next()=(", w.nextX, ",", w.nextY, ")", "logical()=(", w.logicalSize.w0, ",", w.logicalSize.h0, ",", w.logicalSize.w1, ",", w.logicalSize.h1, ")", - w.widgetType, ",", w.name) + w.widgetType, ",", w.name, "text=", w.text) + if (w.realWidth != (w.realSize.w1 - w.realSize.w0)) { log(b, "dump()", s, "badsize()=(", w.realWidth, ",", w.realHeight, ")", diff --git a/toolkit/democui/keybindings.go b/toolkit/democui/keybindings.go index 8e5e937..977a375 100644 --- a/toolkit/democui/keybindings.go +++ b/toolkit/democui/keybindings.go @@ -32,11 +32,28 @@ func defaultKeybindings(g *gocui.Gui) error { // dump out the widgets func addDebugKeys(g *gocui.Gui) { + // dump all widget info to the log g.SetKeybinding("", 'd', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { dumpWidgets(g, v) return nil }) + + // hide all widgets + g.SetKeybinding("", 'h', gocui.ModNone, + func(g *gocui.Gui, v *gocui.View) error { + hideWidgets() + return nil + }) + + // show all widgets + g.SetKeybinding("", 's', gocui.ModNone, + func(g *gocui.Gui, v *gocui.View) error { + showWidgets() + return nil + }) + + // try to adjust all the widget positions g.SetKeybinding("", 'r', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { adjustWidgets() diff --git a/toolkit/democui/tab.go b/toolkit/democui/tab.go new file mode 100644 index 0000000..745956c --- /dev/null +++ b/toolkit/democui/tab.go @@ -0,0 +1,52 @@ +package main + +// implements widgets 'Window' and 'Tab' + +import ( +// "fmt" + "strconv" + +// "git.wit.org/wit/gui/toolkit" +// "github.com/awesome-gocui/gocui" +) + +func adjustWidgets() { + for i := 0; i <= me.highest; i++ { + w := me.widgets[i] + if (w == nil) { + continue + } + p := me.widgets[w.parentId] + if (p != nil) { + w.setParentLogical(p) + } + } +} + +func hideWidgets() { + for i := 0; i <= me.highest; i++ { + w := me.widgets[i] + if (w == nil) { + continue + } + if (w.visable) { + if (w.v != nil) { + cuiName := strconv.Itoa(i) + log(logNow, "about to delete", cuiName, w.name) + me.baseGui.DeleteView(cuiName) + } + } + } +} + +func showWidgets() { + for i := 0; i <= me.highest; i++ { + w := me.widgets[i] + if (w == nil) { + continue + } + if (w.visable) { + w.drawView() + } + } +} diff --git a/toolkit/democui/view.go b/toolkit/democui/view.go index 8699bf6..5ff44ad 100644 --- a/toolkit/democui/view.go +++ b/toolkit/democui/view.go @@ -315,3 +315,35 @@ func place(w *cuiWidget, a *toolkit.Action) { log(logInfo, "place() END") return } + +func (w *cuiWidget) drawView() { + var err error + if (me.baseGui == nil) { + log(logError, "drawView() me.baseGui == nil") + return + } + + a := w.realSize.w0 + b := w.realSize.h0 + c := w.realSize.w1 + d := w.realSize.h1 + + var newName string = "" + newName = strconv.Itoa(w.id) + w.v, err = me.baseGui.SetView(newName, a, b, c, d, 0) + if err == nil { + log(logError, "drawView() internal plugin error err = nil") + return + } + if !errors.Is(err, gocui.ErrUnknownView) { + log(logError, "drawView() internal plugin error error.IS()", err) + return + } + + me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click) + + w.v.Wrap = true + fmt.Fprintln(w.v, " " + w.text) + + w.SetDefaultWidgetColor() +}