'hide' and 'show' works in gocui
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
3ac015e4c4
commit
678b867f1e
25
common.go
25
common.go
|
@ -39,30 +39,26 @@ func (n *Node) Add(str string) {
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
a.ActionType = toolkit.Add
|
a.ActionType = toolkit.Add
|
||||||
a.S = str
|
a.S = str
|
||||||
// a.Widget = &n.widget
|
|
||||||
// action(&a)
|
|
||||||
newaction(&a, n, nil)
|
newaction(&a, n, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) AddText(str string) {
|
func (n *Node) AddText(str string) {
|
||||||
log(debugChange, "AddText() value =", str)
|
log(debugChange, "AddText() value =", str)
|
||||||
|
|
||||||
|
n.Text = str
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
a.ActionType = toolkit.AddText
|
a.ActionType = toolkit.AddText
|
||||||
a.S = str
|
a.S = str
|
||||||
// a.Widget = &n.widget
|
|
||||||
// action(&a)
|
|
||||||
newaction(&a, n, nil)
|
newaction(&a, n, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) SetText(str string) {
|
func (n *Node) SetText(text string) {
|
||||||
log(debugChange, "SetText() value =", str)
|
log(debugChange, "SetText() value =", text)
|
||||||
|
|
||||||
|
n.Text = text
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
a.ActionType = toolkit.SetText
|
a.ActionType = toolkit.SetText
|
||||||
a.S = str
|
a.S = text
|
||||||
// a.Widget = &n.widget
|
|
||||||
// action(&a)
|
|
||||||
newaction(&a, n, nil)
|
newaction(&a, n, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,17 +80,18 @@ func (n *Node) Set(val any) {
|
||||||
|
|
||||||
switch v := val.(type) {
|
switch v := val.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
|
n.B = val.(bool)
|
||||||
a.B = val.(bool)
|
a.B = val.(bool)
|
||||||
case string:
|
case string:
|
||||||
|
n.Text = val.(string)
|
||||||
a.S = val.(string)
|
a.S = val.(string)
|
||||||
case int:
|
case int:
|
||||||
|
n.I = val.(int)
|
||||||
a.I = val.(int)
|
a.I = val.(int)
|
||||||
default:
|
default:
|
||||||
log(debugError, "Set() unknown type =", v, "a =", a)
|
log(debugError, "Set() unknown type =", v, "a =", a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// a.Widget = &n.widget
|
|
||||||
// action(&a)
|
|
||||||
newaction(&a, n, nil)
|
newaction(&a, n, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +101,7 @@ func (n *Node) AppendText(str string) {
|
||||||
tmp := n.widget.S + str
|
tmp := n.widget.S + str
|
||||||
log(debugChange, "AppendText() value =", tmp)
|
log(debugChange, "AppendText() value =", tmp)
|
||||||
a.S = tmp
|
a.S = tmp
|
||||||
// a.Widget = &n.widget
|
n.Text = tmp
|
||||||
// action(&a)
|
|
||||||
newaction(&a, n, nil)
|
newaction(&a, n, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +178,9 @@ func (n *Node) Unpad() {
|
||||||
newaction(&a, n, nil)
|
newaction(&a, n, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is this better?
|
||||||
|
// me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard()
|
||||||
|
|
||||||
func (n *Node) New2() *Node {
|
func (n *Node) New2() *Node {
|
||||||
var newWin *Node
|
var newWin *Node
|
||||||
newWin = NewWindow()
|
newWin = NewWindow()
|
||||||
|
|
1
node.go
1
node.go
|
@ -43,6 +43,7 @@ func (n *Node) New(title string, t toolkit.WidgetType, custom func()) *Node {
|
||||||
func addNode(title string) *Node {
|
func addNode(title string) *Node {
|
||||||
n := new(Node)
|
n := new(Node)
|
||||||
n.Name = title
|
n.Name = title
|
||||||
|
n.Text = title
|
||||||
n.widget.Name = title
|
n.widget.Name = title
|
||||||
n.id = Config.counter
|
n.id = Config.counter
|
||||||
n.widget.Id = n.id
|
n.widget.Id = n.id
|
||||||
|
|
|
@ -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) {
|
func (w *cuiWidget) showWidgetPlacement(b bool, s string) {
|
||||||
log(b, "dump()", s,
|
log(b, "dump()", s,
|
||||||
fmt.Sprintf("(wId,pId)=(%3d,%3d)", w.id, w.parentId),
|
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),
|
fmt.Sprintf("real()=(%3d,%3d,%3d,%3d)", w.realSize.w0, w.realSize.h0, w.realSize.w1, w.realSize.h1),
|
||||||
"next()=(", w.nextX, ",", w.nextY, ")",
|
"next()=(", w.nextX, ",", w.nextY, ")",
|
||||||
"logical()=(", w.logicalSize.w0, ",", w.logicalSize.h0, ",", w.logicalSize.w1, ",", w.logicalSize.h1, ")",
|
"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)) {
|
if (w.realWidth != (w.realSize.w1 - w.realSize.w0)) {
|
||||||
log(b, "dump()", s,
|
log(b, "dump()", s,
|
||||||
"badsize()=(", w.realWidth, ",", w.realHeight, ")",
|
"badsize()=(", w.realWidth, ",", w.realHeight, ")",
|
||||||
|
|
|
@ -32,11 +32,28 @@ func defaultKeybindings(g *gocui.Gui) error {
|
||||||
|
|
||||||
// dump out the widgets
|
// dump out the widgets
|
||||||
func addDebugKeys(g *gocui.Gui) {
|
func addDebugKeys(g *gocui.Gui) {
|
||||||
|
// dump all widget info to the log
|
||||||
g.SetKeybinding("", 'd', gocui.ModNone,
|
g.SetKeybinding("", 'd', gocui.ModNone,
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
func(g *gocui.Gui, v *gocui.View) error {
|
||||||
dumpWidgets(g, v)
|
dumpWidgets(g, v)
|
||||||
return nil
|
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,
|
g.SetKeybinding("", 'r', gocui.ModNone,
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
func(g *gocui.Gui, v *gocui.View) error {
|
||||||
adjustWidgets()
|
adjustWidgets()
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -315,3 +315,35 @@ func place(w *cuiWidget, a *toolkit.Action) {
|
||||||
log(logInfo, "place() END")
|
log(logInfo, "place() END")
|
||||||
return
|
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()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue