listbinding.go 723 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package binding
  2. // DataList is the base interface for all bindable data lists.
  3. //
  4. // Since: 2.0
  5. type DataList interface {
  6. DataItem
  7. GetItem(index int) (DataItem, error)
  8. Length() int
  9. }
  10. type listBase struct {
  11. base
  12. items []DataItem
  13. }
  14. // GetItem returns the DataItem at the specified index.
  15. func (b *listBase) GetItem(i int) (DataItem, error) {
  16. if i < 0 || i >= len(b.items) {
  17. return nil, errOutOfBounds
  18. }
  19. return b.items[i], nil
  20. }
  21. // Length returns the number of items in this data list.
  22. func (b *listBase) Length() int {
  23. return len(b.items)
  24. }
  25. func (b *listBase) appendItem(i DataItem) {
  26. b.items = append(b.items, i)
  27. }
  28. func (b *listBase) deleteItem(i int) {
  29. b.items = append(b.items[:i], b.items[i+1:]...)
  30. }