From 9a2b60fd7f694d01590b831df2abedb0813f496b Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 01:16:47 +0000 Subject: [PATCH] ContourField: the thumbnail asks for the Contour Editor, the arrow opens the presets PresetPicker's edit_face replaces the Edit Contour... button. --- .../imaging/src/ui/layer_style/contour/mod.rs | 14 +++-- crates/imaging/tests/it/contour_field.rs | 53 +++++++++++++++++++ crates/imaging/tests/it/main.rs | 2 + 3 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 crates/imaging/tests/it/contour_field.rs diff --git a/crates/imaging/src/ui/layer_style/contour/mod.rs b/crates/imaging/src/ui/layer_style/contour/mod.rs index d229b4a7d..bef94bf4f 100644 --- a/crates/imaging/src/ui/layer_style/contour/mod.rs +++ b/crates/imaging/src/ui/layer_style/contour/mod.rs @@ -8,9 +8,8 @@ mod stories; use std::sync::Arc; use craft_behavior::{EditEvents, Mixed}; -use craft_ui::buttons::Button; use craft_ui::choice::Checkbox; -use craft_ui::contract::{Bind, EditResponse, NoValue, Outcome, Pattern, Props as _, Show as _, ShowContainer as _, clicked}; +use craft_ui::contract::{Bind, EditResponse, NoValue, Outcome, Pattern, Props as _, Show as _, ShowContainer as _}; use craft_ui::layout_components::{Row, Stack}; use craft_ui::list::ThumbAspect; use craft_ui::patterns::presets::{PickerField, PresetEvent, PresetFooterEvent, PresetPicker, PresetRow, PresetState}; @@ -29,7 +28,6 @@ craft_ui::words! { #[non_exhaustive] pub struct ContourWords { editor: "contour.editor" = "Contour Editor"; - edit: "contour.edit" = "Edit Contour…"; presets: "contour.presets" = "Contour presets"; anti_aliased: "contour.antiAliased" = "Anti-aliased"; preset: "contour.preset" = "Preset"; @@ -207,9 +205,8 @@ pub fn from_curve(curve: &Curve, name: &str) -> Option { Contour::from_points(name, points) } -/// A contour field: the current contour's thumbnail opening the preset browser (a `PresetPicker`), an Edit Contour… -/// button that asks for the Contour Editor, and, with [`anti_alias`](ContourField::anti_alias), the Anti-aliased -/// check box. +/// A contour field: a `PresetPicker` whose thumbnail asks for the Contour Editor and whose arrow opens the preset +/// browser, and, with [`anti_alias`](ContourField::anti_alias), the Anti-aliased check box. /// /// A pick reports an edit of the contour. A built-in contour keeps its name; the one the editor made is "Custom". /// Deleting a user's contour from the browser, or New in its footer, reports a [`ContourAction`]. @@ -269,6 +266,7 @@ impl<'a> ContourField<'a> { let picker = PresetPicker::new(label.clone(), Bind::bound(&mut key), rows, state.reborrowed()) .field(PickerField::Thumbnail) .can_delete(|key| matches!(key, ContourKey::User(_))) + .edit_face() .show(ui); for event in &picker.events { match event { @@ -277,10 +275,10 @@ impl<'a> ContourField<'a> { _ => {} } } - picked = Some(picker.edit); - if clicked(&Button::new(words.edit.clone()).show(ui)) { + if picker.edit_requested { edit_contour = Some(ContourRequest { key: label.as_str().to_owned(), contour: held.clone() }); } + picked = Some(picker.edit); if let Some(bind) = anti_alias.as_mut() && let Some(Mixed::Same(Some(on))) = bind.reborrow().read(root) { diff --git a/crates/imaging/tests/it/contour_field.rs b/crates/imaging/tests/it/contour_field.rs new file mode 100644 index 000000000..b135c218d --- /dev/null +++ b/crates/imaging/tests/it/contour_field.rs @@ -0,0 +1,53 @@ +//! `ContourField`: the thumbnail asks for the Contour Editor, the rest of the field opens the presets. + +use std::cell::RefCell; +use std::rc::Rc; + +use craft_imaging::layer_style::Contour; +use craft_imaging::ui::layer_style::{ContourField, ContourKey, ContourRequest, ContourWords, contour_rows}; +use craft_ui::contract::{Bind, Role}; +use craft_ui::patterns::presets::PresetState; +use craft_ui::runtime::env::Env; +use craft_ui::testing::{Fixture, trial}; +use egui::{Rect, pos2}; + +/// A field over Linear, recording the editor requests it reports. +fn rig() -> (Fixture, Rc>>) { + let requests = Rc::new(RefCell::new(Vec::new())); + let seen = requests.clone(); + let mut contour = Contour::linear(); + let mut state = PresetState::::new(); + let mut fixture = Fixture::new(move |ui| { + let words = Env::of(ui).words::(); + let rows = contour_rows(&Contour::presets(), &[], &words, None); + let out = ContourField::new("Contour", Bind::bound(&mut contour), &rows, Bind::bound(&mut state)).show(ui); + seen.borrow_mut().extend(out.edit_contour); + }); + fixture.settle(); + (fixture, requests) +} + +fn field(fixture: &Fixture) -> Rect { + fixture.by_role(Role::COMBO_BOX).first().expect("the contour field").rect +} + +/// The browser is open while its presets are in the tree; the closed field names only Linear. +fn browser_open(fixture: &Fixture) -> bool { + fixture.by_label("Cone").is_some() +} + +#[trial] +fn the_thumbnail_asks_for_the_editor_and_the_arrow_opens_the_presets() { + let (mut fixture, requests) = rig(); + let rect = field(&fixture); + fixture.click_at(pos2(rect.left() + rect.height() / 2.0, rect.center().y)); + fixture.settle(); + assert_eq!(requests.borrow().len(), 1, "a click on the thumbnail asks for the Contour Editor"); + assert_eq!(requests.borrow()[0].contour, Contour::linear()); + assert!(!browser_open(&fixture), "a click on the thumbnail opens no browser"); + + fixture.click_at(pos2(rect.right() - rect.height() / 2.0, rect.center().y)); + fixture.settle(); + assert!(browser_open(&fixture), "a click on the arrow opens the presets"); + assert_eq!(requests.borrow().len(), 1, "the arrow asks for no editor"); +} diff --git a/crates/imaging/tests/it/main.rs b/crates/imaging/tests/it/main.rs index 293f9398f..62d9b8711 100644 --- a/crates/imaging/tests/it/main.rs +++ b/crates/imaging/tests/it/main.rs @@ -3,6 +3,7 @@ mod adjust_editors; mod adjust_tone; mod blur_pins; +mod contour_field; mod curve; mod fill; mod filter_gallery; @@ -16,6 +17,7 @@ mod scopes; mod select; mod select_mask; mod selection; +mod threshold; mod transform_preview; mod vanishing_point; mod warp;