Recalc recalculates and sets the position and sizes of all children
(ipan IPanel)
| 84 | |
| 85 | // Recalc recalculates and sets the position and sizes of all children |
| 86 | func (bl *VBoxLayout) Recalc(ipan IPanel) { |
| 87 | |
| 88 | // Saves the received panel |
| 89 | bl.pan = ipan |
| 90 | if bl.pan == nil { |
| 91 | return |
| 92 | } |
| 93 | parent := ipan.GetPanel() |
| 94 | if len(parent.Children()) == 0 { |
| 95 | return |
| 96 | } |
| 97 | |
| 98 | // If autoHeight is set, get the sum of heights of this panel's children plus the spacings. |
| 99 | // If the panel content height is less than this height, set its content height to this value. |
| 100 | if bl.autoHeight { |
| 101 | var totalHeight float32 |
| 102 | for _, ichild := range parent.Children() { |
| 103 | child := ichild.(IPanel).GetPanel() |
| 104 | if !child.Visible() || !child.Bounded() { |
| 105 | continue |
| 106 | } |
| 107 | totalHeight += child.Height() |
| 108 | } |
| 109 | // Adds spacing |
| 110 | totalHeight += bl.spacing * float32(len(parent.Children())-1) |
| 111 | if parent.ContentHeight() < totalHeight { |
| 112 | parent.setContentSize(parent.ContentWidth(), totalHeight, false) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // If autoWidth is set, get the maximum width of all the panel's children |
| 117 | // and if the panel content width is less than this maximum, set its content width to this value. |
| 118 | if bl.autoWidth { |
| 119 | var maxWidth float32 |
| 120 | for _, ichild := range parent.Children() { |
| 121 | child := ichild.(IPanel).GetPanel() |
| 122 | if !child.Visible() || !child.Bounded() { |
| 123 | continue |
| 124 | } |
| 125 | if child.Width() > maxWidth { |
| 126 | maxWidth = child.Width() |
| 127 | } |
| 128 | } |
| 129 | if parent.ContentWidth() < maxWidth { |
| 130 | parent.setContentSize(maxWidth, parent.ContentHeight(), false) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // Calculates the total height, expanded height, fixed height and |
| 135 | // the sum of the expand factor for all items. |
| 136 | var theight float32 |
| 137 | //var eheight float32 |
| 138 | var fheight float32 |
| 139 | var texpand float32 |
| 140 | ecount := 0 |
| 141 | paramsDef := VBoxLayoutParams{Expand: 0, AlignH: AlignLeft} |
| 142 | for pos, obj := range parent.Children() { |
| 143 | pan := obj.(IPanel).GetPanel() |
no test coverage detected