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 *HBoxLayout) 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 maximum height of all the panel's children |
| 99 | // and if the panel content height is less than this maximum, set its content height to this value. |
| 100 | if bl.autoHeight { |
| 101 | var maxHeight float32 |
| 102 | for _, ichild := range parent.Children() { |
| 103 | child := ichild.(IPanel).GetPanel() |
| 104 | if !child.Visible() { |
| 105 | continue |
| 106 | } |
| 107 | if child.Height() > maxHeight { |
| 108 | maxHeight = child.Height() |
| 109 | } |
| 110 | } |
| 111 | if parent.ContentHeight() < maxHeight { |
| 112 | parent.setContentSize(parent.ContentWidth(), maxHeight, false) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // If minHeight is set, get the sum of widths of this panel's children plus the spacings. |
| 117 | // If the panel content width is less than this width, set its content width to this value. |
| 118 | if bl.minHeight { |
| 119 | var totalWidth float32 |
| 120 | for _, ichild := range parent.Children() { |
| 121 | child := ichild.(IPanel).GetPanel() |
| 122 | if !child.Visible() { |
| 123 | continue |
| 124 | } |
| 125 | totalWidth += child.Width() |
| 126 | } |
| 127 | // Adds spacing |
| 128 | totalWidth += bl.spacing * float32(len(parent.Children())-1) |
| 129 | if parent.ContentWidth() < totalWidth { |
| 130 | parent.setContentSize(totalWidth, parent.ContentHeight(), false) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // Calculates the total width, expanded width, fixed width and |
| 135 | // the sum of the expand factor for all items. |
| 136 | var twidth float32 |
| 137 | //var ewidth float32 |
| 138 | var fwidth float32 |
| 139 | var texpand float32 |
| 140 | ecount := 0 |
| 141 | paramsDef := HBoxLayoutParams{Expand: 0, AlignV: AlignTop} |
| 142 | for pos, obj := range parent.Children() { |
| 143 | pan := obj.(IPanel).GetPanel() |
no test coverage detected