MCPcopy Index your code
hub / github.com/g3n/engine / recalcRow

Method recalcRow

gui/table.go:1358–1416  ·  view source on GitHub ↗

recalcRow recalculates the positions and sizes of all cells of the specified row Should be called when the row is created and column visibility or order is changed.

(ri int)

Source from the content-addressed store, hash-verified

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.
1358func (t *Table) recalcRow(ri int) {
1359
1360 trow := t.rows[ri]
1361 // Calculates and sets row height
1362 maxheight := float32(0)
1363 for ci := 0; ci < len(t.header.cols); ci++ {
1364 // If column is hidden, ignore
1365 c := t.header.cols[ci]
1366 if !c.Visible() {
1367 continue
1368 }
1369 cell := trow.cells[c.order]
1370 cellHeight := cell.MinHeight() + cell.label.Height()
1371 if cellHeight > maxheight {
1372 maxheight = cellHeight
1373 }
1374 }
1375 trow.SetContentHeight(maxheight)
1376
1377 // Sets row cells sizes and positions and sets row width
1378 px := float32(0)
1379 for ci := 0; ci < len(t.header.cols); ci++ {
1380 // If column is hidden, ignore
1381 c := t.header.cols[ci]
1382 cell := trow.cells[c.order]
1383 if !c.Visible() {
1384 cell.SetVisible(false)
1385 continue
1386 }
1387 // Sets cell position and size
1388 cell.SetPosition(px, 0)
1389 cell.SetVisible(true)
1390 cell.SetSize(c.Width(), trow.ContentHeight())
1391 // Checks for format function
1392 if c.formatFunc != nil {
1393 text := c.formatFunc(TableCell{t, ri, c.id, cell.value})
1394 cell.label.SetText(text)
1395 }
1396 // Sets the cell label alignment inside the cell
1397 ccw := cell.ContentWidth()
1398 lw := cell.label.Width()
1399 space := ccw - lw
1400 lx := float32(0)
1401 switch c.align {
1402 case AlignLeft:
1403 case AlignRight:
1404 if space > 0 {
1405 lx = ccw - lw
1406 }
1407 case AlignCenter:
1408 if space > 0 {
1409 lx = space / 2
1410 }
1411 }
1412 cell.label.SetPosition(lx, 0)
1413 px += c.Width()
1414 }
1415 trow.SetContentWidth(px)

Callers 2

insertRowMethod · 0.95
recalcMethod · 0.95

Calls 12

MinHeightMethod · 0.80
SetContentHeightMethod · 0.80
ContentHeightMethod · 0.80
ContentWidthMethod · 0.80
SetContentWidthMethod · 0.80
VisibleMethod · 0.65
HeightMethod · 0.65
SetVisibleMethod · 0.65
SetPositionMethod · 0.65
WidthMethod · 0.65
SetSizeMethod · 0.45
SetTextMethod · 0.45

Tested by

no test coverage detected