diff --git a/debug.go b/debug.go index b782955..189ef31 100644 --- a/debug.go +++ b/debug.go @@ -49,11 +49,11 @@ func (tk *guiWidget) dumpWidget(s string) { var s1 string var pId int // tk.verifyRect() - if tk.node.Parent == nil { + if tk.parent == nil { log.Logf(WARN, "showWidgetPlacement() parent == nil wId=%d cuiName=%s", tk.WidgetId(), tk.cuiName) pId = 0 } else { - pId = tk.node.Parent.WidgetId + pId = tk.parent.WidgetId() } s1 = fmt.Sprintf("(wId,pId)=(%4d,%4d) ", tk.WidgetId(), pId) sizeW, sizeH := tk.Size() diff --git a/node.go b/node.go new file mode 100644 index 0000000..42ed93e --- /dev/null +++ b/node.go @@ -0,0 +1,59 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "go.wit.com/widget" +) + +func (tk *guiWidget) WidgetType() widget.WidgetType { + if tk.node == nil { + return widget.Label + } + return tk.node.WidgetType +} + +func (tk *guiWidget) WidgetId() int { + return tk.node.WidgetId +} + +func (tk *guiWidget) GetLabel() string { + return tk.node.GetLabel() +} + +func (tk *guiWidget) IsEnabled() bool { + return tk.node.IsEnabled() +} + +func (tk *guiWidget) Checked() bool { + return tk.node.State.Checked +} + +func (tk *guiWidget) Hidden() bool { + if tk.node == nil { + return false + } + if tk.parent == nil { + return tk.node.Hidden() + } + if tk.parent.WidgetId() == 0 { + return tk.node.Hidden() + } + if tk.parent.Hidden() { + return true + } + return tk.node.Hidden() +} + +func (tk *guiWidget) Direction() widget.Orientation { + return tk.node.State.Direction +} + +func (tk *guiWidget) GridW() int { + return tk.node.State.AtW +} + +func (tk *guiWidget) GridH() int { + return tk.node.State.AtH +} diff --git a/place.go b/place.go index b77a505..11038a1 100644 --- a/place.go +++ b/place.go @@ -50,7 +50,7 @@ func (w *guiWidget) placeBox(startW int, startH int) { // re-get the Size (they should not have changed, but maybe they can?) // TODO: figure this out or report that they did sizeW, sizeH = child.Size() - if w.node.State.Direction == widget.Vertical { + if w.Direction() == widget.Vertical { log.Log(INFO, "BOX IS VERTICAL ", w.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String()) // expand based on the child height newH += sizeH diff --git a/plugin.go b/plugin.go index baf1d87..8899bd2 100644 --- a/plugin.go +++ b/plugin.go @@ -154,8 +154,8 @@ func (tk *guiWidget) GetText() string { // return gocui.view name? return tk.cuiName } - if tk.node.State.Label != "" { - return tk.node.State.Label + if tk.GetLabel() != "" { + return tk.GetLabel() } return "" } diff --git a/treeWidget.go b/treeWidget.go index 0477470..5b231bb 100644 --- a/treeWidget.go +++ b/treeWidget.go @@ -18,8 +18,8 @@ func initWidget(n *tree.Node) *guiWidget { w = new(guiWidget) w.node = n - w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK" - // w.node.WidgetType = n.WidgetType + w.cuiName = strconv.Itoa(w.WidgetId()) + " TK" + // w.WidgetType() = n.WidgetType w.labelN = n.State.Label if w.labelN == "" { // remove this debugging hack once things are stable and fixed @@ -39,11 +39,11 @@ func initWidget(n *tree.Node) *guiWidget { p := n.Parent if p == nil { - log.Log(ERROR, "parent == nil", w.String(), n.WidgetId, w.node.WidgetType) + log.Log(ERROR, "parent == nil", w.String(), n.WidgetId, w.WidgetType()) return w } if p.TK == nil { - log.Log(ERROR, "parent.TK == nil", w.String(), n.WidgetId, w.node.WidgetType) + log.Log(ERROR, "parent.TK == nil", w.String(), n.WidgetId, w.WidgetType()) return w } @@ -69,7 +69,7 @@ func setupCtrlDownWidget() { func (w *guiWidget) deleteView() { // make sure the view isn't really there - // log.Log(GOCUI, "deleteView()", w.cuiName, w.node.WidgetType, w.node.WidgetId) + // log.Log(GOCUI, "deleteView()", w.cuiName, w.WidgetType(), w.WidgetId()) me.baseGui.DeleteView(w.cuiName) w.v = nil } @@ -80,7 +80,7 @@ func (tk *guiWidget) String() string { if curval != "" { return curval } - curval = strings.TrimSpace(tk.node.GetLabel()) + curval = strings.TrimSpace(tk.GetLabel()) if curval != "" { return curval } @@ -152,46 +152,3 @@ func (tk *guiWidget) findWidgetByView(v *gocui.View) *guiWidget { } return nil } - -func (tk *guiWidget) WidgetType() widget.WidgetType { - if tk.node == nil { - return widget.Label - } - return tk.node.WidgetType -} - -func (tk *guiWidget) WidgetId() int { - return tk.node.WidgetId -} - -func (tk *guiWidget) GetLabel() string { - return tk.node.GetLabel() -} - -func (tk *guiWidget) IsEnabled() bool { - return tk.node.IsEnabled() -} - -func (tk *guiWidget) Checked() bool { - return tk.node.State.Checked -} - -func (tk *guiWidget) Hidden() bool { - if tk.node == nil { - return false - } - if tk.parent == nil { - return tk.node.Hidden() - } - if tk.parent.WidgetId() == 0 { - return tk.node.Hidden() - } - if tk.parent.Hidden() { - return true - } - return tk.node.Hidden() -} - -func (tk *guiWidget) Direction() widget.Orientation { - return tk.node.State.Direction -}