From bc15e6c87955d9ba837fe125ca2c53737afaf014 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 6 Feb 2025 14:35:01 -0600 Subject: [PATCH] simple cleanups --- init.go | 9 ++++--- structs.go | 70 +++++++++++++++++++++++++++--------------------------- treeAdd.go | 52 ++++++++++++++++++++-------------------- window.go | 9 ++++++- 4 files changed, 75 insertions(+), 65 deletions(-) diff --git a/init.go b/init.go index 8f68fed..60f3871 100644 --- a/init.go +++ b/init.go @@ -58,7 +58,7 @@ func init() { me.myTree.SetChecked = queueSetChecked me.myTree.ToolkitClose = queueToolkitClose - me.newWindowTrigger = make(chan bool, 1) + me.newWindowTrigger = make(chan *guiWidget, 1) go newWindowTrigger() log.Log(NOW, "Init() start pluginChan") @@ -200,14 +200,17 @@ func newWindowTrigger() { for { log.Log(NOW, "newWindowTrigger() for loop") select { - case a := <-me.newWindowTrigger: - log.Log(NOW, "newWindowTrigger() got new window", a) + case tk := <-me.newWindowTrigger: + log.Log(NOW, "newWindowTrigger() got new window", tk.cuiName) time.Sleep(200 * time.Millisecond) redoWindows(1, -1) if !me.stdout.init { me.stdout.init = true relocateStdoutOffscreen() } + tk.makeWindowActive() + tk.doWidgetClick(tk.gocuiSize.w0, tk.gocuiSize.h0) + setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn log.Log(NOW, "newWindowTrigger() after sleep") } } diff --git a/structs.go b/structs.go index 21a2d71..1a8ed5b 100644 --- a/structs.go +++ b/structs.go @@ -37,41 +37,41 @@ type config struct { helpLabel *gocui.View // ? showHelp bool // toggle boolean for the help menu (deprecate?) // dropdownW *guiWidget // grab the dropdown choices from this widget - FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side - FramePadH int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side - PadW int `default:"1" dense:"0"` // pad spacing - PadH int `default:"1" dense:"0"` // pad spacing - WindowW int `default:"8" dense:"0"` // how far down to start Window or Tab headings - WindowH int `default:"-1"` // how far down to start Window or Tab headings - TabW int `default:"5" dense:"0"` // how far down to start Window or Tab headings - TabH int `default:"1" dense:"0"` // how far down to start Window or Tab headings - WindowPadW int `default:"8" dense:"0"` // additional amount of space to put between window & tab widgets - TabPadW int `default:"4" dense:"0"` // additional amount of space to put between window & tab widgets - GroupPadW int `default:"2" dense:"1"` // additional amount of space to indent on a group - BoxPadW int `default:"2" dense:"1"` // additional amount of space to indent on a box - GridPadW int `default:"2" dense:"1"` // additional amount of space to indent on a grid - RawW int `default:"1"` // the raw beginning of each window (or tab) - RawH int `default:"5"` // the raw beginning of each window (or tab) - FakeW int `default:"20"` // offset for the hidden widgets - padded bool // add space between things like buttons - bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? - canvas bool // if set to true, the windows are a raw canvas - menubar bool // for windows - stretchy bool // expand things like buttons to the maximum size - margin bool // add space around the frames of windows - writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe) - ecount int // counts how many mouse and keyboard events have occurred - supermouse bool // prints out every widget found while you move the mouse around - depth int // used for listWidgets() debugging - globalMouseDown bool // yep, mouse is pressed - newWindowTrigger chan bool // work around hack to redraw windows a bit after NewWindow() - stdout stdout // information for the STDOUT window - showDebug bool // todo: move this into config struct - dropdown dropdown // the dropdown menu - allwin []*guiWidget // for tracking which window is next - downW int // where the mouse was pressed down - downH int // where the mouse was pressed down - currentDrag *guiWidget // what widget is currently being moved around + FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side + FramePadH int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side + PadW int `default:"1" dense:"0"` // pad spacing + PadH int `default:"1" dense:"0"` // pad spacing + WindowW int `default:"8" dense:"0"` // how far down to start Window or Tab headings + WindowH int `default:"-1"` // how far down to start Window or Tab headings + TabW int `default:"5" dense:"0"` // how far down to start Window or Tab headings + TabH int `default:"1" dense:"0"` // how far down to start Window or Tab headings + WindowPadW int `default:"8" dense:"0"` // additional amount of space to put between window & tab widgets + TabPadW int `default:"4" dense:"0"` // additional amount of space to put between window & tab widgets + GroupPadW int `default:"2" dense:"1"` // additional amount of space to indent on a group + BoxPadW int `default:"2" dense:"1"` // additional amount of space to indent on a box + GridPadW int `default:"2" dense:"1"` // additional amount of space to indent on a grid + RawW int `default:"1"` // the raw beginning of each window (or tab) + RawH int `default:"5"` // the raw beginning of each window (or tab) + FakeW int `default:"20"` // offset for the hidden widgets + padded bool // add space between things like buttons + bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? + canvas bool // if set to true, the windows are a raw canvas + menubar bool // for windows + stretchy bool // expand things like buttons to the maximum size + margin bool // add space around the frames of windows + writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe) + ecount int // counts how many mouse and keyboard events have occurred + supermouse bool // prints out every widget found while you move the mouse around + depth int // used for listWidgets() debugging + globalMouseDown bool // yep, mouse is pressed + newWindowTrigger chan *guiWidget // work around hack to redraw windows a bit after NewWindow() + stdout stdout // information for the STDOUT window + showDebug bool // todo: move this into config struct + dropdown dropdown // the dropdown menu + allwin []*guiWidget // for tracking which window is next + downW int // where the mouse was pressed down + downH int // where the mouse was pressed down + currentDrag *guiWidget // what widget is currently being moved around } diff --git a/treeAdd.go b/treeAdd.go index 078d625..2e3dbea 100644 --- a/treeAdd.go +++ b/treeAdd.go @@ -31,71 +31,71 @@ func setFake(n *tree.Node) { // set the widget start width & height // func (n *node) addWidget(n *tree.Node) { func addWidget(n *tree.Node) { - var nw *guiWidget - nw = n.TK.(*guiWidget) + var tk *guiWidget + tk = n.TK.(*guiWidget) log.Log(INFO, "setStartWH() w.id =", n.WidgetId, "n.name", n.String()) switch n.WidgetType { case widget.Root: log.Log(INFO, "setStartWH() rootNode w.id =", n.WidgetId, "w.name", n.String()) - nw.color = &colorRoot + tk.color = &colorRoot setFake(n) return case widget.Flag: - nw.color = &colorFlag + tk.color = &colorFlag setFake(n) return case widget.Window: - nw.frame = false - // nw.color = &colorWindow - nw.setColor(&colorWindow) - me.newWindowTrigger <- true + tk.frame = false + // tk.color = &colorWindow + tk.setColor(&colorWindow) + me.newWindowTrigger <- tk redoWindows(0, 0) hideHelp() showHelp() return case widget.Stdout: - nw.labelN = "moreSTDOUT" + tk.labelN = "moreSTDOUT" n.State.ProgName = "moreSTDOUT" n.State.Label = "moreSTDOUT" return case widget.Tab: - nw.color = &colorTab + tk.color = &colorTab return case widget.Button: - nw.color = &colorButton + tk.color = &colorButton return case widget.Checkbox: - nw.color = &colorCheckbox - nw.labelN = "X " + n.State.Label + tk.color = &colorCheckbox + tk.labelN = "X " + n.State.Label return case widget.Dropdown: - nw.color = &colorDropdown + tk.color = &colorDropdown return case widget.Textbox: n.State.Label = "TEXTBOX" - nw.labelN = " " + n.State.Label - nw.color = &colorDropdown + tk.labelN = " " + n.State.Label + tk.color = &colorDropdown return case widget.Combobox: - nw.color = &colorCombobox + tk.color = &colorCombobox return case widget.Box: - nw.color = &colorBox - nw.isFake = true + tk.color = &colorBox + tk.isFake = true setFake(n) return case widget.Grid: - nw.color = &colorGrid - nw.isFake = true + tk.color = &colorGrid + tk.isFake = true setFake(n) return case widget.Group: - nw.color = &colorGroup - nw.frame = false + tk.color = &colorGroup + tk.frame = false return case widget.Label: - nw.color = &colorLabel - nw.frame = false + tk.color = &colorLabel + tk.frame = false return default: /* @@ -104,5 +104,5 @@ func addWidget(n *tree.Node) { } */ } - nw.dumpWidget("in addWidget()") + tk.dumpWidget("addWidget()unknown") } diff --git a/window.go b/window.go index c043df3..313c153 100644 --- a/window.go +++ b/window.go @@ -6,6 +6,7 @@ package main import ( "fmt" + log "go.wit.com/log" "go.wit.com/toolkits/tree" "go.wit.com/widget" ) @@ -37,7 +38,13 @@ func (tk *guiWidget) redrawWindow(w int, h int) { tk.full.h0 = tk.force.h0 tk.setFullSize() - me.baseGui.SetView(tk.cuiName, tk.gocuiSize.w0, tk.gocuiSize.h0, tk.gocuiSize.w1, tk.gocuiSize.h1, 0) + v, err := me.baseGui.SetView(tk.cuiName, tk.gocuiSize.w0, tk.gocuiSize.h0, tk.gocuiSize.w1, tk.gocuiSize.h1, 0) + if err != nil { + log.Info("crap. got an err", err) + } + if tk.v != v { + log.Info("crap. got another problem v != tk.v") + } tk.Show() tk.v.Clear() fmt.Fprint(tk.v, "ZZZ"+tk.GetText())