tiggers gocui on startup

This commit is contained in:
Jeff Carr 2025-02-08 12:05:25 -06:00
parent ed024aac70
commit 665d2289e2
3 changed files with 63 additions and 30 deletions

34
find.go
View File

@ -45,25 +45,25 @@ func (r rectType) inRect(w int, h int) bool {
func (tk *guiWidget) findByXYreal(w int, h int) []*guiWidget {
var widgets []*guiWidget
if !tk.Visible() {
// ignore widgets that are not visible
} else {
// if !tk.Visible() {
// ignore widgets that are not visible
// } else {
// check the location to see if this is under (W,H)
// if it is, return this widget
// if (tk.gocuiSize.w0 <= w) && (w <= tk.gocuiSize.w1) &&
// (tk.gocuiSize.h0 <= h) && (h <= tk.gocuiSize.h1) {
if tk.gocuiSize.inRect(w, h) {
widgets = append(widgets, tk)
} else {
// if (tk.full.w0 <= w) && (w <= tk.full.w1) &&
// (tk.full.h0 <= h) && (h <= tk.full.h1) {
if tk.full.inRect(w, h) {
widgets = append(widgets, tk)
}
// log.Log(GOCUI, "findByXY() found", widget.node.WidgetType, w, h)
}
// check the location to see if this is under (W,H)
// if it is, return this widget
// if (tk.gocuiSize.w0 <= w) && (w <= tk.gocuiSize.w1) &&
// (tk.gocuiSize.h0 <= h) && (h <= tk.gocuiSize.h1) {
// if tk.gocuiSize.inRect(w, h) {
// widgets = append(widgets, tk)
// } else {
// if (tk.full.w0 <= w) && (w <= tk.full.w1) &&
// (tk.full.h0 <= h) && (h <= tk.full.h1) {
if tk.full.inRect(w, h) {
widgets = append(widgets, tk)
}
// log.Log(GOCUI, "findByXY() found", widget.node.WidgetType, w, h)
// }
// }
// tk.verifyRect()
// search through the children widgets in the binary tree

47
init.go
View File

@ -56,6 +56,7 @@ func init() {
me.myTree = tree.New()
me.myTree.PluginName = "gocui"
go refreshGocui()
if val, err := me.myTree.ConfigFind("dark"); err == nil {
if val == "true" {
@ -207,6 +208,47 @@ func gocuiMain() {
}
}
// this hack is to wait for the application to send something
// before trying to do anything. todo: rethink this someday
func waitOK() {
for {
if me.ok {
return
}
time.Sleep(10 * time.Millisecond)
}
}
var lastRefresh time.Time
func testRefresh(*gocui.Gui) error {
log.Info("in testRefresh")
return nil
}
func refreshGocui() {
lastRefresh = time.Now()
for {
time.Sleep(10 * time.Millisecond)
// log.Info("refresh checking ok")
if !me.ok {
continue
}
if time.Since(lastRefresh) > 1*time.Second {
if me.mouse.mouseUp {
log.Info("refresh now on mouseUp")
me.baseGui.Update(testRefresh)
} else {
log.Info("refresh skip on mouseDown")
// me.baseGui.Update()
}
lastRefresh = time.Now()
}
}
}
// set the widget start width & height
func newWindowTrigger() {
log.Log(NOW, "newWindowTriggerl() START")
for {
@ -222,7 +264,10 @@ func newWindowTrigger() {
relocateStdoutOffscreen()
}
tk.makeWindowActive()
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
// place the new window relative to the mouse
tk.redrawWindow(me.mouse.downW+8, me.mouse.downH-2)
// tk.redrawWindow(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")
}

View File

@ -4,8 +4,6 @@
package main
import (
"time"
log "go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
@ -30,16 +28,6 @@ func setFake(n *tree.Node) {
}
}
func waitOK() {
for {
if me.ok {
return
}
time.Sleep(10 * time.Millisecond)
}
}
// set the widget start width & height
// func (n *node) addWidget(n *tree.Node) {
func addWidget(n *tree.Node) {
if !me.ok {