move code blocks around
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
07ddc4e44d
commit
a907a4418a
76
draw.go
76
draw.go
|
@ -1,5 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/awesome-gocui/gocui"
|
||||||
|
log "go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
var toggle bool = true
|
var toggle bool = true
|
||||||
|
|
||||||
func (w *guiWidget) DrawAt(offsetW, offsetH int) {
|
func (w *guiWidget) DrawAt(offsetW, offsetH int) {
|
||||||
|
@ -36,3 +45,70 @@ func (w *guiWidget) drawTree(draw bool) {
|
||||||
child.drawTree(draw)
|
child.drawTree(draw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// display's the text of the widget in gocui
|
||||||
|
// create or recreate the gocui widget visible
|
||||||
|
// will create a new gocui view if there isn't one or if it has been moved
|
||||||
|
// deletes the old view if it exists and recreates it
|
||||||
|
func (w *guiWidget) recreateView() {
|
||||||
|
var err error
|
||||||
|
log.Log(INFO, "recreateView() START", w.WidgetType, w.String())
|
||||||
|
if me.baseGui == nil {
|
||||||
|
log.Log(ERROR, "recreateView() ERROR: me.baseGui == nil", w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.cuiName == "" {
|
||||||
|
log.Log(ERROR, "recreateView() w.cuiName was not set for widget", w)
|
||||||
|
w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK"
|
||||||
|
}
|
||||||
|
log.Log(INFO, "recreateView() labelN =", w.labelN)
|
||||||
|
|
||||||
|
// this deletes the button from gocui
|
||||||
|
me.baseGui.DeleteView(w.cuiName)
|
||||||
|
w.v = nil
|
||||||
|
|
||||||
|
w.textResize()
|
||||||
|
a := w.gocuiSize.w0
|
||||||
|
b := w.gocuiSize.h0
|
||||||
|
c := w.gocuiSize.w1
|
||||||
|
d := w.gocuiSize.h1
|
||||||
|
|
||||||
|
w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0)
|
||||||
|
if err == nil {
|
||||||
|
w.showWidgetPlacement("recreateView()")
|
||||||
|
log.Log(ERROR, "recreateView() internal plugin error err = nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !errors.Is(err, gocui.ErrUnknownView) {
|
||||||
|
w.showWidgetPlacement("recreateView()")
|
||||||
|
log.Log(ERROR, "recreateView() internal plugin error error.IS()", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// this sets up the keybinding for the name of the window
|
||||||
|
// does this really need to be done? I think we probably already
|
||||||
|
// know everything about where all the widgets are so we could bypass
|
||||||
|
// the gocui package and just handle all the mouse events internally here (?)
|
||||||
|
// for now, the w.v.Name is a string "1", "2", "3", etc from the widgetId
|
||||||
|
|
||||||
|
// set the binding for this gocui view now that it has been created
|
||||||
|
// gocui handles overlaps of views so it will run on the view that is clicked on
|
||||||
|
me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
|
||||||
|
|
||||||
|
// this actually sends the text to display to gocui
|
||||||
|
w.v.Wrap = true
|
||||||
|
w.v.Frame = w.frame
|
||||||
|
w.v.Clear()
|
||||||
|
fmt.Fprint(w.v, w.labelN)
|
||||||
|
|
||||||
|
// if you don't do this here, it will be black & white only
|
||||||
|
if w.color != nil {
|
||||||
|
w.v.FrameColor = w.color.frame
|
||||||
|
w.v.FgColor = w.color.fg
|
||||||
|
w.v.BgColor = w.color.bg
|
||||||
|
w.v.SelFgColor = w.color.selFg
|
||||||
|
w.v.SelBgColor = w.color.selBg
|
||||||
|
}
|
||||||
|
log.Log(INFO, "recreateView() END")
|
||||||
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ func moveMsg(g *gocui.Gui) {
|
||||||
movingMsg = true
|
movingMsg = true
|
||||||
}
|
}
|
||||||
g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH+me.FramePadH, 0)
|
g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH+me.FramePadH, 0)
|
||||||
me.startOutputW = mx-xOffset
|
me.startOutputW = mx - xOffset
|
||||||
me.startOutputH = my-yOffset
|
me.startOutputH = my - yOffset
|
||||||
g.SetViewOnBottom("msg")
|
g.SetViewOnBottom("msg")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@ type config struct {
|
||||||
ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed
|
ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed
|
||||||
currentWindow *guiWidget // this is the current tab or window to show
|
currentWindow *guiWidget // this is the current tab or window to show
|
||||||
logStdout *tree.Node // where to show STDOUT
|
logStdout *tree.Node // where to show STDOUT
|
||||||
startOutputW int
|
startOutputW int
|
||||||
startOutputH int
|
startOutputH int
|
||||||
helpLabel *gocui.View
|
helpLabel *gocui.View
|
||||||
|
|
||||||
// this is a floating widget that we show whenever the user clicks on a
|
// this is a floating widget that we show whenever the user clicks on a
|
||||||
|
|
72
view.go
72
view.go
|
@ -2,13 +2,8 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
@ -48,73 +43,6 @@ func (w *guiWidget) textResize() bool {
|
||||||
return changed
|
return changed
|
||||||
}
|
}
|
||||||
|
|
||||||
// display's the text of the widget in gocui
|
|
||||||
// create or recreate the gocui widget visible
|
|
||||||
// will create a new gocui view if there isn't one or if it has been moved
|
|
||||||
// deletes the old view if it exists and recreates it
|
|
||||||
func (w *guiWidget) recreateView() {
|
|
||||||
var err error
|
|
||||||
log.Log(INFO, "recreateView() START", w.WidgetType, w.String())
|
|
||||||
if me.baseGui == nil {
|
|
||||||
log.Log(ERROR, "recreateView() ERROR: me.baseGui == nil", w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if w.cuiName == "" {
|
|
||||||
log.Log(ERROR, "recreateView() w.cuiName was not set for widget", w)
|
|
||||||
w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK"
|
|
||||||
}
|
|
||||||
log.Log(INFO, "recreateView() labelN =", w.labelN)
|
|
||||||
|
|
||||||
// this deletes the button from gocui
|
|
||||||
me.baseGui.DeleteView(w.cuiName)
|
|
||||||
w.v = nil
|
|
||||||
|
|
||||||
w.textResize()
|
|
||||||
a := w.gocuiSize.w0
|
|
||||||
b := w.gocuiSize.h0
|
|
||||||
c := w.gocuiSize.w1
|
|
||||||
d := w.gocuiSize.h1
|
|
||||||
|
|
||||||
w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0)
|
|
||||||
if err == nil {
|
|
||||||
w.showWidgetPlacement("recreateView()")
|
|
||||||
log.Log(ERROR, "recreateView() internal plugin error err = nil")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !errors.Is(err, gocui.ErrUnknownView) {
|
|
||||||
w.showWidgetPlacement("recreateView()")
|
|
||||||
log.Log(ERROR, "recreateView() internal plugin error error.IS()", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// this sets up the keybinding for the name of the window
|
|
||||||
// does this really need to be done? I think we probably already
|
|
||||||
// know everything about where all the widgets are so we could bypass
|
|
||||||
// the gocui package and just handle all the mouse events internally here (?)
|
|
||||||
// for now, the w.v.Name is a string "1", "2", "3", etc from the widgetId
|
|
||||||
|
|
||||||
// set the binding for this gocui view now that it has been created
|
|
||||||
// gocui handles overlaps of views so it will run on the view that is clicked on
|
|
||||||
me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
|
|
||||||
|
|
||||||
// this actually sends the text to display to gocui
|
|
||||||
w.v.Wrap = true
|
|
||||||
w.v.Frame = w.frame
|
|
||||||
w.v.Clear()
|
|
||||||
fmt.Fprint(w.v, w.labelN)
|
|
||||||
|
|
||||||
// if you don't do this here, it will be black & white only
|
|
||||||
if w.color != nil {
|
|
||||||
w.v.FrameColor = w.color.frame
|
|
||||||
w.v.FgColor = w.color.fg
|
|
||||||
w.v.BgColor = w.color.bg
|
|
||||||
w.v.SelFgColor = w.color.selFg
|
|
||||||
w.v.SelBgColor = w.color.selBg
|
|
||||||
}
|
|
||||||
log.Log(INFO, "recreateView() END")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *guiWidget) hideWidgets() {
|
func (w *guiWidget) hideWidgets() {
|
||||||
if w == nil {
|
if w == nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -103,7 +103,7 @@ func (tk *guiWidget) Visible() bool {
|
||||||
|
|
||||||
func (w *guiWidget) Show() {
|
func (w *guiWidget) Show() {
|
||||||
// always should the dropdown widget
|
// always should the dropdown widget
|
||||||
if w== me.dropdownV {
|
if w == me.dropdownV {
|
||||||
me.dropdownV.recreateView()
|
me.dropdownV.recreateView()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ func (w *guiWidget) Show() {
|
||||||
// then ignore it
|
// then ignore it
|
||||||
log.Log(NOW, "Show() widget =", w.cuiName, w.String())
|
log.Log(NOW, "Show() widget =", w.cuiName, w.String())
|
||||||
log.Log(NOW, "Show() w.IsCurrent() returned", w.IsCurrent())
|
log.Log(NOW, "Show() w.IsCurrent() returned", w.IsCurrent())
|
||||||
if ! w.IsCurrent() {
|
if !w.IsCurrent() {
|
||||||
log.Log(NOW, "Show() NOT drawing", w.cuiName, w.String())
|
log.Log(NOW, "Show() NOT drawing", w.cuiName, w.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue