fake buttons have labels

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-28 03:33:08 -06:00
parent 1f3d664dbd
commit e678a5cc62
7 changed files with 31 additions and 23 deletions

View File

@ -8,14 +8,17 @@ func (w *guiWidget) setCheckbox(b any) {
if w.node.WidgetType != widget.Checkbox { if w.node.WidgetType != widget.Checkbox {
return return
} }
if w.node.State.Label == "" {
w.node.State.Label = "BLANK"
}
if widget.GetBool(b) { if widget.GetBool(b) {
w.checked = widget.GetBool(b) w.checked = widget.GetBool(b)
w.label = "X " + w.label w.labelN = "X " + w.node.State.Label
} else { } else {
w.checked = widget.GetBool(b) w.checked = widget.GetBool(b)
w.label = " " + w.label w.labelN = " " + w.node.State.Label
} }
t := len(w.label) + 1 t := len(w.labelN) + 1
w.gocuiSize.w1 = w.gocuiSize.w0 + t w.gocuiSize.w1 = w.gocuiSize.w0 + t
// w.realWidth = w.gocuiSize.Width() + me.PadW // w.realWidth = w.gocuiSize.Width() + me.PadW

View File

@ -242,7 +242,7 @@ func doWidgetClick(n *tree.Node) {
} }
me.ddNode = n me.ddNode = n
log.Log(NOW, "new dns list should be set to:", dnsList) log.Log(NOW, "new dns list should be set to:", dnsList)
tk.label = dnsList tk.labelN = dnsList
tk.SetText(dnsList) tk.SetText(dnsList)
SetVisible(me.ddview, true) SetVisible(me.ddview, true)
} }
@ -297,7 +297,7 @@ func click(g *gocui.Gui, v *gocui.View) error {
var w *guiWidget var w *guiWidget
w = n.TK.(*guiWidget) w = n.TK.(*guiWidget)
if n != nil { if n != nil {
log.Log(NOW, "click() Found widget =", n.WidgetId, n.String(), ",", w.label) log.Log(NOW, "click() Found widget =", n.WidgetId, n.String(), ",", w.labelN)
if n.String() == "DropBox" { if n.String() == "DropBox" {
log.Log(NOW, "click() this is the dropdown menu. set a flag here what did I click? where is the mouse?") log.Log(NOW, "click() this is the dropdown menu. set a flag here what did I click? where is the mouse?")
log.Log(NOW, "click() set a global dropdown clicked flag=true here") log.Log(NOW, "click() set a global dropdown clicked flag=true here")
@ -372,7 +372,7 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
var tk *guiWidget var tk *guiWidget
tk = me.ctrlDown.TK.(*guiWidget) tk = me.ctrlDown.TK.(*guiWidget)
tk.label = found.String() tk.labelN = found.String()
tk.cuiName = "ctrlDown" tk.cuiName = "ctrlDown"
// me.ctrlDown.parent = me.rootNode // me.ctrlDown.parent = me.rootNode
} }
@ -381,7 +381,7 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
if found == nil { if found == nil {
found = me.treeRoot found = me.treeRoot
} }
tk.label = found.String() tk.labelN = found.String()
newR := realGocuiSize(found) newR := realGocuiSize(found)
tk.gocuiSize.w0 = newR.w0 tk.gocuiSize.w0 = newR.w0
tk.gocuiSize.h0 = newR.h0 tk.gocuiSize.h0 = newR.h0

View File

@ -46,7 +46,7 @@ func (w *guiWidget) showWidgetPlacement(b bool, s string) {
w.gocuiSize.Width(), w.gocuiSize.Height(), w.gocuiSize.Width(), w.gocuiSize.Height(),
w.gocuiSize.w0, w.gocuiSize.h0, w.gocuiSize.w1, w.gocuiSize.h1) w.gocuiSize.w0, w.gocuiSize.h0, w.gocuiSize.w1, w.gocuiSize.h1)
} else { } else {
s1 += fmt.Sprintf(" ") s1 += fmt.Sprintf(" w.Visable() == false ")
} }
if w.node.Parent != nil { if w.node.Parent != nil {
if w.node.Parent.WidgetType == widget.Grid { if w.node.Parent.WidgetType == widget.Grid {
@ -54,7 +54,7 @@ func (w *guiWidget) showWidgetPlacement(b bool, s string) {
} }
} }
tmp := "." + w.String() + "." tmp := "." + w.String() + "."
log.Log(INFO, s1, s, w.node.WidgetType, ",", tmp) // , "text=", w.text) log.Log(INFO, s1, s, w.node.WidgetType, ",", tmp, "jcarr") // , "text=", w.text)
} }
/* /*

View File

@ -99,8 +99,8 @@ func (w *guiWidget) SetText(text string) {
log.Log(NOW, "widget is nil") log.Log(NOW, "widget is nil")
return return
} }
if widget.GetString(w.value) != text { if w.labelN != text {
w.value = text w.labelN = text
changed = true changed = true
} }
if !changed { if !changed {

View File

@ -139,7 +139,7 @@ type guiWidget struct {
checked bool checked bool
// the actual text to display in the console // the actual text to display in the console
label string labelN string
vals []string // dropdown menu items vals []string // dropdown menu items
@ -148,7 +148,7 @@ type guiWidget struct {
direction widget.Orientation direction widget.Orientation
progname string // progname string
// the logical size of the widget // the logical size of the widget
// For example, 40x12 would be the center of a normal terminal // For example, 40x12 would be the center of a normal terminal

15
view.go
View File

@ -26,7 +26,7 @@ func (w *guiWidget) textResize() bool {
var width, height int = 0, 0 var width, height int = 0, 0
var changed bool = false var changed bool = false
for i, s := range splitLines(w.label) { for i, s := range splitLines(w.labelN) {
log.Log(INFO, "textResize() len =", len(s), i, s) log.Log(INFO, "textResize() len =", len(s), i, s)
if width < len(s) { if width < len(s) {
width = len(s) width = len(s)
@ -60,6 +60,7 @@ func (w *guiWidget) showView() {
log.Log(ERROR, "showView() w.cuiName was not set for widget", w) log.Log(ERROR, "showView() w.cuiName was not set for widget", w)
w.cuiName = string(w.node.WidgetId) w.cuiName = string(w.node.WidgetId)
} }
log.Log(ERROR, "showView() labelN =", w.labelN)
// if the gocui element doesn't exist, create it // if the gocui element doesn't exist, create it
if w.v == nil { if w.v == nil {
@ -76,7 +77,7 @@ func (w *guiWidget) showView() {
} else { } else {
log.Log(NOW, "showView() Clear() and Fprint() here wId =", w.cuiName) log.Log(NOW, "showView() Clear() and Fprint() here wId =", w.cuiName)
w.v.Clear() w.v.Clear()
fmt.Fprint(w.v, w.label) fmt.Fprint(w.v, w.labelN)
w.SetVisible(false) w.SetVisible(false)
w.SetVisible(true) w.SetVisible(true)
return return
@ -122,10 +123,10 @@ func (w *guiWidget) recreateView() {
w.v = nil w.v = nil
if w.String() == "CLOUDFLARE_EMAIL" { if w.String() == "CLOUDFLARE_EMAIL" {
w.showWidgetPlacement(true, "n.String()="+w.String()+" n.tk.label="+w.label+" "+w.cuiName) w.showWidgetPlacement(true, "n.String()="+w.String()+" n.tk.label="+w.labelN+" "+w.cuiName)
// w.dumpWidget("jwc") // w.dumpWidget("jwc")
w.textResize() w.textResize()
w.showWidgetPlacement(true, "n.String()="+w.String()+" n.tk.label="+w.label+" "+w.cuiName) w.showWidgetPlacement(true, "n.String()="+w.String()+" n.tk.label="+w.labelN+" "+w.cuiName)
} }
a := w.gocuiSize.w0 a := w.gocuiSize.w0
@ -159,7 +160,7 @@ func (w *guiWidget) recreateView() {
w.v.Wrap = true w.v.Wrap = true
w.v.Frame = w.frame w.v.Frame = w.frame
w.v.Clear() w.v.Clear()
fmt.Fprint(w.v, w.label) fmt.Fprint(w.v, w.labelN)
// n.showWidgetPlacement(true, "n.String()=" + n.String() + " n.tk.label=" + n.tk.label + " " + w.cuiName) // n.showWidgetPlacement(true, "n.String()=" + n.String() + " n.tk.label=" + n.tk.label + " " + w.cuiName)
// n.dumpWidget("jwc 2") // n.dumpWidget("jwc 2")
@ -172,7 +173,7 @@ func (w *guiWidget) recreateView() {
w.v.SelBgColor = w.color.selBg w.v.SelBgColor = w.color.selBg
} }
if w.String() == "CLOUDFLARE_EMAIL" { if w.String() == "CLOUDFLARE_EMAIL" {
w.showWidgetPlacement(true, "w.String()="+w.String()+" w.label="+w.label+" "+w.cuiName) w.showWidgetPlacement(true, "w.String()="+w.String()+" w.label="+w.labelN+" "+w.cuiName)
dumpTree(w.node, true) dumpTree(w.node, true)
} }
log.Log(ERROR, "recreateView() END") log.Log(ERROR, "recreateView() END")
@ -206,8 +207,8 @@ func (w *guiWidget) hideFake() {
func (w *guiWidget) showFake() { func (w *guiWidget) showFake() {
if w.isFake { if w.isFake {
// w.setFake() // w.setFake()
w.showWidgetPlacement(true, "showFake:")
w.showView() w.showView()
w.showWidgetPlacement(true, "showFake:")
} }
for _, child := range w.children { for _, child := range w.children {
child.showFake() child.showFake()

View File

@ -18,6 +18,10 @@ func initWidget(n *tree.Node) *guiWidget {
w.node = n w.node = n
w.WidgetType = n.WidgetType w.WidgetType = n.WidgetType
w.labelN = n.State.Label
if w.labelN == "" {
w.labelN = n.GetProgName()
}
if n.WidgetType == widget.Root { if n.WidgetType == widget.Root {
log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId) log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
@ -104,7 +108,7 @@ func (w *guiWidget) IsCurrent() bool {
} }
func (tk *guiWidget) String() string { func (tk *guiWidget) String() string {
return tk.progname return tk.node.String()
} }
func (tk *guiWidget) Visible() bool { func (tk *guiWidget) Visible() bool {
@ -160,10 +164,10 @@ func addDropdown() *tree.Node {
// store the internal toolkit information // store the internal toolkit information
tk := new(guiWidget) tk := new(guiWidget)
tk.frame = true tk.frame = true
tk.label = "DropBox text" tk.labelN = "DropBox text"
// copy the data from the action message // copy the data from the action message
tk.progname = "DropBox" tk.node.State.Label = "DropBox"
// set the name used by gocui to the id // set the name used by gocui to the id
tk.cuiName = "-1 dropbox" tk.cuiName = "-1 dropbox"