setVScrollBar sets the visibility state of the vertical scrollbar
(state bool)
| 1436 | |
| 1437 | // setVScrollBar sets the visibility state of the vertical scrollbar |
| 1438 | func (t *Table) setVScrollBar(state bool) { |
| 1439 | |
| 1440 | // Visible |
| 1441 | if state { |
| 1442 | var scrollWidth float32 = 20 |
| 1443 | // Creates scroll bar if necessary |
| 1444 | if t.vscroll == nil { |
| 1445 | t.vscroll = NewVScrollBar(0, 0) |
| 1446 | t.vscroll.SetBorders(0, 0, 0, 1) |
| 1447 | t.vscroll.Subscribe(OnChange, t.onVScrollBar) |
| 1448 | t.Panel.Add(t.vscroll) |
| 1449 | } |
| 1450 | // Sets the scroll bar size and positions |
| 1451 | py, height := t.rowsHeight() |
| 1452 | t.vscroll.SetSize(scrollWidth, height) |
| 1453 | t.vscroll.SetPositionX(t.ContentWidth() - scrollWidth) |
| 1454 | t.vscroll.SetPositionY(py) |
| 1455 | t.vscroll.recalc() |
| 1456 | t.vscroll.SetVisible(true) |
| 1457 | if !t.scrollBarEvent { |
| 1458 | maxFirst := t.calcMaxFirst() |
| 1459 | t.vscroll.SetValue(float32(t.firstRow) / float32(maxFirst)) |
| 1460 | } else { |
| 1461 | t.scrollBarEvent = false |
| 1462 | } |
| 1463 | // scroll bar must be on top of all table rows |
| 1464 | t.SetTopChild(t.vscroll) |
| 1465 | // Not visible |
| 1466 | } else { |
| 1467 | if t.vscroll != nil { |
| 1468 | t.vscroll.SetVisible(false) |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | // onVScrollBar is called when a vertical scroll bar event is received |
| 1474 | func (t *Table) onVScrollBar(evname string, ev interface{}) { |
no test coverage detected