2024-01-28 20:15:59 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/widget"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (tk *guiWidget) Size() (int, int) {
|
|
|
|
if tk == nil {
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
if me.treeRoot == nil {
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
2024-01-30 02:54:37 -06:00
|
|
|
// don't count hidden widgets in size calculations
|
2024-02-05 07:31:04 -06:00
|
|
|
if tk.node.Hidden() {
|
2024-01-30 02:54:37 -06:00
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
2024-01-28 20:15:59 -06:00
|
|
|
switch tk.WidgetType {
|
|
|
|
case widget.Window:
|
|
|
|
var maxH int = 0
|
|
|
|
var maxW int = 0
|
|
|
|
for _, child := range tk.children {
|
2024-02-05 07:31:04 -06:00
|
|
|
if tk.node.Hidden() {
|
2024-01-30 03:17:15 -06:00
|
|
|
continue
|
|
|
|
}
|
2024-01-28 20:15:59 -06:00
|
|
|
sizeW, sizeH := child.Size()
|
|
|
|
maxW += sizeW
|
|
|
|
if sizeH > maxH {
|
|
|
|
maxH = sizeH
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return maxW, maxH
|
|
|
|
case widget.Grid:
|
|
|
|
return tk.sizeGrid()
|
|
|
|
case widget.Box:
|
|
|
|
return tk.sizeBox()
|
|
|
|
case widget.Group:
|
|
|
|
// move the group to the parent's next location
|
|
|
|
maxW := tk.gocuiSize.Width()
|
|
|
|
maxH := tk.gocuiSize.Height()
|
|
|
|
|
|
|
|
for _, child := range tk.children {
|
2024-02-05 07:31:04 -06:00
|
|
|
if tk.node.Hidden() {
|
2024-01-30 03:17:15 -06:00
|
|
|
continue
|
|
|
|
}
|
2024-01-28 20:15:59 -06:00
|
|
|
sizeW, sizeH := child.Size()
|
|
|
|
|
|
|
|
// increment straight down
|
|
|
|
maxH += sizeH
|
|
|
|
if sizeW > maxW {
|
|
|
|
maxW = sizeW
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 00:49:46 -06:00
|
|
|
return maxW + me.GroupPadW + 3, maxH
|
2024-02-03 19:28:19 -06:00
|
|
|
case widget.Label:
|
|
|
|
return len(tk.String()) + 2, 1
|
2024-02-01 11:37:46 -06:00
|
|
|
case widget.Checkbox:
|
|
|
|
return len(tk.String()) + 2, 3
|
2024-01-28 20:15:59 -06:00
|
|
|
}
|
|
|
|
if tk.isFake {
|
|
|
|
return 0, 0
|
|
|
|
}
|
2024-01-28 21:15:15 -06:00
|
|
|
return len(tk.String()), 3
|
2024-01-28 20:15:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *guiWidget) sizeGrid() (int, int) {
|
2024-02-05 07:31:04 -06:00
|
|
|
if w.node.Hidden() {
|
2024-01-30 03:17:15 -06:00
|
|
|
return 0, 0
|
|
|
|
}
|
2024-01-28 20:15:59 -06:00
|
|
|
|
|
|
|
// first compute the max sizes of the rows and columns
|
|
|
|
for _, child := range w.children {
|
2024-02-05 07:31:04 -06:00
|
|
|
if w.node.Hidden() {
|
2024-01-30 03:17:15 -06:00
|
|
|
continue
|
|
|
|
}
|
2024-01-28 20:15:59 -06:00
|
|
|
sizeW, sizeH := child.Size()
|
|
|
|
|
2024-01-30 10:32:53 -06:00
|
|
|
sizeW += 2
|
|
|
|
|
2024-01-28 20:15:59 -06:00
|
|
|
// set the child's realWidth, and grid offset
|
2024-01-28 20:36:59 -06:00
|
|
|
if w.widths[child.node.State.AtW] < sizeW {
|
|
|
|
w.widths[child.node.State.AtW] = sizeW
|
2024-01-28 20:15:59 -06:00
|
|
|
}
|
2024-01-28 20:36:59 -06:00
|
|
|
if w.heights[child.node.State.AtH] < sizeH {
|
|
|
|
w.heights[child.node.State.AtH] = sizeH
|
2024-01-28 20:15:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the width and height offset of the grid for AtW,AtH
|
2024-01-28 21:22:34 -06:00
|
|
|
var totalW int = 0
|
|
|
|
var totalH int = 0
|
|
|
|
for _, width := range w.widths {
|
|
|
|
totalW += width
|
2024-01-28 20:15:59 -06:00
|
|
|
}
|
2024-01-28 21:22:34 -06:00
|
|
|
for _, h := range w.heights {
|
|
|
|
totalH += h
|
|
|
|
}
|
2024-01-29 23:39:33 -06:00
|
|
|
return totalW + me.GridPadW, totalH
|
2024-01-28 20:15:59 -06:00
|
|
|
}
|
|
|
|
|
2024-01-30 02:54:37 -06:00
|
|
|
func (w *guiWidget) sizeBox() (int, int) {
|
|
|
|
if w.WidgetType != widget.Box {
|
2024-01-28 20:15:59 -06:00
|
|
|
return 0, 0
|
|
|
|
}
|
2024-02-05 07:31:04 -06:00
|
|
|
if w.node.Hidden() {
|
2024-01-30 03:17:15 -06:00
|
|
|
return 0, 0
|
|
|
|
}
|
2024-01-28 20:15:59 -06:00
|
|
|
var maxW int = 0
|
|
|
|
var maxH int = 0
|
|
|
|
|
2024-01-30 02:54:37 -06:00
|
|
|
for _, child := range w.children {
|
2024-02-05 07:31:04 -06:00
|
|
|
if w.node.Hidden() {
|
2024-01-30 03:17:15 -06:00
|
|
|
continue
|
|
|
|
}
|
2024-01-28 20:15:59 -06:00
|
|
|
sizeW, sizeH := child.Size()
|
2024-02-05 04:28:42 -06:00
|
|
|
if child.node.State.Direction == widget.Vertical {
|
2024-01-28 20:15:59 -06:00
|
|
|
maxW += sizeW
|
|
|
|
if sizeH > maxH {
|
|
|
|
maxH = sizeH
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
maxH += sizeH
|
|
|
|
if sizeW > maxW {
|
|
|
|
maxW = sizeW
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-29 23:39:33 -06:00
|
|
|
return maxW + me.BoxPadW, maxH
|
2024-01-28 20:15:59 -06:00
|
|
|
}
|