Skip to content

Rebuild the color dialog with a space switcher, a comparison and slots - #358

Merged
smelfungus merged 8 commits into
masterfrom
color-dialog
Sep 26, 2026
Merged

smelfungus merged 8 commits into
masterfrom
color-dialog

Conversation

@smelfungus

Copy link
Copy Markdown
Member

ColorPickerDialog showed one space its caller fixed, with its title and buttons as strings, so an app could not let the user choose a space or change what the buttons do, and an app on another design system had no dialog to build on. Builds on #357.

Foundation (codes.side.colorpicker.foundation)

  • ColorPickerDialogState holds the original color, the spaces offered, the space shown and a ColorPickerState for the edit. result is the original itself until the color changes, so an untouched Display P3 color comes back unconverted, after a switch of space too. ColorPickerDialogState.Saver and rememberColorPickerDialogState save it across configuration changes and process death.
  • BasicColorComparison splits one swatch between the original, at the start, and the new color; the original half is a button that restores it.
  • BasicColorPickerDialogContent lays out header, switcher and picker by the space it is given, not the window's size classes: stacked when that fits the height; with the plane beside the sliders when it does not and there are 480 dp of width; scrolling otherwise. It never shrinks while open, so a space with no plane does not make the dialog jump. It measures its parts rather than asking their intrinsic sizes, so a slot built on BoxWithConstraints or a lazy list lays out like any other.

Material 3

  • ColorPickerDialog, in a ColorValue and a Color form, is Material's AlertDialog over that content. It switches between spaces, Okhsl, OkLCh, HSV and RGB by default, and opens in the value's own space, so a color it returned reopens where it was picked.
  • Its title, header, switcher and buttons are slots handed a sealed ColorPickerDialogScope, which reads the state and confirms or dismisses; ColorPickerDialogDefaults holds the defaults. The header is a ColorComparison and the color in hex; the switcher is segmented buttons for up to five spaces and a menu beyond.
  • onDismiss is onDismissRequest, as Material's dialogs name it; title, confirmText and dismissText give way to the slots.
  • A screen reader announces the dialog by its title's words, where Material's announces "Dialog".

The sample opens the new dialog. Two new screenshot references record it, stacked on a phone and side by side on a landscape tablet; the 28 existing references validate unchanged. A landscape phone's dialog window is about 420 dp wide, under the 480 dp side by side needs, so there the body scrolls. The README, the docs page and the CHANGELOG follow.

Tests: colorpicker-foundation 272 JVM, 138 Android host, 138 wasm; colorpicker-material3 159, 4, 4; color 216, 206, 206; color-compose 14, 14, 14. apiCheck, checkNoMaterial, the iOS klib compile, every sample and the 30 screenshot previews pass.

The dialog kept only a ColorPickerState, so nothing outside it knew the color it opened with or the space it showed, and a dialog on another design system had nothing to build on. ColorPickerDialogState holds the original, the spaces offered and the one shown, and the picker's state. Its result is the original itself until the color changes, so an untouched wide-gamut color comes back unconverted. rememberColorPickerDialogState saves all of it across configuration changes and process death, and a new initial value or list of spaces starts it over.
A dialog showed only the color being edited, so the user could not see what they started from or get back to it. BasicColorComparison draws the original in the start half and the new color in the end half over the checkerboard, and the original half becomes a button that restores it when given onRestoreOriginal. ColorComparison draws it in the theme's swatch shape and checkerboard colors. The halves fill a height given only as a minimum, which is what a comparison in a scrolling column gets.
A picker stacked under a header and a switcher is some 700 dp tall, more than a short window gives a dialog, and a dialog cannot read the window's size classes since it can sit in any window. BasicColorPickerDialogContent stacks header, switcher and picker when that fits the height it is given; when it does not and the width is at least 480 dp, it puts the plane beside the sliders with header and switcher in one row; and otherwise it scrolls. It never shrinks while open, so a space with no plane does not make the dialog jump. The stacked form it measures to decide stays composed while the other is shown, and its semantics are cleared then: a node that is composed but never placed is still in the semantics tree, and a screen reader would find every slider twice.
The dialog showed the one space its caller fixed, and its title and buttons were strings, so an app could neither let the user choose a space nor change what the buttons do. It switches between spaces, Okhsl, OkLCh, HSV and RGB by default, and opens in the value's own space, so a color it returned reopens where it was picked. It shows the original beside the new color, with the new one in hex, and pressing the original restores it. Its title, header, switcher and buttons are slots handed a ColorPickerDialogScope, which reads the state and confirms or dismisses. onDismiss is onDismissRequest, as Material's dialogs name it. A screen reader announces the dialog by its title's words, where Material's announces "Dialog". The sample opens it over its own state.
Nothing rendered the dialog, so a change to its layout would have gone unseen. Two references record it: stacked on a phone, and with the plane beside the sliders on a landscape tablet. A landscape phone's dialog window is about 420 dp wide, too narrow for that, so there its body scrolls. The 28 existing references validate unchanged.
The README still passed the dialog a space, a title and button texts, which it no longer takes. It shows the dialog as it is, with both screenshots, says what confirming returns after a switch or a restore and when the plane goes beside the sliders, and shows a slot confirming through the scope. The foundation table maps the dialog and the comparison, and the migration row names onDismissRequest. The CHANGELOG lists the dialog's changed parameters as breaking and its new parts as added.
ColorPickerDialogScope was an open interface, so an app could implement it, a test double say, and a member added to it later would break that app. Only the library implements it, as with the sliders' and planes' scopes, which are sealed already. Sealed, it can grow without breaking anyone.
The body asked its stacked form for its intrinsic height, and the switcher beside the sliders for its intrinsic width, so a slot built on SubcomposeLayout, a BoxWithConstraints, a lazy list or a tab row, crashed the dialog: SubcomposeLayout cannot answer intrinsic measurements. In a scrolling column the body also crashed, measuring its scrolling stacked form at an unlimited height. It now measures the stacked form and reads from its scroll whether it overflows; side by side, it measures the switcher first at its own width and gives the header the rest; and with no height limit it lays the stacked form out at its own height, unscrolled. Stacked, the switcher is given the whole width, so Material's switcher no longer fills its width itself.
@smelfungus
smelfungus merged commit 0cfe2be into master Sep 26, 2026
2 checks passed
@smelfungus
smelfungus deleted the color-dialog branch September 26, 2026 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant