diff --git a/crates/color-ui/src/ui/picker/full.rs b/crates/color-ui/src/ui/picker/full.rs index 88f852e10..068022c2d 100644 --- a/crates/color-ui/src/ui/picker/full.rs +++ b/crates/color-ui/src/ui/picker/full.rs @@ -18,8 +18,9 @@ use super::{Collected, ColorPicker, ColorPickerWords, Pass, PickedColor}; use crate::ui::{AreaMode, AreaShape, CompareSwatch}; /// Two columns that never stack: the two halves of the picker, the right half (compare block and actions over the two -/// field groups), and each field group (the radio cell, then the channel's letter, field and unit). -const TWO_COLUMNS: &[ColumnWidth] = &[ColumnWidth::Content, ColumnWidth::Content]; +/// field groups), each field group (the radio cell, then the channel's letter, field and unit), and the dialog's Color +/// Swatches view (the swatches, then the buttons' cell). +pub(crate) const TWO_COLUMNS: &[ColumnWidth] = &[ColumnWidth::Content, ColumnWidth::Content]; /// The models the picker shows and the area modes it offers. #[derive(Clone, Copy)] diff --git a/crates/color-ui/src/ui/picker/mod.rs b/crates/color-ui/src/ui/picker/mod.rs index 484122748..4edd1e379 100644 --- a/crates/color-ui/src/ui/picker/mod.rs +++ b/crates/color-ui/src/ui/picker/mod.rs @@ -22,6 +22,7 @@ use egui::{Pos2, Response, Ui}; use super::{AreaMode, ColorWarning}; pub(crate) use channel::channel_name; pub use channel::{ChannelRow, ChannelRule, ChannelUnit, TrackRamp}; +pub(crate) use full::TWO_COLUMNS; pub use value::ColorConstraint; use value::Rules; diff --git a/crates/color-ui/src/ui/picker_dialog.rs b/crates/color-ui/src/ui/picker_dialog.rs index 928111299..312a91b26 100644 --- a/crates/color-ui/src/ui/picker_dialog.rs +++ b/crates/color-ui/src/ui/picker_dialog.rs @@ -17,11 +17,14 @@ use craft_settings::Remembered; use craft_theme::variant::Tone; use craft_theme::{ColorModel, Srgba, builtin_models}; use craft_ui::choice::{SwatchArrangement, SwatchSpacing, SwatchTable}; -use craft_ui::contract::{Bind, CanvasGesture, CollectionEvent, Entry, Sampler as _, Show as _, ShowCollection as _, ShowContainer as _}; +use craft_ui::contract::{ + Bind, CanvasGesture, CollectionEvent, Entry, FooterSlot, Gap, Sampler as _, Show as _, ShowCollection 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::layout::{CellAlign, GridFit}; +use craft_ui::layout_components::{Grid, Stack}; use craft_ui::notices::{Notice, NoticeLayout}; use craft_ui::patterns::form_dialogs::{HostRequests, ResetFooter}; use craft_ui::pickers::Select; @@ -37,6 +40,7 @@ use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::sync::Arc; +use super::picker::TWO_COLUMNS; use super::{ColorPicker, ColorPickerLayout, ColorWarning, Gamut, PickedColor, ScreenPickGesture, SwatchPalette}; use crate::{AreaMode, CmykModel, not_web_safe, web_safe}; @@ -121,31 +125,35 @@ impl PickerSwatches { /// 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. +/// remembered index, which may lie past the end; it is written only when the user chooses another. The dialog's buttons +/// stand in the cell after it, as they head the Full picker's second column. fn show_swatches(ui: &mut Ui, view: &PickerSwatches, library: &mut usize, held: &mut Mixed, 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> = 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)); + Grid::new(TWO_COLUMNS).fit(GridFit::Fixed).cells(CellAlign::Top).gap(Gap::Section).show(ui, |ui, _| { + Stack::new().show(ui, |ui, _| { + if !view.libraries.is_empty() { + let entries: Vec> = 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; } } - None => { - Notice::new(Tone::Neutral, view.empty.clone()).layout(NoticeLayout::Centred).show(ui); + 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); + } } - } + }); + let _ = FooterSlot::new().show(ui); }); } diff --git a/crates/color-ui/tests/it/picker.rs b/crates/color-ui/tests/it/picker.rs index dd20cb149..0b7b5bed2 100644 --- a/crates/color-ui/tests/it/picker.rs +++ b/crates/color-ui/tests/it/picker.rs @@ -541,10 +541,10 @@ fn a_request_for_the_swatches_opens_the_picker_on_its_swatch_view() { 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 libraries = vec![PickerLibrary::new("Basic", vec![(Label::from("Red"), red)])]; + let libraries = vec![PickerLibrary::new("Basic", vec![(Label::from("Brick"), red)])]; dialogs.borrow_mut().open(ColorPickerDialog::from_request(request).swatch_view(PickerSwatches::new(libraries, "No swatches"))); fixture.idle(6); - fixture.by_label("Red").is_some() + fixture.by_label("Brick").is_some() }; let request = || craft_ui::runtime::requests::ColorRequest::new("fill", red); assert!(shows_swatches(request().on_swatches()), "the swatch view shows the library's cells");