mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
ContourField: the thumbnail asks for the Contour Editor, the arrow opens the presets
PresetPicker's edit_face replaces the Edit Contour... button.
This commit is contained in:
@@ -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> {
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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<RefCell<Vec<ContourRequest>>>) {
|
||||
let requests = Rc::new(RefCell::new(Vec::new()));
|
||||
let seen = requests.clone();
|
||||
let mut contour = Contour::linear();
|
||||
let mut state = PresetState::<ContourKey>::new();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let words = Env::of(ui).words::<ContourWords>();
|
||||
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");
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user