recalc calculates the visibility, positions and sizes of all row cells. should be called in the following situations: - the table is resized - row is added, inserted or removed - column alignment and expansion changed - column visibility is changed - horizontal or vertical scroll position changed
()
| 1308 | // - column visibility is changed |
| 1309 | // - horizontal or vertical scroll position changed |
| 1310 | func (t *Table) recalc() { |
| 1311 | |
| 1312 | // Get available row height for rows |
| 1313 | starty, theight := t.rowsHeight() |
| 1314 | |
| 1315 | // Determines if it is necessary to show the scrollbar or not. |
| 1316 | scroll := false |
| 1317 | py := starty |
| 1318 | for ri := 0; ri < len(t.rows); ri++ { |
| 1319 | trow := t.rows[ri] |
| 1320 | py += trow.height |
| 1321 | if py > starty+theight { |
| 1322 | scroll = true |
| 1323 | break |
| 1324 | } |
| 1325 | } |
| 1326 | t.setVScrollBar(scroll) |
| 1327 | // Recalculates the header |
| 1328 | t.recalcHeader() |
| 1329 | |
| 1330 | // Sets the position and sizes of all cells of the visible rows |
| 1331 | py = starty |
| 1332 | for ri := 0; ri < len(t.rows); ri++ { |
| 1333 | trow := t.rows[ri] |
| 1334 | // If row is before first row or its y coordinate is greater the table height, |
| 1335 | // sets it invisible |
| 1336 | if ri < t.firstRow || py > starty+theight { |
| 1337 | trow.SetVisible(false) |
| 1338 | continue |
| 1339 | } |
| 1340 | t.recalcRow(ri) |
| 1341 | // Set row y position and visible |
| 1342 | trow.SetPosition(0, py) |
| 1343 | trow.SetVisible(true) |
| 1344 | t.updateRowStyle(ri) |
| 1345 | // Set the last completely visible row index |
| 1346 | if py+trow.Height() <= starty+theight { |
| 1347 | t.lastRow = ri |
| 1348 | } |
| 1349 | //log.Error("ri:%v py:%v theight:%v", ri, py, theight) |
| 1350 | py += trow.height |
| 1351 | } |
| 1352 | // Status panel must be on top of all the row panels |
| 1353 | t.SetTopChild(&t.statusPanel) |
| 1354 | } |
| 1355 | |
| 1356 | // recalcRow recalculates the positions and sizes of all cells of the specified row |
| 1357 | // Should be called when the row is created and column visibility or order is changed. |
no test coverage detected