Add widgets to differentiate between Switch and Checkbox
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 827
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 40
Description
### What is the problem or limitation you are having?
Many platforms have support for both a Switch and a Checkbox widget; however, Toga doesn't currently expose this capability.
### Describe the solution you'd like
Two new widgets, plus a change to an existing one:
* Modify ``toga.Switch`` to canonically be a Switch on every platform
* Add ``toga.Checkbox``, a widget that is explicitly a checkbox on every platform.
* Add ``toga.Toggle``, a widget that does what Switch currently does - follow UX guidelines on the preferred representation of boolean concepts (checkbox on desktop, toggle on mobile).
The API for Switch, Checkbox and Toggle should be identical. The core should use the existing Switch code as a base class; with 2 subclasses providing the different factory instantiation. The backends will only need to add 1 extra implementation (where available), with the factory redirecting Toggle to the Switch or Checkbox implementation as required.
The documentation should recommend the use of "Toggle".
### Describe alternatives you've considered
Retain the status quo - a single Switch widget that follows UX convention.
Rename Switch to Toggle to break the coupling between the widget and the specific implementation.
### Additional context
Current platform support:
* macOS - NSSwitch / NSButton (with checkbox style)
* GTK - Gtk.Switch / Gtk.CheckButton
* Windows - No switch in Winforms, but UWP has ToggleSwitch; System.Windows.Forms.CheckBox
* iOS - UISwitch / no checkbox control; but UISwitch has UISwitchStyleCheckbox, but only honours it under Catalyst.
* Android - android.widget.Switch / android.widget.Checkbox
So - iOS and Windows are the only holdouts.
Examples of implementations for Switch for Windows and Checkbox on iOS exist; they are mostly "image button without extra chrome that changes image when pressed". While it is *possible* to fake it, Toga should adhere to platform guidelines, and omit those widget options. This will also serve to encourage the use of the "Toggle" widget.
The transition from Switch to Checkbox will require a backwards compatibility shim on Winforms to warn that toga.Switch will be removed in future.
Thanks to @Kuna42 for the suggestion (#2221)
Contributor guide
Research direction
Start by reading the existing toga.Switch implementation and its backend factory paths, then inspect the platform-specific Switch support described for macOS, GTK, Windows, iOS, and Android. Check the widget API and documentation entry points; done means Switch, Checkbox, and Toggle have the requested platform behavior, compatibility warning, and recommended usage documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, ios, python
- Domain
- desktop, frontend, mobile
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100