diff options
Diffstat (limited to 'toolkit/gocui')
| -rw-r--r-- | toolkit/gocui/debug.go | 3 | ||||
| -rw-r--r-- | toolkit/gocui/main.go | 2 | ||||
| -rw-r--r-- | toolkit/gocui/plugin.go | 38 | ||||
| -rw-r--r-- | toolkit/gocui/view.go | 53 |
4 files changed, 77 insertions, 19 deletions
diff --git a/toolkit/gocui/debug.go b/toolkit/gocui/debug.go index 7512c1e..2669067 100644 --- a/toolkit/gocui/debug.go +++ b/toolkit/gocui/debug.go @@ -45,7 +45,8 @@ func (n *node) showWidgetPlacement(b bool, s string) { s1 += fmt.Sprintf("At(%2d,%2d) ", n.AtW, n.AtH) } } - log(b, s1, s, n.WidgetType, ",", n.Name) // , "text=", w.text) + tmp := "." + n.Name + "." + log(b, s1, s, n.WidgetType, ",", tmp) // , "text=", w.text) } func (n *node) dumpWidget(pad string) { diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go index 04e1255..11f525a 100644 --- a/toolkit/gocui/main.go +++ b/toolkit/gocui/main.go @@ -43,7 +43,7 @@ func catchActionChannel() { log(logError,"ERROR: console did not initialize") continue } - log(logNow, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name) + log(logInfo, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name) action(&a) } } diff --git a/toolkit/gocui/plugin.go b/toolkit/gocui/plugin.go index eae811d..18cb71f 100644 --- a/toolkit/gocui/plugin.go +++ b/toolkit/gocui/plugin.go @@ -51,8 +51,22 @@ func action(a *toolkit.Action) { case toolkit.CloseToolkit: log(logNow, "attempting to close the plugin and release stdout and stderr") standardExit() + case toolkit.Enable: + if n.Visible() { + // widget was already shown + } else { + log(logInfo, "Setting Visable to true", a.Name) + n.SetVisible(true) + } + case toolkit.Disable: + if n.Visible() { + log(logInfo, "Setting Visable to false", a.Name) + n.SetVisible(false) + } else { + // widget was already hidden + } default: - log(logError, "action() Unknown =", a.ActionType, a.WidgetType, a.Name) + log(logError, "action() ActionType =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.Name) } log(logInfo, "action() END") } @@ -70,16 +84,28 @@ func (n *node) AddText(text string) { } func (n *node) SetText(text string) { + var changed bool = false if (n == nil) { log(logNow, "widget is nil") return } - n.S = text - n.Text = text + if (n.Text != text) { + n.Text = text + changed = true + } + if (n.S != text) { + n.S = text + changed = true + } + if (! changed) { + return + } - n.textResize() - n.deleteView() - n.showView() + if (n.Visible()) { + n.textResize() + n.deleteView() + n.showView() + } } func (n *node) Set(val any) { diff --git a/toolkit/gocui/view.go b/toolkit/gocui/view.go index e69bf7c..28b80e0 100644 --- a/toolkit/gocui/view.go +++ b/toolkit/gocui/view.go @@ -20,20 +20,30 @@ func splitLines(s string) []string { return lines } -func (n *node) textResize() { +func (n *node) textResize() bool { w := n.tk var width, height int = 0, 0 + var changed bool = false for i, s := range splitLines(n.Text) { - log(logNow, "textResize() len =", len(s), i, s) + log(logInfo, "textResize() len =", len(s), i, s) if (width < len(s)) { width = len(s) } height += 1 } - w.gocuiSize.w1 = w.gocuiSize.w0 + width + me.FramePadW - w.gocuiSize.h1 = w.gocuiSize.h0 + height + me.FramePadH - n.showWidgetPlacement(logNow, "textResize()") + if (w.gocuiSize.w1 != w.gocuiSize.w0 + width + me.FramePadW) { + w.gocuiSize.w1 = w.gocuiSize.w0 + width + me.FramePadW + changed = true + } + if (w.gocuiSize.h1 != w.gocuiSize.h0 + height + me.FramePadH) { + w.gocuiSize.h1 = w.gocuiSize.h0 + height + me.FramePadH + changed = true + } + if (changed) { + n.showWidgetPlacement(logNow, "textResize() changed") + } + return changed } func (n *node) hideView() { @@ -58,17 +68,38 @@ func (n *node) showView() { x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName) log(logInfo, "showView() w.v already defined for widget", n.Name, err) + // n.smartGocuiSize() + changed := n.textResize() + + if (changed) { + log(logNow, "showView() textResize() changed. Should recreateView here wId =", w.cuiName) + } else { + log(logNow, "showView() Clear() and Fprint() here wId =", w.cuiName) + w.v.Clear() + fmt.Fprint(w.v, n.Text) + n.SetVisible(false) + n.SetVisible(true) + return + } + // if the gocui element has changed where it is supposed to be on the screen // recreate it - if (x0 != w.gocuiSize.w0) || (y0 != w.gocuiSize.h0) { - log(logError, "showView() w.v.w0 != x0", n.Name, w.gocuiSize.w0, x0) - log(logError, "showView() w.v.h0 != y0", n.Name, w.gocuiSize.h0, y0) + if (x0 != w.gocuiSize.w0) { + n.recreateView() + return + } + if (y0 != w.gocuiSize.h0) { + log(logError, "showView() start hight mismatch id=", w.cuiName, "gocui h vs computed h =", w.gocuiSize.h0, y0) + n.recreateView() + return + } + if (x1 != w.gocuiSize.w1) { + log(logError, "showView() too wide", w.cuiName, "w,w", w.gocuiSize.w1, x1) n.recreateView() return } - if (x1 != w.gocuiSize.w1) || (y1 != w.gocuiSize.h1) { - log(logError, "showView() w.v.w1 != x1", n.Name, w.gocuiSize.w1, x1) - log(logError, "showView() w.v.h1 != y1", n.Name, w.gocuiSize.h1, y1) + if (y1 != w.gocuiSize.h1) { + log(logError, "showView() too high", w.cuiName, "h,h", w.gocuiSize.h1, y1) n.recreateView() return } |
