MCPcopy
hub / github.com/g3n/engine / onVScrollBar

Method onVScrollBar

gui/table.go:1474–1501  ·  view source on GitHub ↗

onVScrollBar is called when a vertical scroll bar event is received

(evname string, ev interface{})

Source from the content-addressed store, hash-verified

1472
1473// onVScrollBar is called when a vertical scroll bar event is received
1474func (t *Table) onVScrollBar(evname string, ev interface{}) {
1475
1476 // Calculates the new first visible line
1477 pos := t.vscroll.Value()
1478 maxFirst := t.calcMaxFirst()
1479 first := int(math.Floor((float64(maxFirst) * pos) + 0.5))
1480
1481 // Sets the new selected row
1482 sel := t.rowCursor
1483 selChange := false
1484 if sel < first {
1485 t.rowCursor = first
1486 selChange = true
1487 } else {
1488 lines := first - t.firstRow
1489 lastRow := t.lastRow + lines
1490 if sel > lastRow {
1491 t.rowCursor = lastRow
1492 selChange = true
1493 }
1494 }
1495 t.scrollBarEvent = true
1496 t.firstRow = first
1497 t.recalc()
1498 if selChange {
1499 t.Dispatch(OnChange, nil)
1500 }
1501}
1502
1503// calcMaxFirst calculates the maximum index of the first visible row
1504// such as the remaining rows fits completely inside the table

Callers

nothing calls this directly

Calls 5

calcMaxFirstMethod · 0.95
recalcMethod · 0.95
DispatchMethod · 0.65
ValueMethod · 0.45
FloorMethod · 0.45

Tested by

no test coverage detected