Skip to content

Collection Widgets

Andy Williams edited this page Apr 2, 2024 · 5 revisions

Note

This document is archived as it refers to a design process.

Collection widgets are used to efficiently display and interact with a collection of data.

Types

  • List - 1 Dimensional - []binding.Binding
  • Table - 2 Dimensional - [][]binding.Binding
  • Tree - Hierarchical - []binding.Binding or map[string]binding.Binding

Background

// TODO

Previous Work

Data API

Data API 2

List Proposal

Design

// TODO

Algorithm

  1. Collection widget asks the data binding how many items it has
  2. Collection widget asks the adapter how many types of items will be in the widget (eg. 1 for a simple list, or more for lists with header/footers/dividers) and creates a canvas.Pool for each type.
  3. For each visible index;
    • Collection widget asks the adapter what the type of the item is.
    • Collection widget asks the pool for a fyne.CanvasObject of that type (item/header/footer/divider), if the pool is empty a fyne.CanvasObject is created by the adapter.
    • If the item is a data item;
      • Collection widget asks the data binding for the item.
      • Collection widget asks the adapter to bind the item to the fyne.CanvasObject.

Architecture

There are four main components involved with displaying a list of items;

  • binding.List - provides access to an underlying list of data and triggers listeners when it changes.
  • canvas.Adapter - converts the specific data item from the binder into a fyne.CanvasObject for the list to display.
  • canvas.Pool - maintains a collection of fyne.CanvasObject to be reused rather than allocating a new one.
  • widget.List - renders a range of items from the data binding and receives events.

binding.List

See Data API 2

canvas.Adapter

type Adapter interface {
    // Return the number of different types of cells.
    Types() int
    // Returns the type of the cell at the given index.
    TypeOf(index int) int
    // Creates a cell of the given type.
    Create(type int) fyne.CanvasObject
    // Binds the given canvas object to the binding.
    Bind(fyne.CanvasObject, binding.Binding)
}

canvas.Pool

type Pool interface {
    Obtain() fyne.CanvasObject
    Release(fyne.CanvasObject)
}

widget.List

list := &widget.List{}
list.BindItems(binding.List)
list.SetAdapter(canvas.Adapter)
list.OnSelected = func(index int) {
    log.Println("Selected:", index)
}

Welcome to the Fyne wiki.

Project documentation

Getting involved

Platform details

Clone this wiki locally