Recalc sets the position and sizes of all of the panel's children. It is normally called by the parent panel when its size changes or a child is added or removed.
(ipan IPanel)
| 105 | // It is normally called by the parent panel when its size changes or |
| 106 | // a child is added or removed. |
| 107 | func (g *GridLayout) Recalc(ipan IPanel) { |
| 108 | |
| 109 | type cell struct { |
| 110 | panel *Panel // pointer to cell panel |
| 111 | params GridLayoutParams // copy of params or default |
| 112 | paramsDef bool // true if parameters are default |
| 113 | } |
| 114 | |
| 115 | type row struct { |
| 116 | cells []*cell // array of row cells |
| 117 | height float32 // row height |
| 118 | } |
| 119 | |
| 120 | // Saves the received panel |
| 121 | g.pan = ipan |
| 122 | if g.pan == nil { |
| 123 | return |
| 124 | } |
| 125 | |
| 126 | // Builds array of child rows |
| 127 | pan := ipan.GetPanel() |
| 128 | var irow int |
| 129 | var icol int |
| 130 | rows := []row{} |
| 131 | for _, node := range pan.Children() { |
| 132 | // Ignore invisible child |
| 133 | child := node.(IPanel).GetPanel() |
| 134 | if !child.Visible() { |
| 135 | continue |
| 136 | } |
| 137 | // Checks child layout params, if supplied |
| 138 | ip := child.layoutParams |
| 139 | var params *GridLayoutParams |
| 140 | var ok bool |
| 141 | var paramsDef bool |
| 142 | if ip != nil { |
| 143 | params, ok = child.layoutParams.(*GridLayoutParams) |
| 144 | if !ok { |
| 145 | panic("layoutParams is not GridLayoutParams") |
| 146 | } |
| 147 | paramsDef = false |
| 148 | } else { |
| 149 | params = &GridLayoutParams{} |
| 150 | paramsDef = true |
| 151 | |
| 152 | } |
| 153 | // If first column, creates row and appends to rows |
| 154 | if icol == 0 { |
| 155 | var r row |
| 156 | r.cells = make([]*cell, len(g.columns)) |
| 157 | rows = append(rows, r) |
| 158 | } |
| 159 | // Set current child panel to current cells |
| 160 | rows[irow].cells[icol] = &cell{child, *params, paramsDef} |
| 161 | // Updates next cell column and row |
| 162 | icol += 1 + params.ColSpan |
| 163 | if icol >= len(g.columns) { |
| 164 | irow++ |
no test coverage detected