Separate source and display in TableView and TreeView
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 829
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 40
Description
**Is your feature request related to a problem? Please describe.**
Currently, the Cocoa backend is the only implementation to support arbitrary widgets in a `TableView` or `TreeView`. This is done by just returning a widget instead of a string or (icon, string) tuple in place of the data to be displayed. This is possible because the native `NSTableView` and `NSTreeView` are "view-based", i.e., their cells can display any Cocoa view.
This implementation cannot be copied to other platforms: in Windows, there is no direct support of arbitrary widgets in a Tree / Table (see #841). Gtk is more flexible by allowing data provided by the source to be rendered by a custom `Gtk.CellRenderer`. It does require *an entire column* to have the same renderer and is therefore less flexible than Cocoa.
Finally, a significant issue with the current Cocoa implementation is that the widget to be shown is defined by the source. It therefore is both the data *and* its representation. This becomes problematic for instance when displaying the same data by multiple views, as in the `table` example. Since a widget can only be drawn on screen once, all but one table will have an empty cell instead.
**Describe the solution you'd like**
It would be good to have a uniform solution for table cells across platforms which can display more than just a string and an icon. I like Gtk's concept of defining a "renderer" or view for each column to represent the data and providing several commonly used renderers as default. Those could be:
* icon + text
* checkbox + text
* progress bar
* ...
The user then provides methods to translate the column data to input for the renderer. This can be as simple as "bool -> checked state" or more complex such as "str -> icon".
In addition, one could allow the user to define custom views, though this will be more difficult to achieve in a cross-platform fashion. I envisage subclass of `toga.Widget` which takes column values during init and will be used by toga to construct a cell view for every platform.
**Describe alternatives you've considered**
I'm open to suggestions. The very different platform implementations complicate this a lot.
Contributor guide
Research direction
Start by comparing the existing Cocoa TableView/TreeView behavior with the Windows and Gtk implementations, using TableView, TreeView, and issue #841 as entry points. Define the cross-platform renderer/view boundary and common renderers before implementation; done means the same source/display separation works across platforms without reusing a widget instance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100