sizes shouldn't include hidden widgets

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-30 02:54:37 -06:00
parent 4f19c8b64d
commit ab1c90e93e
1 changed files with 14 additions and 3 deletions

17
size.go
View File

@ -12,11 +12,17 @@ func (tk *guiWidget) Size() (int, int) {
return 0, 0 return 0, 0
} }
// don't count hidden widgets in size calculations
if tk.hidden {
return 0, 0
}
switch tk.WidgetType { switch tk.WidgetType {
case widget.Window: case widget.Window:
var maxH int = 0 var maxH int = 0
var maxW int = 0 var maxW int = 0
for _, child := range tk.children { for _, child := range tk.children {
if tk.hidden { continue }
sizeW, sizeH := child.Size() sizeW, sizeH := child.Size()
maxW += sizeW maxW += sizeW
if sizeH > maxH { if sizeH > maxH {
@ -35,6 +41,7 @@ func (tk *guiWidget) Size() (int, int) {
maxH := tk.gocuiSize.Height() maxH := tk.gocuiSize.Height()
for _, child := range tk.children { for _, child := range tk.children {
if tk.hidden { continue }
sizeW, sizeH := child.Size() sizeW, sizeH := child.Size()
// increment straight down // increment straight down
@ -52,9 +59,11 @@ func (tk *guiWidget) Size() (int, int) {
} }
func (w *guiWidget) sizeGrid() (int, int) { func (w *guiWidget) sizeGrid() (int, int) {
if w.hidden { return 0, 0 }
// first compute the max sizes of the rows and columns // first compute the max sizes of the rows and columns
for _, child := range w.children { for _, child := range w.children {
if w.hidden { continue }
sizeW, sizeH := child.Size() sizeW, sizeH := child.Size()
// set the child's realWidth, and grid offset // set the child's realWidth, and grid offset
@ -78,14 +87,16 @@ func (w *guiWidget) sizeGrid() (int, int) {
return totalW + me.GridPadW, totalH return totalW + me.GridPadW, totalH
} }
func (tk *guiWidget) sizeBox() (int, int) { func (w *guiWidget) sizeBox() (int, int) {
if tk.WidgetType != widget.Box { if w.WidgetType != widget.Box {
return 0, 0 return 0, 0
} }
if w.hidden { return 0, 0 }
var maxW int = 0 var maxW int = 0
var maxH int = 0 var maxH int = 0
for _, child := range tk.children { for _, child := range w.children {
if w.hidden {continue}
sizeW, sizeH := child.Size() sizeW, sizeH := child.Size()
if child.direction == widget.Horizontal { if child.direction == widget.Horizontal {
maxW += sizeW maxW += sizeW