diff --git a/crates/color-ui/src/ui/hud.rs b/crates/color-ui/src/ui/hud.rs index f8a15f453a..0d6b4e3660 100644 --- a/crates/color-ui/src/ui/hud.rs +++ b/crates/color-ui/src/ui/hud.rs @@ -6,7 +6,7 @@ use crate::AreaMode; use craft_behavior::{EditEvent, EditEvents, Metrics, PartKey, Sense}; use craft_theme::Srgba; use craft_ui::contract::{ - Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, EscapeEdit, MeasureCx, Outcome, POPUP_PAD, PaintUi, PartsCx, + Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, EscapeEdit, MeasureCx, Outcome, POPOVER_PAD, PaintUi, PartsCx, Pattern, Props as _, Role, Show as _, ShowContainer as _, pad_of, }; use craft_ui::popover::Popover; @@ -77,7 +77,7 @@ fn start_point(geometry: Geometry, start: Option) -> Pos2 { /// The popover's top left, so that the start colour's point in the area sits at `at`. fn origin(tokens: &UiTokens, at: Pos2, start: Option) -> Pos2 { let point = start_point(Geometry::of(tokens), start); - let pad = pad_of(tokens, POPUP_PAD); + let pad = pad_of(tokens, POPOVER_PAD); pos2(at.x - pad - point.x, at.y - pad - point.y) } diff --git a/crates/color-ui/src/ui/picker_dialog.rs b/crates/color-ui/src/ui/picker_dialog.rs index 98e6125e2c..e646baf396 100644 --- a/crates/color-ui/src/ui/picker_dialog.rs +++ b/crates/color-ui/src/ui/picker_dialog.rs @@ -24,7 +24,7 @@ use craft_ui::dialog::{ ButtonPlace, Dialog, DialogId, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id, serde_fields, set_serde_field, }; use craft_ui::layout::{CellAlign, GridFit}; -use craft_ui::layout_components::{Grid, Stack}; +use craft_ui::layout_components::{Grid, Row, Stack}; use craft_ui::notices::{Notice, NoticeLayout}; use craft_ui::patterns::form_dialogs::{HostRequests, ResetFooter}; use craft_ui::pickers::Select; @@ -41,7 +41,7 @@ use std::borrow::Cow; use std::sync::Arc; use super::picker::TWO_COLUMNS; -use super::{ColorPicker, ColorPickerLayout, ColorWarning, Gamut, PickedColor, ScreenPickGesture, SwatchPalette}; +use super::{ColorPicker, ColorPickerLayout, ColorPickerWords, ColorWarning, CompareSwatch, Gamut, PickedColor, ScreenPickGesture, SwatchPalette}; use crate::{AreaMode, CmykModel, not_web_safe, web_safe}; type StandardColors = (Vec<(Label, Srgba)>, Vec<(Label, Srgba)>); @@ -318,27 +318,47 @@ impl TabbedBody<'_> { let (cells, greys) = self.standard.map_or((&[][..], &[][..]), |(cells, greys)| (cells.as_slice(), greys.as_slice())); let current = held.same().map(|picked| picked.color); let mut pick = None; - Stack::new().show(ui, |ui, _| { - let honeycomb = SwatchTable::new(self.words.standard_colors.clone(), cells) - .arrangement(SwatchArrangement::Honeycomb) - .tips(true) - .selection(Bind::given(chosen(cells, current))) - .show_all(ui); - if let Some(at) = honeycomb.selected { - pick = cells.get(at).map(|(_, color)| *color); - } - let row = SwatchTable::new(self.words.greys.clone(), greys) - .per_row(greys.len().max(1)) - .tips(true) - .selection(Bind::given(chosen(greys, current))) - .show_all(ui); - if let Some(at) = row.selected { - pick = greys.get(at).map(|(_, color)| *color); + let mut restore = None; + // The compare block stands beside the honeycomb, as it does beside the Custom page's area. + Row::new().show(ui, |ui, _| { + Stack::new().show(ui, |ui, _| { + let honeycomb = SwatchTable::new(self.words.standard_colors.clone(), cells) + .arrangement(SwatchArrangement::Honeycomb) + .tips(true) + .selection(Bind::given(chosen(cells, current))) + .show_all(ui); + if let Some(at) = honeycomb.selected { + pick = cells.get(at).map(|(_, color)| *color); + } + let row = SwatchTable::new(self.words.greys.clone(), greys) + .per_row(greys.len().max(1)) + .tips(true) + .selection(Bind::given(chosen(greys, current))) + .show_all(ui); + if let Some(at) = row.selected { + pick = greys.get(at).map(|(_, color)| *color); + } + }); + if let Some(compare) = self.compare { + let new = held.same().map_or(Mixed::Mixed, |picked| Mixed::Same(picked.color)); + let current = match compare { + Mixed::Same(current) => Mixed::Same(current.color), + Mixed::Mixed => Mixed::Mixed, + }; + let label = Env::of(ui).words::().new_color.clone(); + if CompareSwatch::new(label, new, current).show(ui).restore + && let Mixed::Same(current) = compare + { + restore = Some(current); + } } }); if let Some(color) = pick { *held = Mixed::Same(PickedColor::rgb(color)); } + if let Some(current) = restore { + *held = Mixed::Same(current); + } } /// The compact picker over the colour, the compare swatch beside its area; the model switch is the memory's. diff --git a/crates/color-ui/tests/it/picker.rs b/crates/color-ui/tests/it/picker.rs index 6e6ab0d54a..d6dc9368a8 100644 --- a/crates/color-ui/tests/it/picker.rs +++ b/crates/color-ui/tests/it/picker.rs @@ -597,6 +597,15 @@ fn the_tabbed_colors_dialog_opens_on_its_tab_and_answers_from_either_page() { fixture.click(&cell); fixture.idle(4); assert_eq!(dialog_color(&dialogs).as_deref(), Some("#0000ff"), "a honeycomb pick is the colour"); + // #7984: the Standard page shows the compare block too, and its current half restores the opening colour. + assert!(fixture.by_label("New color").is_some(), "the Standard page shows the compare block"); + let restore = fixture.by_label("Restore current color").expect("the compare block's current half"); + fixture.click(&restore); + fixture.idle(4); + assert_eq!(dialog_color(&dialogs).as_deref(), Some("#123456"), "the current half restores the opening colour"); + let cell = fixture.by_label("Standard 2").expect("the honeycomb shows its cells"); + fixture.click(&cell); + fixture.idle(4); assert!(dialogs.borrow_mut().confirm::(&ctx), "OK answers"); let answered = dialogs.borrow_mut().take::().and_then(DialogResult::ok).map(|result| result.picked.color.to_hex()); diff --git a/crates/menu/src/ribbon/gallery.rs b/crates/menu/src/ribbon/gallery.rs index 683fb76fb2..08f9683a10 100644 --- a/crates/menu/src/ribbon/gallery.rs +++ b/crates/menu/src/ribbon/gallery.rs @@ -226,6 +226,8 @@ pub enum GalleryFace<'a> { thumbnails: &'a Thumbnails, /// What renders the thumbnail. source: &'a dyn ThumbSource, + /// Whether the transparency grid shows behind transparent pixels. + checker: bool, }, /// A tile painted directly. Paint(&'a dyn Fn(&ContentPainterCx, Rect)), @@ -250,7 +252,17 @@ impl<'a> GalleryFace<'a> { /// A thumbnail under `key`, rendered by `source` into `thumbnails`. pub fn rendered(key: u64, thumbnails: &'a Thumbnails, source: &'a dyn ThumbSource) -> Self { - GalleryFace::Rendered { key, thumbnails, source } + GalleryFace::Rendered { key, thumbnails, source, checker: true } + } + + /// Whether a rendered thumbnail shows the transparency grid behind its transparent pixels (default on). Off for a + /// thumbnail that is a mask on the surface it sits on, such as an equation symbol. Other faces ignore it. + #[must_use] + pub fn checker(mut self, on: bool) -> Self { + if let GalleryFace::Rendered { checker, .. } = &mut self { + *checker = on; + } + self } /// The picture this face shows, `size` high and `aspect` times as wide. It is decoration: the tile that holds it @@ -258,7 +270,9 @@ impl<'a> GalleryFace<'a> { fn picture(&self, aspect: ThumbAspect, size: ThumbSize) -> Picture<'a> { let picture = match self { GalleryFace::Image { key, revision, image } => Picture::new(Label::default(), *key, *image).revision(*revision), - GalleryFace::Rendered { key, thumbnails, source } => Picture::rendered(Label::default(), *key, thumbnails, *source), + GalleryFace::Rendered { key, thumbnails, source, checker } => { + Picture::rendered(Label::default(), *key, thumbnails, *source).checker(*checker) + } GalleryFace::Paint(paint) => { let paint = *paint; Picture::painter(Label::default(), aspect, move |cx: &ContentPainterCx<'_>, rect: Rect| paint(cx, rect)) diff --git a/crates/menu/src/ribbon/gallery/stories.rs b/crates/menu/src/ribbon/gallery/stories.rs index 786f074e2b..2a80c79e78 100644 --- a/crates/menu/src/ribbon/gallery/stories.rs +++ b/crates/menu/src/ribbon/gallery/stories.rs @@ -172,8 +172,7 @@ fn gallery_rendered(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { let options = ThumbnailOptions::new(); let thumbnails = Thumbnails::::in_context(ui.ctx(), "craft_menu.gallery.story", options); let source = FakeThumbSource::::new().later(true); - let items: Vec> = (0..COUNT) - .map(|at| GalleryItem { key: at, label: name(at), face: GalleryFace::Rendered { key: at as u64, thumbnails: &thumbnails, source: &source } }) - .collect(); + let items: Vec> = + (0..COUNT).map(|at| GalleryItem { key: at, label: name(at), face: GalleryFace::rendered(at as u64, &thumbnails, &source) }).collect(); show(ui, &items) } diff --git a/crates/menu/src/shortcuts/view/lists.rs b/crates/menu/src/shortcuts/view/lists.rs index 00b35ce177..5bd47ed1a5 100644 --- a/crates/menu/src/shortcuts/view/lists.rs +++ b/crates/menu/src/shortcuts/view/lists.rs @@ -24,6 +24,8 @@ use crate::shortcuts::state::{DialogState, Env}; const LISTS_SHARE: f32 = 0.5; /// The detail column's share of the width beside the lists. const DETAIL_SHARE: f32 = 0.5; +/// The most Categories rows shown before the list scrolls. +const CATEGORY_ROWS: u16 = 6; const PANES: [ColumnWidth; 2] = [ColumnWidth::fill(LISTS_SHARE), ColumnWidth::fill(DETAIL_SHARE)]; /// One frame of the command-lists body: a search field, the Categories list beside the Commands @@ -62,6 +64,8 @@ fn categories(ui: &mut Ui, env: &Env<'_>, state: &mut DialogState) { let mut selection = Selection::new(at.into_iter().collect(), at, at); let out = List::::new(words.categories.clone()) .id_salt("categories") + // A short list, so the Commands list under it keeps room in a dialog of ordinary height. + .max_rows(CATEGORY_ROWS) .select(SelectMode::Single) .selection(Bind::bound(&mut selection)) .show_items(ui, &Titles(&labels), &mut |key, _| ListRow::new(labels[*key].clone())); diff --git a/crates/menu/tests/it/ribbon_gallery.rs b/crates/menu/tests/it/ribbon_gallery.rs index 44abf3d767..93e83d0e78 100644 --- a/crates/menu/tests/it/ribbon_gallery.rs +++ b/crates/menu/tests/it/ribbon_gallery.rs @@ -263,3 +263,26 @@ fn the_current_tile_paints_an_accent_fill_and_edge_even_when_focused() { assert!(shapes.iter().any(|p| p.fill == fill && near(p, current)), "{who}: the focused current tile keeps its fill"); } } + +/// How many shapes a gallery of one rendered tile of a transparent image paints, as built or with `checker(false)`. +fn shapes_of_rendered(opt_out: bool) -> usize { + use craft_ui::primitives::textures::{FakeThumbSource, ThumbnailOptions, Thumbnails}; + let mut fixture = Fixture::new(move |ui| { + let options = ThumbnailOptions::new().jobs(std::sync::Arc::new(craft_host::InlineJobs)); + let thumbnails = Thumbnails::::in_context(ui.ctx(), "gallery_checker_test", options); + let source = FakeThumbSource::::new(); + // The default case sets nothing, so a default that turned the grid off fails here. + let face = GalleryFace::rendered(1, &thumbnails, &source); + let face = if opt_out { face.checker(false) } else { face }; + let items = [GalleryItem { key: 0_usize, label: Label::from("Mask"), face }]; + Gallery::new("Symbols", &items, None).tiles(1, 1).show(ui); + }); + fixture.settle(); + fixture.frame_shapes().len() +} + +#[trial] +fn a_rendered_gallery_tile_paints_a_checker_unless_it_opts_out() { + let (with, without) = (shapes_of_rendered(false), shapes_of_rendered(true)); + assert!(with > without, "the default paints {with} shapes, the opt-out {without}: the grid is the difference"); +} diff --git a/crates/menu/tests/it/shortcuts/lists.rs b/crates/menu/tests/it/shortcuts/lists.rs index 6322b27524..71131385c9 100644 --- a/crates/menu/tests/it/shortcuts/lists.rs +++ b/crates/menu/tests/it/shortcuts/lists.rs @@ -1,7 +1,7 @@ //! The Customize Keyboard layout: each change is applied at once and Escape closes without rolling back. use craft_keymap::{Binding, CommandDef, CommandRef, Keymap, Platform, Scope, Scopes, Trigger}; -use craft_menu::shortcuts::{Layout, Outcome}; +use craft_menu::shortcuts::{Area, Layout, Outcome}; use craft_ui::contract::Role; use craft_ui::testing::trial; use egui::{Key, Modifiers}; @@ -79,3 +79,29 @@ fn command_lists_assign_remove_and_close_apply_each_change_at_once() { assert_eq!(keys(&rig), left, "the keymap keeps the edits"); assert!(rig.bindings("file.export").is_empty(), "the taken chord is not given back"); } + +/// A long Categories list must not take the room the Commands list needs: in a dialog of ordinary height a command row +/// still shows above the footer. +#[trial] +fn commands_keep_room_beside_a_long_categories_list() { + let rig = Rig::tuned(Platform::Mac, |options| { + options.layout = Layout::CommandLists; + options.own_areas = true; + options.size = Some(egui::vec2(640.0, 460.0)); + options.areas = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"].map(|name| Area::new(name, name, |_| true)).to_vec(); + }); + let row = rig.find("Bring to Front").center(); + let footer = rig.find("Reset All…").center(); + assert!(row.y < footer.y, "the command row ({row:?}) sits above the footer ({footer:?})"); + // The capped list scrolls: the arrow keys still reach its last entry. + let mut rig = rig; + rig.click("A"); + for _ in 0..11 { + rig.press(Modifiers::NONE, Key::ArrowDown); + } + let area = { + let shared = rig.shared.borrow(); + shared.state.snapshot(&shared.km).expect("the dialog has shown").area + }; + assert_eq!(area, "L", "the last Categories entry is reachable"); +} diff --git a/crates/pages/src/ui/mod.rs b/crates/pages/src/ui/mod.rs index 6b1fbfffca..62446f4cd6 100644 --- a/crates/pages/src/ui/mod.rs +++ b/crates/pages/src/ui/mod.rs @@ -52,8 +52,8 @@ pub use reading::{ReadingNav, ReadingNavOutput, ReadingState, ReadingView, Readi pub use setup::{PageLayoutChoice, PageLayoutMenus, PageSetupDialog}; pub use sync_views::{Lead, SyncedViews, SyncedViewsOutput, SyncedViewsState}; pub use table::{ - BorderEdges, BorderPreset, CellAlign, CellSelectionOverlay, EdgeKey, EdgeLook, EdgePicker, RowHeight, SampleArea, TableChange, TableGeometry, - TableProperties, TablePropertiesOutput, TableSizePicker, TableSizePickerOutput, TableValues, TextDirection, + BorderEdges, BorderPreset, CellAlign, CellSelectionOverlay, EdgeKey, EdgeLook, EdgePicker, EdgeSize, RowHeight, SampleArea, TableChange, + TableGeometry, TableProperties, TablePropertiesOutput, TableSizePicker, TableSizePickerOutput, TableValues, TextDirection, }; pub use text_selection::{ MarkArea, MarkKind, PageTextSource, PageTexts, TextMark, TextMarks, TextSelectState, TextSelectTool, TextSelection, TextSpan, diff --git a/crates/pages/src/ui/table/edges.rs b/crates/pages/src/ui/table/edges.rs index 06d5626abc..8bf957674c 100644 --- a/crates/pages/src/ui/table/edges.rs +++ b/crates/pages/src/ui/table/edges.rs @@ -163,6 +163,8 @@ pub struct EdgePickerStyle { focus: FocusLook, /// The side of the square. side: f32, + /// The side of the square at [`EdgeSize::Sample`]. + sample_side: f32, /// How far the outer lines sit inside the square, and how near a line the pointer picks it. inset: f32, /// The area inside the lines. @@ -198,6 +200,20 @@ pub struct EdgePicker<'a> { /// How the picture is drawn: the proxy diagram, or a sample of the borders on text, a paragraph or a page. #[prop] look: EdgeLook, + /// The extent of the square: a thumbnail, or a sample-sized preview. + #[prop] + preview: EdgeSize, +} + +/// How large the picker's square is. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum EdgeSize { + /// A thumbnail (`size.thumb.lg`). + #[default] + Thumb, + /// A preview at sample size (`size.thumb.sample.lg`), for a Borders or Shading dialog's page-like preview. + Sample, } /// How the borders preview is drawn. @@ -246,7 +262,7 @@ struct ClickRun { impl<'a> EdgePicker<'a> { /// A picker named `label` editing `edges`. pub fn new(label: impl Into