color-w2: net change of 1 commits

- color-w2: written from its sheet
This commit is contained in:
bflatastic
2026-11-21 21:27:00 +07:00
parent 3f8dbe0121
commit ada9064e32
4 changed files with 232 additions and 39 deletions
+7 -5
View File
@@ -178,12 +178,13 @@ pub struct ChannelRow<'a> {
/// Whether the track shows over the transparency checkerboard.
checker: bool,
unit: ChannelUnit,
marks: &'a [f64],
}
impl<'a> ChannelRow<'a> {
/// A row named `label` over `value`, ruled by `rule`.
pub fn new(label: impl Into<Label>, value: Bind<'a, f64>, rule: ChannelRule) -> Self {
ChannelRow { label: label.into(), short: None, value, rule, track: None, checker: false, unit: ChannelUnit::None }
ChannelRow { label: label.into(), short: None, value, rule, track: None, checker: false, unit: ChannelUnit::None, marks: &[] }
}
/// Shows `short` at the line's start in place of the label, which stays the row's name.
@@ -213,14 +214,14 @@ impl<'a> ChannelRow<'a> {
/// The ticks under the track, passed to `SliderField::marks`; not the labelled form, whose caption line has no room
/// in a channel row.
#[must_use]
pub fn marks(self, marks: &'a [f64]) -> Self {
let _ = marks;
todo!("co.K9")
pub fn marks(mut self, marks: &'a [f64]) -> Self {
self.marks = marks;
self
}
/// Shows the row; the edit of the slider or the field, `None` when the row did not run.
pub fn show(self, ui: &mut Ui) -> Option<EditResponse<f64>> {
let ChannelRow { label, short, mut value, rule, track, checker, unit } = self;
let ChannelRow { label, short, mut value, rule, track, checker, unit, marks } = self;
let side = match short {
Some(short) => SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::text(Label::from(short)))),
None => SideLabel::new(),
@@ -229,6 +230,7 @@ impl<'a> ChannelRow<'a> {
.side(side.scrub(true))
.show(ui, |ui, _| {
channel_slider(label.clone(), value.reborrowed(), &rule, unit, track.clone().map(|stops| (stops, checker)))
.marks(marks)
.layout(SliderFieldLayout::Inline)
.field_sizing(Sizing::Content)
.thumb(SliderThumb::Triangle)
+78 -9
View File
@@ -1,15 +1,18 @@
//! Stories of `ColorPicker` and `ColorPickerDialog`: Compact, Compact with opacity, Compact with Only Web Colors, Full
//! with Photoshop's models and both warnings, Full with an InDesign-like model set, and the dialog behind its button.
use craft_behavior::Mixed;
use craft_theme::{Channel, ColorModel, DefaultOn, HsbModel, LabModel, MAX_CHANNELS, ModelValues, OklchModel, RgbModel, Srgba};
use craft_ui::contract::{Bind, Props as _, Show as _};
use craft_ui::contract::{Bind, EditResponse, Props as _, Show as _, ShowContainer as _};
use craft_ui::layout_components::Stack;
use craft_ui::runtime::env::Label;
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
use egui::Ui;
use super::channel::{ChannelRow, ChannelRule, TrackRamp};
use super::channel::{ChannelRow, ChannelRule, ChannelUnit, TrackRamp};
use super::screen_pick::ScreenPickButton;
use super::{ColorPicker, ColorPickerLayout, ColorPickerOutput, PickedColor};
use crate::ui::{AreaMode, ColorPickerDialog, ColorWarning};
use crate::ui::{AreaMode, ColorPickerDialog, ColorWarning, PickerLibrary, PickerSwatches};
use craft_ui::dialog::stories::hosted;
/// A naive CMYK in percent, without a working space: a host's model for the stories. A real host converts through its
@@ -132,6 +135,35 @@ fn color_picker_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
hosted(ui, data, (), || ColorPickerDialog::foreground(Srgba::rgb(0.2, 0.5, 0.8)))
}
/// The dialog with the Color Swatches button after Cancel: two libraries, the first of eight colours.
#[story(ColorPicker<'static>, covers = [], drive = Drive::Never)]
fn color_picker_dialog_with_swatches(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
hosted(ui, data, (), || {
let eight = [
("Red", Srgba::rgb(0.9, 0.1, 0.1)),
("Orange", Srgba::rgb(0.95, 0.5, 0.1)),
("Yellow", Srgba::rgb(0.95, 0.85, 0.1)),
("Green", Srgba::rgb(0.1, 0.65, 0.2)),
("Cyan", Srgba::rgb(0.1, 0.75, 0.85)),
("Blue", Srgba::rgb(0.1, 0.3, 0.9)),
("Violet", Srgba::rgb(0.5, 0.2, 0.8)),
("Magenta", Srgba::rgb(0.9, 0.1, 0.6)),
];
let basic = PickerLibrary::new("Basic", eight.into_iter().map(|(name, color)| (Label::from(name), color)).collect());
let grays = PickerLibrary::new("Grays", vec![(Label::from("Black"), Srgba::BLACK), (Label::from("White"), Srgba::rgb(1.0, 1.0, 1.0))]);
ColorPickerDialog::foreground(Srgba::rgb(0.1, 0.3, 0.9)).swatch_view(PickerSwatches::new(vec![basic, grays], Label::from("No swatches")))
})
}
/// The dialog whose only library is empty: the Color Swatches view shows the notice.
#[story(ColorPicker<'static>, covers = [], drive = Drive::Never)]
fn color_picker_dialog_with_an_empty_library(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
hosted(ui, data, (), || {
let libraries = vec![PickerLibrary::new("Empty", Vec::new())];
ColorPickerDialog::foreground(Srgba::rgb(0.2, 0.5, 0.8)).swatch_view(PickerSwatches::new(libraries, Label::from("No swatches")))
})
}
#[story(ScreenPickButton, covers = [Default], drive = Drive::Never)]
fn screen_pick_button(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
ScreenPickButton::new().label("Sample color from the screen").show(ui).into()
@@ -142,14 +174,51 @@ fn track_ramp(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
TrackRamp::new(vec![Srgba::rgb(0.0, 0.0, 0.0), Srgba::rgb(1.0, 1.0, 1.0)], false).show(ui).into()
}
/// The saturation row the channel-row stories share: HSB's rule over a white-to-red track.
fn saturation_row(value: Bind<'_, f64>) -> ChannelRow<'_> {
let channel = HsbModel.channels()[1];
ChannelRow::new("Saturation", value, ChannelRule::of(&channel)).track(vec![Srgba::rgb(1.0, 1.0, 1.0), Srgba::rgb(1.0, 0.0, 0.0)])
}
fn row_output(edit: Option<EditResponse<f64>>) -> StoryOutput {
edit.map_or_else(StoryOutput::default, StoryOutput::from)
}
#[story(ChannelRow<'static>, covers = [], drive = Drive::Never)]
fn channel_row(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let value = data.value("value", 40.0_f64);
let channel = HsbModel.channels()[1];
let row = ChannelRow::new("Saturation", Bind::bound(value), ChannelRule::of(&channel))
.track(vec![Srgba::rgb(1.0, 1.0, 1.0), Srgba::rgb(1.0, 0.0, 0.0)]);
match row.show(ui) {
Some(edit) => StoryOutput::from(edit),
None => StoryOutput::default(),
row_output(saturation_row(Bind::bound(value)).show(ui))
}
/// Rows whose number counts percent, degrees and a model's own unit text.
#[story(ChannelRow<'static>, covers = [], drive = Drive::Never)]
fn channel_row_units(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let value = data.value("value", 40.0_f64);
let mut edit = None;
for unit in [ChannelUnit::Percent, ChannelUnit::Degrees, ChannelUnit::Text("pt")] {
edit = edit.or(saturation_row(Bind::bound(&mut *value)).unit(unit).show(ui));
}
row_output(edit)
}
/// A row over a mixed value: the field shows the mixed readout until an edit makes it concrete.
#[story(ChannelRow<'static>, covers = [], drive = Drive::Never)]
fn channel_row_mixed(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
row_output(saturation_row(Bind::given(Mixed::<f64>::Mixed)).show(ui))
}
/// A row in a disabled container.
#[story(ChannelRow<'static>, covers = [], drive = Drive::Never)]
fn channel_row_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let value = data.value("value", 40.0_f64);
let shown = Stack::new().enabled(false).show(ui, |ui, _| saturation_row(Bind::bound(value)).show(ui));
row_output(shown.inner.flatten())
}
/// A row with ticks at 0, 50 and 100 under the track.
#[story(ChannelRow<'static>, covers = [], drive = Drive::Never)]
fn channel_row_marks(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let value = data.value("value", 40.0_f64);
let marks = [0.0, 50.0, 100.0];
row_output(saturation_row(Bind::bound(value)).marks(&marks).show(ui))
}
+90 -24
View File
@@ -14,12 +14,17 @@ use craft_cms::convert::CmykConverter;
use craft_host::Host;
use craft_host::target::Caps;
use craft_settings::Remembered;
use craft_theme::variant::Tone;
use craft_theme::{ColorModel, Srgba, builtin_models};
use craft_ui::contract::{Bind, CanvasGesture, Sampler as _, ShowContainer as _};
use craft_ui::choice::SwatchSpacing;
use craft_ui::contract::{Bind, CanvasGesture, Entry, Sampler as _, Show as _, ShowContainer as _};
use craft_ui::dialog::{
ButtonPlace, Dialog, DialogId, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id, serde_fields, set_serde_field,
};
use craft_ui::layout_components::Stack;
use craft_ui::notices::{Notice, NoticeLayout};
use craft_ui::patterns::form_dialogs::{HostRequests, ResetFooter};
use craft_ui::pickers::Select;
use craft_ui::runtime::env::{Env, Label};
use craft_ui::runtime::focus::Initial;
use craft_ui::runtime::overlay::CloseReason;
@@ -29,7 +34,7 @@ use craft_ui::sections::{DialogRole, FooterButton};
use egui::{Context, Id, Ui};
use std::sync::Arc;
use super::{ColorPicker, ColorPickerLayout, ColorWarning, Gamut, PickedColor, ScreenPickGesture};
use super::{ColorPicker, ColorPickerLayout, ColorWarning, Gamut, PickedColor, ScreenPickGesture, SwatchPalette};
use crate::{AreaMode, CmykModel, not_web_safe, web_safe};
craft_ui::words! {
@@ -44,6 +49,9 @@ craft_ui::words! {
add_to_swatches: "colorPickerDialog.addToSwatches" = "Add to Swatches";
out_of_gamut: "colorPickerDialog.outOfGamut" = "Out of gamut for printing: click for the nearest printable color";
not_web_color: "colorPickerDialog.notWebColor" = "Not a web color: click for the nearest web color";
color_swatches: "colorPickerDialog.colorSwatches" = "Color Swatches";
color_models: "colorPickerDialog.colorModels" = "Color Models";
library: "colorPickerDialog.library" = "Swatch library";
}
}
@@ -76,8 +84,7 @@ pub struct PickerLibrary {
impl PickerLibrary {
/// A library named `name` of `swatches`.
pub fn new(name: impl Into<Label>, swatches: Vec<(Label, Srgba)>) -> Self {
let _ = (name, swatches);
todo!("co.K10")
PickerLibrary { name: name.into(), swatches }
}
}
@@ -95,11 +102,40 @@ pub struct PickerSwatches {
impl PickerSwatches {
/// Swatch libraries `libraries`, with `empty` as the notice for an empty one.
pub fn new(libraries: Vec<PickerLibrary>, empty: impl Into<Label>) -> Self {
let _ = (libraries, empty);
todo!("co.K10")
PickerSwatches { libraries, empty: empty.into() }
}
}
/// The Color Swatches view: the library `Select` over the chosen library's spaced palette, whose cell equal to the colour
/// in `held` is marked and whose pick replaces `held`; the notice for a library without swatches. `library` is the
/// remembered index, which may lie past the end; it is written only when the user chooses another.
fn show_swatches(ui: &mut Ui, view: &PickerSwatches, library: &mut usize, held: &mut Mixed<PickedColor>, library_label: &Label) {
let mut chosen = (*library).min(view.libraries.len().saturating_sub(1));
Stack::new().show(ui, |ui, _| {
if !view.libraries.is_empty() {
let entries: Vec<Entry<usize>> = view.libraries.iter().enumerate().map(|(i, lib)| Entry::new(i, lib.name.clone())).collect();
let shown = Select::new(library_label.clone(), Bind::given(chosen), &entries).show(ui);
if let Some(next) = shown.value().copied() {
chosen = next;
*library = next;
}
}
match view.libraries.get(chosen).filter(|lib| !lib.swatches.is_empty()) {
Some(lib) => {
// A colour that is not set marks no cell of a library without it; black stands for "none yet".
let color = held.same().map_or(Srgba::BLACK, |picked| picked.color);
let shown = SwatchPalette::new(lib.name.clone(), Bind::given(color), &lib.swatches).spacing(SwatchSpacing::Spaced).show(ui);
if let Some(picked) = shown.edit.as_ref().and_then(|edit| edit.value()).copied() {
*held = Mixed::Same(PickedColor::rgb(picked));
}
}
None => {
Notice::new(Tone::Neutral, view.empty.clone()).layout(NoticeLayout::Centred).show(ui);
}
}
});
}
/// The remembered scope of [`ColorPickerMemory`].
const MEMORY_SCOPE: &str = "colorPicker.memory";
@@ -128,12 +164,12 @@ enum Title {
/// dialog takes the picker's size: one arrangement in every room.
///
/// - **Opening:** the hex field has the focus with its text selected, so typing replaces it. The field shows the
/// component it showed last time and Only Web Colors is as it was left ([`ColorPickerMemory`]); with Only Web Colors
/// component and view it showed last time and Only Web Colors is as it was left ([`ColorPickerMemory`]); with Only Web Colors
/// on, the opening colour is snapped to the nearest web colour and the compare swatch's "current" half shows the
/// snapped colour, so OK without an edit changes nothing (storytold/photocraft#4995).
/// - **Warnings:** the out-of-gamut chip shows when the colour leaves the CMYK gamut of the [`cmyk`](Self::cmyk)
/// converter (ΔE over 3); with Only Web Colors off, the web-colour chip shows for a colour that is not one. A click
/// on a chip takes its nearest colour.
/// - **Warnings:** the out-of-gamut chip shows when the colour leaves the [`gamut`](Self::gamut) (the CMYK gamut of the
/// [`cmyk`](Self::cmyk) converter when none is given); with Only Web Colors off, the web-colour chip shows for a colour
/// that is not one. A click on a chip takes its nearest colour.
/// - **Eyedroppers:** while the dialog is the top dialog it files an `EyedropperRequest` through
/// [`requests`](Self::requests); the host runs its canvas dropper, which samples under the dialog (the dialog
/// registers [`canvas`](Self::canvas) with the sampler) and answers with `HostRequests::answer_eyedropper`. The
@@ -159,6 +195,8 @@ pub struct ColorPickerDialog {
remember: bool,
add_to_swatches: bool,
cmyk: Option<CmykConverter>,
gamut: Option<Gamut<'static>>,
swatches: Option<PickerSwatches>,
eyedropper: bool,
canvas_samples: bool,
canvas: Option<Id>,
@@ -213,6 +251,8 @@ impl ColorPickerDialog {
remember: true,
add_to_swatches: true,
cmyk: None,
gamut: None,
swatches: None,
eyedropper: true,
canvas_samples: true,
canvas: None,
@@ -232,17 +272,17 @@ impl ColorPickerDialog {
/// A body button after Cancel switches between Color Models and Color Swatches: a library `Select` over a spaced
/// `SwatchPalette` with the current colour's cell marked, a pick being an edit. Without it there is no button.
#[must_use]
pub fn swatch_view(self, swatches: PickerSwatches) -> ColorPickerDialog {
let _ = swatches;
todo!("co.K10")
pub fn swatch_view(mut self, swatches: PickerSwatches) -> ColorPickerDialog {
self.swatches = Some(swatches);
self
}
/// The gamut the out-of-gamut chip tests with `Gamut::nearest`; without it the `cmyk` converter gives
/// `Gamut::cmyk`.
#[must_use]
pub fn gamut(self, gamut: Gamut<'static>) -> ColorPickerDialog {
let _ = gamut;
todo!("co.K12")
pub fn gamut(mut self, gamut: Gamut<'static>) -> ColorPickerDialog {
self.gamut = Some(gamut);
self
}
/// Fills `{name}` in a given title with `value`, after the title is translated: the title follows a language
@@ -286,9 +326,9 @@ impl ColorPickerDialog {
self
}
/// The document's CMYK converter: the C, M, Y, K fields convert through it and the out-of-gamut chip tests against
/// it. Without it the dialog uses the built-in coated converter, as PhotoCraft does for a document without a CMYK
/// profile.
/// The document's CMYK converter: the C, M, Y, K fields convert through it, and it is the out-of-gamut chip's gamut
/// when [`gamut`](Self::gamut) gives none. Without it the dialog uses the built-in coated converter, as PhotoCraft
/// does for a document without a CMYK profile.
#[must_use]
pub fn cmyk(mut self, converter: &CmykConverter) -> ColorPickerDialog {
self.cmyk = Some(converter.clone());
@@ -497,17 +537,34 @@ impl StackDialog for ColorPickerDialog {
}
};
let cmyk = CmykModel::new(self.cmyk.clone().unwrap_or_else(|| CmykConverter::coated().clone()));
let fallback;
let gamut = match &self.gamut {
Some(gamut) => gamut,
None => {
fallback = Gamut::cmyk(cmyk.converter().clone());
&fallback
}
};
let footer = ResetFooter::new(ui, None, true);
let changed = self.current != self.opening;
let mut buttons = footer.buttons(FooterButton::new(common.ok.clone(), DialogRole::Accept).enabled(self.current.is_some()), changed).to_vec();
// The buttons after OK and Cancel are placed by position; their indices are read back from the list.
let mut toggle_at = None;
if self.swatches.is_some() {
toggle_at = Some(buttons.len());
let label = if self.memory.swatches { words.color_models.clone() } else { words.color_swatches.clone() };
buttons.push(FooterButton::new(label, DialogRole::Other).stays_open(true));
}
let mut add_at = None;
if self.add_to_swatches {
add_at = Some(buttons.len());
buttons.push(FooterButton::new(words.add_to_swatches.clone(), DialogRole::Other).stays_open(true));
}
let arm = self.sampling.then_some(self.canvas).flatten();
let keep_open = self.canvas;
let screen = self.eyedropper && env.view().shell().caps.contains(Caps::SCREEN_CAPTURE);
let Self { current, opening, compare, memory, screen_busy, sample, pending_screen, open, .. } = self;
let Self { current, opening, compare, memory, screen_busy, sample, pending_screen, open, swatches: view, .. } = self;
let mut held: Mixed<PickedColor> = current.map_or(Mixed::Mixed, Mixed::Same);
let (sampled, busy, compare_with) = (sample.take(), *screen_busy, compare.then(|| opening.map_or(Mixed::Mixed, Mixed::Same)));
let color = current.map(|current| current.color);
@@ -526,14 +583,19 @@ impl StackDialog for ColorPickerDialog {
if let Some(canvas) = arm {
cx.pass_canvas_gesture(canvas, CanvasGesture::PRIMARY);
}
// PLAN: the swatch view should keep the value fields and replace only the area and strip, which the picker body
// (picker/mod.rs, not in this set) lays out; here it replaces the whole picker body.
if let Some(view) = view.as_ref().filter(|_| memory.swatches) {
show_swatches(ui, view, &mut memory.library, &mut held, &words.library);
return;
}
let mut models: Vec<&dyn ColorModel> = builtin_models().into_iter().filter(|model| model.default_on().full).collect();
models.push(&cmyk);
let mut warnings = Vec::new();
if let Some(color) = color {
let rgb = [color.r, color.g, color.b];
if let Some(nearest) = cmyk.converter().nearest_in_gamut(rgb, CmykConverter::PICKER_GAMUT_DE) {
warnings
.push(ColorWarning::new(words.out_of_gamut.clone(), Srgba { r: nearest[0], g: nearest[1], b: nearest[2], a: color.a }));
if let Some(nearest) = gamut.nearest(color) {
warnings.push(ColorWarning::new(words.out_of_gamut.clone(), Srgba { a: color.a, ..nearest }));
}
if !web_only && let Some(nearest) = not_web_safe(rgb) {
warnings.push(ColorWarning::web_colors(
@@ -563,12 +625,16 @@ impl StackDialog for ColorPickerDialog {
self.current = held.same().copied();
let (picked, closed) = (shown.output.picked, shown.output.closed);
if picked.is_some() && picked == toggle_at {
self.memory.swatches = !self.memory.swatches;
return None;
}
let ok = (picked == Some(0) || closed == Some(CloseReason::Enter)) && self.current.is_some();
if !ok && picked == Some(1) && footer.resetting() {
self.current = self.opening;
return None;
}
if picked == Some(2) {
if picked.is_some() && picked == add_at {
self.pending_swatch = self.current;
return None;
}
+57 -1
View File
@@ -4,13 +4,16 @@ use std::cell::RefCell;
use std::rc::Rc;
use craft_behavior::Mixed;
use craft_color_ui::ui::{ColorPicker, ColorPickerDialog, ColorPickerLayout, ColorPopover, ColorReadout, ColorWarning, PickedColor};
use craft_color_ui::ui::{
ColorPicker, ColorPickerDialog, ColorPickerLayout, ColorPopover, ColorReadout, ColorWarning, PickedColor, PickerLibrary, PickerSwatches,
};
use craft_host::{AppInfo, Host};
use craft_theme::{ColorModel, HsbModel, LabModel, ModelValues, OklchModel, RgbModel, Rgba, Size, Srgba, ThemeId};
use craft_ui::contract::{Bind, Role, ShowContainer as _};
use craft_ui::dialog::{DialogHost, DialogResult, dialog_id};
use craft_ui::layout::RowAlign;
use craft_ui::layout_components::Row;
use craft_ui::runtime::env::Label;
use craft_ui::testing::{Fixture, trial};
use egui::{Key, Modifiers, Rect, vec2};
@@ -354,6 +357,59 @@ fn the_color_picker_dialog_stands_its_buttons_over_the_second_group_in_photoshop
}
}
/// The Color Swatches button switches the dialog to the swatch view, which marks the cell of the current colour; a click
/// on another cell is an edit that OK answers. A remembered library past the end shows the last library, and an empty
/// library shows the notice.
#[trial]
fn the_color_picker_dialogs_swatch_view_marks_the_current_colour_and_a_pick_is_an_edit() {
let (red, blue, green) = (Srgba::rgb(1.0, 0.0, 0.0), Srgba::rgb(0.0, 0.0, 1.0), Srgba::rgb(0.0, 1.0, 0.0));
let library = |name: &'static str, swatches: &[(&'static str, Srgba)]| {
PickerLibrary::new(name, swatches.iter().map(|(name, color)| (Label::from(*name), *color)).collect())
};
let open = |libraries: Vec<PickerLibrary>| {
let dialogs = Rc::new(RefCell::new(DialogHost::new()));
let shown = Rc::clone(&dialogs);
let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui));
fixture.room(vec2(900.0, 700.0));
let dialog = ColorPickerDialog::new("fill", "Fill", red).swatch_view(PickerSwatches::new(libraries, "No swatches"));
dialogs.borrow_mut().open(dialog);
fixture.idle(6);
(dialogs, fixture)
};
let id = dialog_id(("color-picker", "fill"));
let (dialogs, mut fixture) = open(vec![library("Basic", &[("Red", red), ("Blue", blue)])]);
let toggle = fixture.by_label("Color Swatches").expect("the dialog shows the Color Swatches button");
fixture.click(&toggle).idle(4);
let selected = |fixture: &Fixture, name: &str| {
let cell = fixture.by_label(name).unwrap_or_else(|| panic!("the swatch view shows {name}"));
fixture.tree().data_of(cell.node).and_then(|data| data.is_selected()).unwrap_or(false)
};
assert!(selected(&fixture, "Red"), "the cell equal to the current colour is marked");
assert!(!selected(&fixture, "Blue"), "and no other");
let blue_cell = fixture.by_label("Blue").expect("the blue cell");
fixture.click(&blue_cell).idle(4);
let current = dialogs.borrow().get::<ColorPickerDialog>().and_then(|d| d.current()).map(|picked| picked.color.to_hex());
assert_eq!(current, Some(blue.to_hex()), "a click on a cell edits the colour");
let ctx = fixture.ctx().clone();
assert!(dialogs.borrow_mut().confirm::<ColorPickerDialog>(&ctx));
let answered = dialogs.borrow_mut().take::<ColorPickerDialog>().and_then(DialogResult::ok).map(|result| result.picked.color.to_hex());
assert_eq!(answered, Some(blue.to_hex()), "OK answers the picked colour");
let (dialogs, mut fixture) = open(vec![library("Basic", &[("Red", red)]), library("Spare", &[("Green", green)])]);
let ctx = fixture.ctx().clone();
assert_eq!(dialogs.borrow_mut().set_json_field(&ctx, id, "swatches", serde_json::json!(true)), Ok(()));
assert_eq!(dialogs.borrow_mut().set_json_field(&ctx, id, "library", serde_json::json!(9)), Ok(()));
fixture.idle(4);
assert!(fixture.by_label("Green").is_some(), "a library past the end shows the last library");
let (dialogs, mut fixture) = open(vec![library("Empty", &[])]);
let ctx = fixture.ctx().clone();
assert_eq!(dialogs.borrow_mut().set_json_field(&ctx, id, "swatches", serde_json::json!(true)), Ok(()));
fixture.idle(4);
assert!(fixture.texts().iter().any(|run| run.text == "No swatches"), "an empty library shows the notice");
}
/// The Compact picker's width is set by the area and the strip, and its rows take that width; its popover is as wide
/// wherever the well stands and whatever the room.
#[trial]