120 lines
2.0 KiB
Go
120 lines
2.0 KiB
Go
|
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
|
||
|
}
|
||
|
|
||
|
switch tk.WidgetType {
|
||
|
case widget.Window:
|
||
|
var maxH int = 0
|
||
|
var maxW int = 0
|
||
|
for _, child := range tk.children {
|
||
|
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 {
|
||
|
sizeW, sizeH := child.Size()
|
||
|
|
||
|
// increment straight down
|
||
|
maxH += sizeH
|
||
|
if sizeW > maxW {
|
||
|
maxW = sizeW
|
||
|
}
|
||
|
}
|
||
|
return maxW, maxH
|
||
|
}
|
||
|
if tk.isFake {
|
||
|
return 0, 0
|
||
|
}
|
||
|
return tk.gocuiSize.Width(), tk.gocuiSize.Height()
|
||
|
}
|
||
|
|
||
|
func (w *guiWidget) sizeGrid() (int, int) {
|
||
|
|
||
|
// first compute the max sizes of the rows and columns
|
||
|
for _, child := range w.children {
|
||
|
sizeW, sizeH := child.Size()
|
||
|
|
||
|
// set the child's realWidth, and grid offset
|
||
|
if w.widths[child.AtW] < sizeW {
|
||
|
w.widths[child.AtW] = sizeW
|
||
|
}
|
||
|
if w.heights[child.AtH] < sizeH {
|
||
|
w.heights[child.AtH] = sizeH
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var maxW int = 0
|
||
|
var maxH int = 0
|
||
|
|
||
|
// find the width and height offset of the grid for AtW,AtH
|
||
|
for _, child := range w.children {
|
||
|
var totalW, totalH int
|
||
|
for i, w := range w.widths {
|
||
|
if i < child.AtW {
|
||
|
totalW += w
|
||
|
}
|
||
|
}
|
||
|
for i, h := range w.heights {
|
||
|
if i < child.AtH {
|
||
|
totalH += h
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if totalW > maxW {
|
||
|
maxW = totalW
|
||
|
}
|
||
|
if totalH > maxH {
|
||
|
maxH = totalH
|
||
|
}
|
||
|
}
|
||
|
return maxW, maxH
|
||
|
}
|
||
|
|
||
|
func (tk *guiWidget) sizeBox() (int, int) {
|
||
|
if tk.WidgetType != widget.Box {
|
||
|
return 0, 0
|
||
|
}
|
||
|
var maxW int = 0
|
||
|
var maxH int = 0
|
||
|
|
||
|
for _, child := range tk.children {
|
||
|
sizeW, sizeH := child.Size()
|
||
|
if child.direction == widget.Horizontal {
|
||
|
maxW += sizeW
|
||
|
if sizeH > maxH {
|
||
|
maxH = sizeH
|
||
|
}
|
||
|
} else {
|
||
|
maxH += sizeH
|
||
|
if sizeW > maxW {
|
||
|
maxW = sizeW
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return maxW, maxH
|
||
|
}
|
||
|
|