summaryrefslogtreecommitdiff
path: root/size.go
diff options
context:
space:
mode:
Diffstat (limited to 'size.go')
-rw-r--r--size.go203
1 files changed, 203 insertions, 0 deletions
diff --git a/size.go b/size.go
index ac12415..2d06e4e 100644
--- a/size.go
+++ b/size.go
@@ -4,6 +4,8 @@
package main
import (
+ "fmt"
+
"go.wit.com/widget"
)
@@ -133,3 +135,204 @@ func (w *guiWidget) sizeBox() (int, int) {
}
return maxW + me.BoxPadW, maxH
}
+
+/*
+var wtf bool
+
+func (tk *guiWidget) verifyRect() bool {
+ if !tk.Visible() {
+ // log.Info("verifyRect() tk is not visible", tk.cuiName)
+ return false
+ }
+ vw0, vh0, vw1, vh1, err := me.baseGui.ViewPosition(tk.cuiName)
+ if err != nil {
+ // log.Printf("verifyRect() gocui err=%v cuiName=%s v.Name=%s", err, tk.cuiName, tk.v.Name())
+ vw0, vh0, vw1, vh1, err = me.baseGui.ViewPosition(tk.v.Name())
+ if err != nil {
+ log.Printf("verifyRect() ACTUAL FAIL gocui err=%v cuiName=%s v.Name=%s", err, tk.cuiName, tk.v.Name())
+ return false
+ }
+ // return false
+ }
+ var ok bool = true
+ if vw0 != tk.full.w0 {
+ // log.Info("verifyRect() FIXING w0", tk.cuiName, vw0, vw1, vh0, vh1, tk.gocuiSize.w0, "w0 =", vw0)
+ tk.full.w0 = vw0
+ ok = false
+ }
+ if vw1 != tk.full.w1 {
+ // log.Info("verifyRect() FIXING w1", tk.cuiName, vw0, vw1, vh0, vh1, tk.gocuiSize.w1, "w1 =", vw1)
+ tk.full.w1 = vw1
+ ok = false
+ }
+ if vh0 != tk.full.h0 {
+ // log.Info("verifyRect() FIXING h0", tk.cuiName, vw0, vw1, vh0, vh1, tk.gocuiSize.h0)
+ tk.full.h0 = vh0
+ ok = false
+ }
+ if vh1 != tk.full.h1 {
+ // log.Info("verifyRect() FIXING h1", tk.cuiName, vw0, vw1, vh0, vh1, tk.gocuiSize.h1)
+ tk.full.h1 = vh1
+ ok = false
+ }
+ if !ok {
+ // log.Info("verifyRect() NEED TO FIX RECT HERE", tk.cuiName)
+ // tk.dumpWidget("verifyRect() FIXME")
+ }
+ // log.Printf("verifyRect() OK cuiName=%s v.Name=%s", tk.cuiName, tk.v.Name())
+ return true
+}
+*/
+
+func (tk *guiWidget) setFullSize() bool {
+ r := tk.getFullSize()
+
+ var changed bool
+ if tk.full.w0 != r.w0 {
+ tk.full.w0 = r.w0
+ changed = true
+ }
+ if tk.full.w1 != r.w1 {
+ tk.full.w1 = r.w1
+ changed = true
+ }
+ if tk.full.h0 != r.h0 {
+ tk.full.h0 = r.h0
+ changed = true
+ }
+ if tk.full.h1 != r.h1 {
+ tk.full.h1 = r.h1
+ changed = true
+ }
+ if changed {
+ tk.dumpWidget(fmt.Sprintf("setFullSize(changed)"))
+ }
+ return changed
+}
+
+func (tk *guiWidget) gridFullSize() rectType {
+ var r rectType
+ var first bool = true
+ for _, child := range tk.children {
+ cr := child.getFullSize()
+ if cr.Width() == 0 && cr.Height() == 0 {
+ // ignore widgets of zero size?
+ continue
+ }
+ if first {
+ // use the lowest width and hight from children widgets
+ r.w0 = cr.w0
+ r.h0 = cr.h0
+ r.w1 = cr.w1
+ r.h1 = cr.h1
+ first = false
+ // child.dumpWidget(fmt.Sprintf("grid(f)"))
+ continue
+ }
+ // child.dumpWidget(fmt.Sprintf("grid()"))
+ // use the lowest width and hight from children widgets
+ if r.w0 > cr.w0 {
+ r.w0 = cr.w0
+ }
+ if r.h0 > cr.h0 {
+ r.h0 = cr.h0
+ }
+ // use the highest width and hight from children widgets
+ if r.w1 < cr.w1 {
+ r.w1 = cr.w1
+ }
+ if r.h1 < cr.h1 {
+ r.h1 = cr.h1
+ }
+ }
+ tk.full.w0 = r.w0
+ tk.full.w1 = r.w1
+ tk.full.h0 = r.h0
+ tk.full.h1 = r.h1
+ return r
+}
+
+func (tk *guiWidget) buttonFullSize() rectType {
+ var r rectType
+ r.w0 = tk.gocuiSize.w0
+ r.w1 = tk.gocuiSize.w1
+ r.h0 = tk.gocuiSize.h0
+ r.h1 = tk.gocuiSize.h1
+
+ // try setting the full values here ? is this right?
+ tk.full.w0 = r.w0
+ tk.full.w1 = r.w1
+ tk.full.h0 = r.h0
+ tk.full.h1 = r.h1
+
+ return r
+}
+
+// this checks a widget to see if it is under (W,H), then checks the widget's children
+// anything that matches is passed back as an array of widgets
+func (tk *guiWidget) getFullSize() rectType {
+ var r rectType
+
+ if tk.node.WidgetType == widget.Grid {
+ return tk.gridFullSize()
+ }
+
+ // these are 'simple' widgets
+ // the full size is exactly what gocui uses
+ switch tk.node.WidgetType {
+ case widget.Label:
+ return tk.buttonFullSize()
+ case widget.Button:
+ return tk.buttonFullSize()
+ case widget.Checkbox:
+ return tk.buttonFullSize()
+ case widget.Dropdown:
+ return tk.buttonFullSize()
+ default:
+ }
+
+ if tk.v == nil {
+ r.w0 = tk.full.w0
+ r.w1 = tk.full.w1
+ r.h0 = tk.full.h0
+ r.h1 = tk.full.h1
+ } else {
+ r.w0 = tk.gocuiSize.w0
+ r.w1 = tk.gocuiSize.w1
+ r.h0 = tk.gocuiSize.h0
+ r.h1 = tk.gocuiSize.h1
+ }
+
+ // search through the children widgets in the binary tree
+ for _, child := range tk.children {
+ cr := child.getFullSize()
+ /* this didn't make things work either
+ if child.v == nil {
+ continue
+ }
+ */
+ // use the lowest width and hight from children widgets
+ if r.w0 > cr.w0 {
+ r.w0 = cr.w0
+ }
+ if r.h0 > cr.h0 {
+ r.h0 = cr.h0
+ }
+ // use the highest width and hight from children widgets
+ if r.w1 < cr.w1 {
+ r.w1 = cr.w1
+ }
+ if r.h1 < cr.h1 {
+ r.h1 = cr.h1
+ }
+
+ }
+
+ // try setting the full values here ? is this right?
+ tk.full.w0 = r.w0
+ tk.full.w1 = r.w1
+ tk.full.h0 = r.h0
+ tk.full.h1 = r.h1
+
+ return r
+}