|
|
|
@@ -103,6 +103,22 @@ impl TargetKey {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The swatch last picked in the Swatches view and the stop or point it is picked for.
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
struct PickedSwatch {
|
|
|
|
|
target: TargetKey,
|
|
|
|
|
name: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl PickedSwatch {
|
|
|
|
|
/// The active document's swatch `name`, picked for `target`.
|
|
|
|
|
fn of(app: &VectorcraftApp, target: &Target, name: &str) -> Option<Self> {
|
|
|
|
|
let key = TargetKey::of(app, target)?;
|
|
|
|
|
app.session.active()?.doc.swatch(name)?;
|
|
|
|
|
Some(Self { target: key, name: name.to_owned() })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A Color mode command from the popover's menu that has not been seen to finish.
|
|
|
|
|
struct OwnMode {
|
|
|
|
|
/// The document's history step when it ran.
|
|
|
|
@@ -264,9 +280,9 @@ fn recolor(mut stops: Vec<GradientStop>, i: usize, color: Color, link: Option<(S
|
|
|
|
|
/// comes from: a linked colour's tint swatch for that tint, or its global swatch at 100%; an unlinked colour's process
|
|
|
|
|
/// swatch of that very colour. Where several entries qualify, `picked`, the swatch last picked in the popover for this
|
|
|
|
|
/// target, is the one.
|
|
|
|
|
fn swatch_colors(app: &VectorcraftApp, target: &Target, picked: Option<&(TargetKey, String)>) -> (Vec<(String, Color)>, Option<usize>) {
|
|
|
|
|
fn swatch_colors(app: &VectorcraftApp, target: &Target, picked: Option<&PickedSwatch>) -> (Vec<(String, Color)>, Option<usize>) {
|
|
|
|
|
let Some(st) = app.session.active() else { return (vec![], None) };
|
|
|
|
|
let picked = picked.filter(|(key, _)| key.matches(app, target)).map(|(_, name)| name.as_str());
|
|
|
|
|
let picked = picked.filter(|p| p.target.matches(app, target));
|
|
|
|
|
let (link, color) = match target {
|
|
|
|
|
Target::Stop(paint, i) => {
|
|
|
|
|
let stop = &paint.gradient.stops[*i];
|
|
|
|
@@ -277,6 +293,7 @@ fn swatch_colors(app: &VectorcraftApp, target: &Target, picked: Option<&(TargetK
|
|
|
|
|
let mut colors = Vec::new();
|
|
|
|
|
let mut selected = None;
|
|
|
|
|
for swatch in st.doc.swatches_iter() {
|
|
|
|
|
let is_picked = picked.is_some_and(|p| p.name == swatch.name);
|
|
|
|
|
let Some(own) = swatch.paint.color() else { continue };
|
|
|
|
|
// Picking this swatch would give the target the colour and link it has now.
|
|
|
|
|
let source = match (link, swatch.tint_of()) {
|
|
|
|
@@ -284,7 +301,7 @@ fn swatch_colors(app: &VectorcraftApp, target: &Target, picked: Option<&(TargetK
|
|
|
|
|
(Some((base, tint)), None) => swatch.global && swatch.name == base && same_tint(tint, 1.0),
|
|
|
|
|
(None, _) => !swatch.global && matches!(swatch.paint, Paint::Solid { color: c, swatch: None, .. } if c == color),
|
|
|
|
|
};
|
|
|
|
|
if source && (selected.is_none() || picked == Some(swatch.name.as_str())) {
|
|
|
|
|
if source && (selected.is_none() || is_picked) {
|
|
|
|
|
selected = Some(colors.len());
|
|
|
|
|
}
|
|
|
|
|
colors.push((swatch.name.clone(), own));
|
|
|
|
@@ -377,7 +394,7 @@ pub(crate) struct GradientStopPopover {
|
|
|
|
|
panel: ColorPanelState,
|
|
|
|
|
feed: Option<Feed>,
|
|
|
|
|
/// The swatch last picked in the Swatches view and the stop or point it was picked for.
|
|
|
|
|
picked_swatch: Option<(TargetKey, String)>,
|
|
|
|
|
picked_swatch: Option<PickedSwatch>,
|
|
|
|
|
/// The fields set from outside, applied at confirm.
|
|
|
|
|
set: PopoverFields,
|
|
|
|
|
filed: Filed,
|
|
|
|
@@ -552,7 +569,10 @@ fn swatches(ui: &mut Ui, feed: &Feed, filed: &mut Filed) {
|
|
|
|
|
Notice::new(Tone::Info, tl!("The document has no colour swatches.").to_owned()).show(ui);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let shown = SwatchPalette::new("Swatches", Bind::given(feed.current), &feed.tiles).selected_swatch(feed.selected_swatch).show(ui);
|
|
|
|
|
// Only the entry the target's colour comes from is selected, and none when no entry is: a swatch that only draws
|
|
|
|
|
// the same colour, such as a spot ink an unlinked stop has the colour of, is not.
|
|
|
|
|
let shown =
|
|
|
|
|
SwatchPalette::new("Swatches", Bind::given(feed.current), &feed.tiles).selected_swatch(feed.selected_swatch).select_by_color(false).show(ui);
|
|
|
|
|
// A click on a swatch other than the one shown as the target's, also one of the colour the target already has. A
|
|
|
|
|
// click on the one shown changes nothing.
|
|
|
|
|
if let Some(swatch) = shown.picked_swatch.filter(|i| Some(*i) != feed.selected_swatch).and_then(|i| feed.swatches.get(i)) {
|
|
|
|
@@ -643,6 +663,23 @@ fn refresh(app: &VectorcraftApp, ctx: &egui::Context, id: DialogId, target: &Tar
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// After the swatch `from` of the document `uid` was renamed `to`, the open popover's remembered pick takes the new name
|
|
|
|
|
/// when it is that swatch, picked for the selected stop or point.
|
|
|
|
|
pub(crate) fn follow_swatch_rename(app: &VectorcraftApp, uid: u64, from: &str, to: &str) {
|
|
|
|
|
let Some(target) = selected(app) else { return };
|
|
|
|
|
let Some(dialogs) = app.dialogs() else { return };
|
|
|
|
|
dialogs.with(|host| {
|
|
|
|
|
if let Some(popover) = host.get_mut_by_id::<GradientStopPopover>(dialog_id(KIND))
|
|
|
|
|
&& let Some(picked) = &mut popover.picked_swatch
|
|
|
|
|
&& picked.target.document.0 == uid
|
|
|
|
|
&& picked.target.matches(app, &target)
|
|
|
|
|
&& picked.name == from
|
|
|
|
|
{
|
|
|
|
|
picked.name = to.to_owned();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Opens the popover on the selected stop (a freeform gradient's selected point) of the active gradient, the stop
|
|
|
|
|
/// at `index` when it is not the selected one. Nothing opens without a window or a stop to edit.
|
|
|
|
|
pub(crate) fn open_at(app: &mut VectorcraftApp, index: usize, anchor: Anchor) {
|
|
|
|
@@ -670,6 +707,9 @@ pub(crate) fn open_at(app: &mut VectorcraftApp, index: usize, anchor: Anchor) {
|
|
|
|
|
/// Once per frame: applies what the user did in the popover and its confirmed answer, closes it when its stop or
|
|
|
|
|
/// point goes away, and pushes the target's values for the next frame. One line of `dialogs::host::pump`.
|
|
|
|
|
pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
|
|
|
|
for (uid, from, to) in app.session.take_swatch_renames() {
|
|
|
|
|
follow_swatch_rename(app, uid, &from, &to);
|
|
|
|
|
}
|
|
|
|
|
let Some(dialogs) = app.dialogs() else { return };
|
|
|
|
|
let id = dialog_id(KIND);
|
|
|
|
|
match dialogs.with(|host| host.take_by_id::<GradientStopPopover>(id)) {
|
|
|
|
@@ -735,7 +775,7 @@ pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
|
|
|
|
{
|
|
|
|
|
pick_swatch(app, &target, &name, color);
|
|
|
|
|
// Swatches of one colour draw alike: the Swatches view shows the one picked, not the first of them.
|
|
|
|
|
let picked = selected(app).and_then(|target| TargetKey::of(app, &target)).map(|key| (key, name));
|
|
|
|
|
let picked = selected(app).and_then(|target| PickedSwatch::of(app, &target, &name));
|
|
|
|
|
dialogs.with(|host| {
|
|
|
|
|
if let Some(popover) = host.get_mut_by_id::<GradientStopPopover>(id) {
|
|
|
|
|
popover.picked_swatch = picked;
|
|
|
|
@@ -918,20 +958,29 @@ mod tests {
|
|
|
|
|
let target = selected(&app).unwrap();
|
|
|
|
|
pick_swatch(&mut app, &target, "First green ink", Color::from_hex("#00ff00").unwrap());
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some("First green ink"));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First green ink"));
|
|
|
|
|
panel.click("Second green ink");
|
|
|
|
|
assert_eq!(stops(&panel.app())[1].swatch.as_deref(), Some("Second green ink"));
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some("Second green ink"), "the view shows the swatch picked");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second green ink"), "the view shows the swatch picked");
|
|
|
|
|
panel.app().run("swatch.edit", json!({"name": "Second green ink", "color": "#123456"})).unwrap();
|
|
|
|
|
assert_eq!(stops(&panel.app())[1].color.to_hex(), "#123456", "the stop follows the swatch it was given");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The swatch the open popover's Swatches view shows as the target's.
|
|
|
|
|
fn shown_swatch(app: &VectorcraftApp) -> Option<String> {
|
|
|
|
|
app.dialogs().unwrap().with(|host| {
|
|
|
|
|
let feed = host.get_by_id::<GradientStopPopover>(dialog_id(KIND))?.feed.as_ref()?;
|
|
|
|
|
feed.swatches.get(feed.selected_swatch?).map(|(name, _)| name.clone())
|
|
|
|
|
})
|
|
|
|
|
/// The swatch the open popover's Swatches view shows as the target's, after two fresh frames: the first one's pump
|
|
|
|
|
/// feeds the view an edit made outside it, and the second draws that feed. The view draws that swatch's cell
|
|
|
|
|
/// selected and no other, and no cell selected when it shows none.
|
|
|
|
|
fn shown_swatch(panel: &mut crate::tests::panel_harness::Panel) -> Option<String> {
|
|
|
|
|
panel.frame();
|
|
|
|
|
panel.frame();
|
|
|
|
|
let (names, shown) = panel.app().dialogs().unwrap().with(|host| {
|
|
|
|
|
let feed = host.get_by_id::<GradientStopPopover>(dialog_id(KIND)).and_then(|popover| popover.feed.as_ref()).expect("the view's feed");
|
|
|
|
|
let shown = feed.selected_swatch.and_then(|i| feed.swatches.get(i)).map(|(name, _)| name.clone());
|
|
|
|
|
(feed.swatches.iter().map(|(name, _)| name.clone()).collect::<Vec<_>>(), shown)
|
|
|
|
|
});
|
|
|
|
|
let drawn: Vec<String> =
|
|
|
|
|
names.into_iter().filter(|name| panel.selected_role(name, craft::ui::contract::Role::LIST_BOX_OPTION) == Some(true)).collect();
|
|
|
|
|
assert_eq!(drawn, shown.iter().cloned().collect::<Vec<_>>(), "the cells the view draws selected");
|
|
|
|
|
shown
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
@@ -941,16 +990,149 @@ mod tests {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()), None, "the stop's green is no swatch's");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel), None, "the stop's green is no swatch's");
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
assert_eq!(stops(&panel.app())[1].color.to_hex(), "#008080");
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some("Second teal"));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"));
|
|
|
|
|
let undo = panel.app().session.active().unwrap().history.undo.len();
|
|
|
|
|
panel.click("First teal");
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some("First teal"));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First teal"));
|
|
|
|
|
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo, "the same colour again is no edit");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_swatches_view_keeps_the_picked_process_swatch_through_a_rename() {
|
|
|
|
|
let mut app = app();
|
|
|
|
|
for name in ["First teal", "Second teal"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"));
|
|
|
|
|
panel.app().run("swatch.edit", json!({"name": "Second teal", "newName": "Renamed teal"})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Renamed teal"), "the renamed swatch stays the one shown");
|
|
|
|
|
panel.app().run("edit.undo", json!({})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First teal"), "Undo of the rename falls back to the first qualifying swatch");
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
panel.app().run("swatch.edit", json!({"name": "First teal", "newName": "Other teal"})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"), "a rename of the other swatch moves nothing");
|
|
|
|
|
let first = panel.app().session.active().unwrap().doc.swatches_iter().position(|s| s.name == "Other teal").unwrap();
|
|
|
|
|
panel.app().run("swatch.move", json!({"name": "Second teal", "to": first})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"), "the picked swatch moved before the other stays the one shown");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_swatches_view_keeps_the_picked_swatch_through_a_rename_in_a_batch() {
|
|
|
|
|
let mut app = app();
|
|
|
|
|
for name in ["First teal", "Second teal"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
panel
|
|
|
|
|
.app()
|
|
|
|
|
.run("command.batch", json!({"commands": [{"command": "swatch.edit", "params": {"name": "Second teal", "newName": "Renamed teal"}}]}))
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Renamed teal"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_swatches_view_keeps_the_pick_when_a_batch_renames_a_swatch_in_another_document() {
|
|
|
|
|
let mut app = app();
|
|
|
|
|
for name in ["First teal", "Second teal"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
|
|
|
|
for name in ["First teal", "Second teal"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
app.run("document.activate", json!({"index": 0})).unwrap();
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"));
|
|
|
|
|
panel
|
|
|
|
|
.app()
|
|
|
|
|
.run(
|
|
|
|
|
"command.batch",
|
|
|
|
|
json!({"commands": [
|
|
|
|
|
{"command": "document.activate", "params": {"index": 1}},
|
|
|
|
|
{"command": "swatch.edit", "params": {"name": "Second teal", "newName": "Renamed teal"}},
|
|
|
|
|
{"command": "document.activate", "params": {"index": 0}}
|
|
|
|
|
]}),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"));
|
|
|
|
|
assert!(panel.app().session.documents()[1].doc.swatch("Renamed teal").is_some());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_swatches_view_follows_renames_that_bypass_app_run() {
|
|
|
|
|
let mut app = app();
|
|
|
|
|
for name in ["First teal", "Second teal"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
panel.app().session.execute("swatch.edit", &json!({"name": "Second teal", "newName": "Renamed teal"})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Renamed teal"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_swatches_view_does_not_give_a_deleted_picked_swatch_to_its_neighbor() {
|
|
|
|
|
let mut app = app();
|
|
|
|
|
for name in ["First teal", "Second teal", "Third teal"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"));
|
|
|
|
|
panel.app().run("swatch.delete", json!({"name": "Second teal"})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First teal"), "the swatch after the deleted one is not taken for it");
|
|
|
|
|
panel.app().run("edit.undo", json!({})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"), "Undo of the deletion shows the picked swatch again");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_swatches_view_does_not_give_a_deleted_picked_swatch_to_a_replacement() {
|
|
|
|
|
let mut app = app();
|
|
|
|
|
for name in ["First teal", "Second teal"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"));
|
|
|
|
|
panel.app().run("swatch.delete", json!({"name": "Second teal"})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First teal"));
|
|
|
|
|
panel.app().run("swatch.new", json!({"name": "New teal", "color": "#008080"})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First teal"), "a new swatch in the deleted one's place is not taken for it");
|
|
|
|
|
panel.app().run("edit.undo", json!({})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First teal"));
|
|
|
|
|
panel.app().run("edit.undo", json!({})).unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"), "Undo of the deletion shows the picked swatch again");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_swatches_view_does_not_follow_a_replacement_in_a_batch() {
|
|
|
|
|
let mut app = app();
|
|
|
|
|
for name in ["First teal", "Second teal"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
panel.click("Second teal");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second teal"));
|
|
|
|
|
panel
|
|
|
|
|
.app()
|
|
|
|
|
.run(
|
|
|
|
|
"command.batch",
|
|
|
|
|
json!({"commands": [
|
|
|
|
|
{"command": "swatch.delete", "params": {"name": "Second teal"}},
|
|
|
|
|
{"command": "swatch.new", "params": {"name": "New teal", "color": "#008080"}}
|
|
|
|
|
]}),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First teal"), "the replacement does not inherit the pick");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_swatches_view_shows_the_tint_swatch_picked_among_two_of_one_tint() {
|
|
|
|
|
let mut app = app();
|
|
|
|
@@ -962,12 +1144,12 @@ mod tests {
|
|
|
|
|
panel.click(&tints[1]);
|
|
|
|
|
let stop = stops(&panel.app())[1].clone();
|
|
|
|
|
assert_eq!((stop.swatch.as_deref(), (stop.tint * 100.0).round()), (Some("Green ink"), 40.0));
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some(tints[1].as_str()));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some(tints[1].as_str()));
|
|
|
|
|
panel.click(&tints[0]);
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some(tints[0].as_str()));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some(tints[0].as_str()));
|
|
|
|
|
panel.click("Green ink");
|
|
|
|
|
assert_eq!(stops(&panel.app())[1].tint, 1.0);
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some("Green ink"));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Green ink"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
@@ -975,17 +1157,28 @@ mod tests {
|
|
|
|
|
let mut app = app();
|
|
|
|
|
app.run("swatch.new", json!({"name": "Green ink", "color": "#00ff00", "spot": true})).unwrap();
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()), None, "the stop's green is not linked to the ink");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel), None, "the stop's green is not linked to the ink");
|
|
|
|
|
panel.click("Green ink");
|
|
|
|
|
assert_eq!(stops(&panel.app())[1].swatch.as_deref(), Some("Green ink"));
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some("Green ink"));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Green ink"));
|
|
|
|
|
|
|
|
|
|
// Two spot inks of the stop's green: the unlinked stop shows neither, and a pick links the stop to that one.
|
|
|
|
|
let mut app = self::app();
|
|
|
|
|
for name in ["First green ink", "Second green ink"] {
|
|
|
|
|
app.run("swatch.new", json!({"name": name, "color": "#00ff00", "spot": true})).unwrap();
|
|
|
|
|
}
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel), None, "the stop's green is linked to neither ink");
|
|
|
|
|
panel.click("Second green ink");
|
|
|
|
|
assert_eq!(stops(&panel.app())[1].swatch.as_deref(), Some("Second green ink"));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Second green ink"));
|
|
|
|
|
|
|
|
|
|
let mut app = self::app();
|
|
|
|
|
app.run("swatch.new", json!({"name": "Green ink", "color": "#00ff00", "spot": true})).unwrap();
|
|
|
|
|
crate::panels::gradient::recolor_selected(&mut app, Color::from_hex("#00ff00").unwrap(), &json!({"swatch": "Green ink", "tint": 40}));
|
|
|
|
|
assert_eq!((stops(&app)[1].tint * 100.0).round(), 40.0);
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()), None, "a 40% tint is not the ink at 100%");
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel), None, "a 40% tint is not the ink at 100%");
|
|
|
|
|
panel.click("Green ink");
|
|
|
|
|
let stop = stops(&panel.app())[1].clone();
|
|
|
|
|
assert_eq!((stop.swatch.as_deref(), stop.tint), (Some("Green ink"), 1.0));
|
|
|
|
@@ -1005,7 +1198,7 @@ mod tests {
|
|
|
|
|
app.run("gradient.selectStop", json!({"index": 1})).unwrap();
|
|
|
|
|
let undo = app.session.active().unwrap().history.undo.len();
|
|
|
|
|
let mut panel = swatches_view(app);
|
|
|
|
|
assert_eq!(shown_swatch(&panel.app()).as_deref(), Some("Green ink"));
|
|
|
|
|
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("Green ink"));
|
|
|
|
|
panel.click("Green ink");
|
|
|
|
|
let Paint::Gradient(paint) = active_paint(&panel.app()) else { panic!("expected a gradient") };
|
|
|
|
|
assert_eq!(paint.swatch.as_deref(), Some("Linked gradient"));
|
|
|
|
|