From 7eb1280a7fea9363ce6587e9d34099c356c0a1df Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 13:03:50 -0800 Subject: [PATCH] Width profiles: reorder the Profile list Rows of the Profile drop-down below Uniform can be dragged to a new place, and stroke.widthProfile.move {name, to} does the same from a script. Uniform stays first. The order is kept with the preferences (widthProfileOrder) and is stored only while it differs from the default one. - move takes a profile's id or its label, and refuses Uniform, an unknown name and a `to` past the last row. - Moving a profile to the place it already has changes nothing. - A deleted saved profile leaves the order, so one saved later under the same name goes to the end of the list. - Reset Profiles also puts the built-ins back in their first order, and is enabled when only the order changed. Ported from the reordering part of #10920. Co-authored-by: erolkarino --- crates/engine/src/cmd/stroke.rs | 86 ++++++++++++-- crates/engine/src/prefs.rs | 6 + crates/engine/src/tests/widthprofiles.rs | 106 ++++++++++++++++++ crates/ui-egui/src/panels/stroke.rs | 3 + .../src/panels/stroke/profile_picker.rs | 42 +++++-- .../ui-egui/src/panels/tests_strokedepth.rs | 46 ++++++++ docs/mcp.md | 10 +- 7 files changed, 282 insertions(+), 17 deletions(-) diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index 4ee4f01c10..bedfadd6c4 100644 --- a/crates/engine/src/cmd/stroke.rs +++ b/crates/engine/src/cmd/stroke.rs @@ -12,7 +12,7 @@ use vectorcraft_tools::builder::is_live_paint; use super::appearance::{ItemTarget, edit_items, item_target}; use super::paint::{live_paint_parts_skipped, painted}; -use super::{CommandSpec, Result, Session, always, bad, bool_or, cmd, has_doc, ok, str_param}; +use super::{CommandSpec, Result, Session, always, bad, bool_or, cmd, has_doc, index_opt, ok, str_param}; use crate::DocState; use crate::inspect::{ALIGNS, CAPS, JOINS, StrokeMixed, node_stroke, scale_layer}; @@ -77,10 +77,19 @@ pub fn specs() -> Vec { "Reset Profiles", [], None, - "{} remove every saved profile, leaving the built-ins → {removed: count}", - has_saved_profiles, + "{} remove every saved profile, leaving the built-ins in their first order → {removed: count}", + can_reset_profiles, profile_reset ), + cmd!( + "stroke.widthProfile.move", + "Move Width Profile", + [], + None, + "{name: a profile's id or label (stroke.widthProfile.list; not Uniform, which stays first), to: its new place among the profiles after Uniform (0 = right after Uniform)} reorder the Profile list (kept with the preferences) → {order: the ids after Uniform}", + always, + profile_move + ), cmd!( query "stroke.widthProfile.list", "Width Profiles", @@ -710,12 +719,23 @@ impl ProfileEntry<'_> { } impl Session { - /// The Profile list: the built-in profiles, then the saved ones. + /// The Profile list: Uniform, then the other built-in profiles and the saved ones in + /// [`Prefs::width_profile_order`](crate::Prefs::width_profile_order) (by default the built-ins, then the saved + /// ones). A profile the order doesn't name follows the ones it does, in the default order. pub fn profile_entries(&self) -> impl Iterator> { - let built_in = WidthProfile::PRESETS.iter().map(|p| ProfileEntry { id: p.id, label: p.label, points: p.points, built_in: true }); - let saved = - self.prefs.width_profiles.iter().map(|p| ProfileEntry { id: &p.name, label: &p.name, points: &p.profile.points, built_in: false }); - built_in.chain(saved) + let uniform = std::iter::once(WidthProfile::PRESETS[0]).map(|p| ProfileEntry { id: p.id, label: p.label, points: p.points, built_in: true }); + let mut rest: Vec> = WidthProfile::PRESETS[1..] + .iter() + .map(|p| ProfileEntry { id: p.id, label: p.label, points: p.points, built_in: true }) + .chain(self.prefs.width_profiles.iter().map(|p| ProfileEntry { id: &p.name, label: &p.name, points: &p.profile.points, built_in: false })) + .collect(); + let order = &self.prefs.width_profile_order; + if !order.is_empty() { + let place: std::collections::HashMap<&str, usize> = order.iter().enumerate().rev().map(|(at, id)| (id.as_str(), at)).collect(); + // A stable sort keeps the default order among the profiles the order doesn't name. + rest.sort_by_key(|e| place.get(e.id).copied().unwrap_or(usize::MAX)); + } + uniform.chain(rest) } /// The Profile list row showing `p` (`None`: the plain stroke), if it is listed. @@ -759,6 +779,21 @@ fn has_saved_profiles(s: &Session) -> std::result::Result<(), String> { if s.prefs.width_profiles.is_empty() { Err("no saved profiles".into()) } else { Ok(()) } } +fn can_reset_profiles(s: &Session) -> std::result::Result<(), String> { + if s.prefs.width_profiles.is_empty() && s.prefs.width_profile_order.is_empty() { + Err("no saved profiles, and the list is in its first order".into()) + } else { + Ok(()) + } +} + +/// Keeps `order` (the ids after Uniform) as the Profile list's order, storing none when it is the default one. +fn set_profile_order(s: &mut Session, order: Vec) { + let default: Vec<&str> = WidthProfile::PRESETS[1..].iter().map(|p| p.id).chain(s.prefs.width_profiles.iter().map(|p| p.name.as_str())).collect(); + let is_default = order.len() == default.len() && order.iter().zip(&default).all(|(a, b)| a == b); + s.prefs.width_profile_order = if is_default { vec![] } else { order }; +} + fn profile_add(s: &mut Session, p: &Value) -> Result { const C: &str = "stroke.widthProfile.add"; let profile = s.profile_to_add().map_err(|e| bad(C, e))?; @@ -787,14 +822,49 @@ fn profile_delete(s: &mut Session, p: &Value) -> Result { } let i = s.prefs.width_profiles.iter().position(|sp| sp.name == name).ok_or_else(|| bad(C, format!("no saved profile called {name}")))?; s.prefs.width_profiles.remove(i); + // A profile saved later under the same name goes to the end of the list, not to this one's place. + if !s.prefs.width_profile_order.is_empty() { + let order = s.prefs.width_profile_order.iter().filter(|id| **id != name).cloned().collect(); + set_profile_order(s, order); + } Ok(json!({ "deleted": name })) } fn profile_reset(s: &mut Session, _: &Value) -> Result { let removed = std::mem::take(&mut s.prefs.width_profiles).len(); + s.prefs.width_profile_order.clear(); Ok(json!({ "removed": removed })) } +fn profile_move(s: &mut Session, p: &Value) -> Result { + const C: &str = "stroke.widthProfile.move"; + let name = match p.get("name") { + None | Some(Value::Null) => return Err(bad(C, "missing `name`")), + Some(v) => v.as_str().ok_or_else(|| bad(C, "`name` must be a profile's id or label"))?, + }; + let to = index_opt(p, "to", C)?.ok_or_else(|| bad(C, "missing `to`"))?; + let mut entries = s.profile_entries(); + let uniform = entries.next().map(|e| (e.id, e.label)); + if uniform.is_some_and(|(id, label)| id == name || label == name) { + return Err(bad(C, "Uniform stays first in the Profile list")); + } + let mut order: Vec = entries.map(|e| e.id.to_string()).collect(); + let from = s + .profile_entries() + .skip(1) + .position(|e| e.id == name || e.label == name) + .ok_or_else(|| bad(C, format!("no width profile called {name} (see stroke.widthProfile.list)")))?; + if to >= order.len() { + return Err(bad(C, format!("`to` must be less than {}, the number of profiles after Uniform", order.len()))); + } + if from != to { + let id = order.remove(from); + order.insert(to, id); + set_profile_order(s, order.clone()); + } + Ok(json!({ "order": order })) +} + fn profile_list(s: &mut Session, _: &Value) -> Result { let profiles: Vec = s .profile_entries() diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs index 0cb1cf613f..46faf6e3d5 100644 --- a/crates/engine/src/prefs.rs +++ b/crates/engine/src/prefs.rs @@ -373,6 +373,11 @@ pub struct Prefs { /// Preferences dialog field, so it has no [`cmd::prefscmds::PREF_SPECS`] row. #[serde(skip_serializing_if = "Vec::is_empty")] pub width_profiles: Vec, + /// The order of the Profile list's rows after Uniform (`stroke.widthProfile.move`): built-in ids and saved + /// profile names. Empty is the default order, the built-ins and then the saved profiles. Not a Preferences + /// dialog field, so resetting the preferences keeps it; Reset Profiles clears it. + #[serde(skip_serializing_if = "Vec::is_empty")] + pub width_profile_order: Vec, /// General → Use Japanese Crop Marks: the style of Create Trim Marks and Effect → Crop Marks. pub japanese_crop_marks: bool, /// Appearance panel → New Art Has Basic Appearance (on): new art takes one fill and stroke; @@ -732,6 +737,7 @@ impl Default for Prefs { trace_presets: vec![], gradient_presets: vec![], width_profiles: vec![], + width_profile_order: vec![], japanese_crop_marks: false, new_art_basic: true, color_themes: vec![], diff --git a/crates/engine/src/tests/widthprofiles.rs b/crates/engine/src/tests/widthprofiles.rs index fe041dae43..48fe1a6e78 100644 --- a/crates/engine/src/tests/widthprofiles.rs +++ b/crates/engine/src/tests/widthprofiles.rs @@ -127,6 +127,112 @@ fn saved_profiles_round_trip_with_the_preferences() { assert!(fresh.resolve_profile("Mine").is_some_and(|p| p == Some(custom()))); } +fn listed(s: &mut Session) -> Vec { + ids(&s.execute("stroke.widthProfile.list", &json!({})).unwrap()).into_iter().map(str::to_owned).collect() +} + +/// A line with two saved profiles, "Alpha" and "Beta", after the built-ins. +fn session_with_saved() -> Session { + let (mut s, id) = session_with_line(); + set_profile(&mut s, id, custom()); + s.execute("stroke.widthProfile.add", &json!({"name": "Alpha"})).unwrap(); + set_profile(&mut s, id, WidthProfile { points: vec![(0.0, 1.0, 0.0), (1.0, 0.0, 1.0)] }); + s.execute("stroke.widthProfile.add", &json!({"name": "Beta"})).unwrap(); + s +} + +#[test] +fn move_reorders_built_in_and_saved_profiles_below_uniform() { + let mut s = session_with_saved(); + let undo_depth = s.doc().unwrap().history.undo.len(); + // A built-in named by its label, and a saved profile by its name. + assert_eq!(s.execute("stroke.widthProfile.move", &json!({"name": "Wave", "to": 0})).unwrap()["order"][0], "wave"); + s.execute("stroke.widthProfile.move", &json!({"name": "Beta", "to": 1})).unwrap(); + s.execute("stroke.widthProfile.move", &json!({"name": "taperEnd", "to": 7})).unwrap(); + assert_eq!(listed(&mut s), ["uniform", "wave", "Beta", "lens", "taperStart", "pinch", "teardrop", "Alpha", "taperEnd"]); + assert_eq!(s.doc().unwrap().history.undo.len(), undo_depth, "the order is kept with the preferences, not the document"); + // The Stroke panel's rows follow it, and a moved profile still applies by its id. + assert_eq!(s.profile_entries().nth(2).map(|e| e.id), Some("Beta")); + s.execute("stroke.set", &json!({"profile": "wave"})).unwrap(); + assert_eq!(s.execute("stroke.widthProfile.list", &json!({})).unwrap()["current"], "wave"); + + // Moving a profile to the place it has leaves the list as it is. + let before = s.prefs.width_profile_order.clone(); + assert_eq!(s.execute("stroke.widthProfile.move", &json!({"name": "Beta", "to": 1})).unwrap()["order"][1], "Beta"); + assert_eq!(s.prefs.width_profile_order, before); + + // Moved back into the first order, the list stores no order. + s.execute("stroke.widthProfile.move", &json!({"name": "wave", "to": 5})).unwrap(); + s.execute("stroke.widthProfile.move", &json!({"name": "taperEnd", "to": 3})).unwrap(); + s.execute("stroke.widthProfile.move", &json!({"name": "Beta", "to": 7})).unwrap(); + assert_eq!(listed(&mut s), ["uniform", "lens", "taperStart", "taperEnd", "pinch", "teardrop", "wave", "Alpha", "Beta"]); + assert!(s.prefs.width_profile_order.is_empty()); +} + +#[test] +fn move_keeps_uniform_first_and_refuses_bad_params() { + let mut s = session_with_saved(); + for p in [ + json!({"name": "uniform", "to": 1}), + json!({"name": "Uniform", "to": 0}), + json!({"name": "Nope", "to": 0}), + json!({"name": "Alpha", "to": 8}), + json!({"name": "Alpha", "to": -1}), + json!({"name": "Alpha", "to": 1.5}), + json!({"name": "Alpha", "to": "1"}), + json!({"name": "Alpha"}), + json!({"name": 3, "to": 0}), + json!({"to": 0}), + ] { + assert!(s.execute("stroke.widthProfile.move", &p).is_err(), "{p}"); + } + let past_the_end = s.execute("stroke.widthProfile.move", &json!({"name": "Alpha", "to": 8})).unwrap_err().to_string(); + assert!(past_the_end.contains("must be less than 8"), "{past_the_end}"); + assert!(s.prefs.width_profile_order.is_empty(), "a refused move changes nothing"); + assert_eq!(listed(&mut s)[0], "uniform"); + // The last place is the last row. + s.execute("stroke.widthProfile.move", &json!({"name": "lens", "to": 7})).unwrap(); + assert_eq!(listed(&mut s).last().map(String::as_str), Some("lens")); +} + +#[test] +fn the_order_survives_the_preferences_and_resets_with_the_profiles() { + let mut s = session_with_saved(); + assert_eq!(s.execute("stroke.widthProfile.reset", &json!({})).unwrap()["removed"], 2); + // With only built-ins, a changed order is still something Reset Profiles puts back. + assert!(s.execute("stroke.widthProfile.reset", &json!({})).is_err()); + s.execute("stroke.widthProfile.move", &json!({"name": "pinch", "to": 0})).unwrap(); + let order = listed(&mut s); + assert_eq!(order[1], "pinch"); + + // It is written with the preferences, read back by a new session, and kept by Reset Preferences. + let json = s.prefs.to_json(); + assert_eq!(json["widthProfileOrder"][0], "pinch"); + let mut fresh = Session::new(); + fresh.apply_prefs(serde_json::from_value(json).unwrap()); + assert_eq!(listed(&mut fresh), order); + s.execute("prefs.reset", &json!({})).unwrap(); + assert_eq!(listed(&mut s), order); + assert!(Prefs::default().to_json().get("widthProfileOrder").is_none()); + + assert_eq!(s.execute("stroke.widthProfile.reset", &json!({})).unwrap()["removed"], 0); + assert_eq!(listed(&mut s), WidthProfile::PRESETS.iter().map(|p| p.id).collect::>()); +} + +#[test] +fn a_deleted_profile_leaves_the_order_and_a_new_one_goes_last() { + let (mut s, id) = session_with_line(); + set_profile(&mut s, id, custom()); + s.execute("stroke.widthProfile.add", &json!({"name": "Mine"})).unwrap(); + s.execute("stroke.widthProfile.move", &json!({"name": "Mine", "to": 0})).unwrap(); + s.execute("stroke.widthProfile.move", &json!({"name": "wave", "to": 1})).unwrap(); + s.execute("stroke.widthProfile.delete", &json!({"name": "Mine"})).unwrap(); + assert!(!s.prefs.width_profile_order.iter().any(|id| id == "Mine")); + // Saved again under the same name, it goes to the end instead of back to the top. + s.execute("stroke.widthProfile.add", &json!({"name": "Mine"})).unwrap(); + assert_eq!(listed(&mut s), ["uniform", "wave", "lens", "taperStart", "taperEnd", "pinch", "teardrop", "Mine"]); +} + #[test] fn every_built_in_applies_and_the_params_doc_names_them() { let (mut s, id) = session_with_line(); diff --git a/crates/ui-egui/src/panels/stroke.rs b/crates/ui-egui/src/panels/stroke.rs index 18c6e872b2..df23514f30 100644 --- a/crates/ui-egui/src/panels/stroke.rs +++ b/crates/ui-egui/src/panels/stroke.rs @@ -955,6 +955,9 @@ fn apply_profile_action(app: &mut VectorcraftApp, action: ProfileAction) { ProfileAction::Reset => { crate::dialogs::confirm::ask(app, tl!("Do you want to reset profiles?"), "", "stroke.widthProfile.reset", json!({})); } + ProfileAction::Move { name, to } => { + crate::menus::invoke(app, "stroke.widthProfile.move", json!({"name": name, "to": to})); + } } } diff --git a/crates/ui-egui/src/panels/stroke/profile_picker.rs b/crates/ui-egui/src/panels/stroke/profile_picker.rs index 9e0bfff157..9ba90ba82f 100644 --- a/crates/ui-egui/src/panels/stroke/profile_picker.rs +++ b/crates/ui-egui/src/panels/stroke/profile_picker.rs @@ -1,7 +1,7 @@ //! The Variable Width Profile dropdown (`ProfileSelect`): a combo box whose popup shows the width -//! profile list with built-in labels and captionless user-added thumbnails, a right-click Delete -//! Profile on saved rows, and a footer bar with Add to Profiles…, Delete Profile, and Reset -//! Profiles. +//! profile list with built-in labels and captionless user-added thumbnails, rows that drag to a new +//! place below Uniform, a right-click Delete Profile on saved rows, and a footer bar with Add to +//! Profiles…, Delete Profile, and Reset Profiles. use std::borrow::Cow; use std::collections::HashSet; @@ -9,14 +9,14 @@ use std::collections::HashSet; use craft::behavior::nav::{StepResult, ValueAxes, ValueSteps}; use craft::behavior::overlay::MinWidth; use craft::behavior::{ - CancelReason, ColumnKey, ColumnWidth, DisplayOrder, GesturePhase, HitLevel, HitPriority, IconId, ItemSource, Metrics, NavMove, PartKey, Proposal, - Selection, Sense, TypeAhead, WheelPhase, wheel_step, + CancelReason, ColumnKey, ColumnWidth, DisplayOrder, EditEvent, GesturePhase, HitLevel, HitPriority, IconId, ItemSource, Metrics, NavMove, + PartKey, Proposal, Selection, Sense, TypeAhead, WheelPhase, wheel_step, }; use craft::ui::contract::overlay::OverlayFit; use craft::ui::contract::{ Access, ActivateOn, Bind, BindMut, CollectionEvent, ColumnSpec, Common, Component, Cx, Edit as _, EditResponse, Focus as _, HoverLead, Input, LeadOnOpen, LeadSource, MeasureCx, Numeric, Outcome, Overlay, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, Popup, PopupHandle, - Props, Role, Show as _, ShowCollection as _, ShowContainer as _, WordSetCx as _, + Props, ReorderRule, Role, Show as _, ShowCollection as _, ShowContainer as _, WordSetCx as _, }; use craft::ui::layout_components::Stack; use craft::ui::list::{List, ListRow, RowEvent, ThumbAspect, ThumbSize}; @@ -46,6 +46,10 @@ const SAVED_THUMB_INSET: f32 = 2.0; const FACE: PartKey = PartKey::new("face"); const POPUP: &str = "list"; const LIST_SALT: &str = "items"; +/// The id of the Uniform row, the list's first. +const UNIFORM_ID: &str = "uniform"; +/// The rows above the first one a drag can move or land before: Uniform and the divider under it. +const PINNED_ROWS: usize = 2; /// Row identity in the profile list, keeping the non-interactive divider distinct from any /// user-saved profile name (even a literal `"__profile_separator__"`). @@ -62,6 +66,11 @@ impl ProfileRowKey { ProfileRowKey::Separator => None, } } + + /// Every profile row but Uniform's, which stays first, drags to a new place. + fn is_reorderable(&self) -> bool { + self.profile().is_some_and(|id| id != UNIFORM_ID) + } } /// One silhouette sample `(t, left_offset, right_offset)` returned by `stroke::silhouette`. @@ -150,12 +159,17 @@ pub(super) struct ProfileActions { pub can_reset: bool, } -/// A management action requested by the dropdown footer or a saved row's menu. +/// A management action requested by the dropdown footer, a saved row's menu or a row drag. #[derive(Clone, Debug, PartialEq, Eq)] pub(super) enum ProfileAction { Add, Delete(Option), Reset, + /// Move the profile `name` to place `to` among the rows after Uniform (`stroke.widthProfile.move`). + Move { + name: String, + to: usize, + }, } /// Output of [`ProfileSelect`]: the underlying profile pick/preview edit and any management action. @@ -530,6 +544,14 @@ impl ProfileSelect { cx.memory::().previewed = false; popup.close(cx); } + // `to` counts the rows left once the dragged one is out, Uniform and the divider among them. + CollectionEvent::Reorder(EditEvent::Set { after, .. } | EditEvent::Commit { after, .. }) => { + if after.key.is_reorderable() + && let (Some(name), Some(to)) = (after.key.profile(), after.to.checked_sub(PINNED_ROWS)) + { + self.action = Some(ProfileAction::Move { name: name.to_owned(), to }); + } + } _ => {} } } @@ -574,6 +596,12 @@ fn show_popup_body( .activate(ActivateOn::Click) .lead_on_open(LeadOnOpen::First) .selection(Bind::given(view.selection.clone())); + if rows.separator { + list = list + .can_drag(|key: &ProfileRowKey| key.is_reorderable()) + .reorder(ReorderRule::new()) + .accepts(|drag, _, insert| insert >= PINNED_ROWS && drag.keys.iter().all(ProfileRowKey::is_reorderable)); + } if let Some(key) = view.reveal { list = list.reveal(key.clone()); } diff --git a/crates/ui-egui/src/panels/tests_strokedepth.rs b/crates/ui-egui/src/panels/tests_strokedepth.rs index 17acf6f994..25a929079f 100644 --- a/crates/ui-egui/src/panels/tests_strokedepth.rs +++ b/crates/ui-egui/src/panels/tests_strokedepth.rs @@ -443,6 +443,52 @@ fn dropdown_row_menu_deletes_saved_profiles_only() { assert!(panel.app().session.profile_entries().any(|e| e.id == "wave"), "the built-ins stay"); } +#[test] +fn dropdown_rows_drag_to_a_new_place_below_uniform() { + use craft::ui::contract::Role; + use egui::{Modifiers, pos2}; + + let mut session = vectorcraft_engine::Session::new(); + session.execute("file.new", &serde_json::json!({"width": 400, "height": 400})).unwrap(); + let id = session.execute("shape.rectangle", &serde_json::json!({"x": 20, "y": 20, "width": 100, "height": 80})).unwrap()["id"].as_u64().unwrap(); + session.execute("stroke.set", &serde_json::json!({"weight": 6.0})).unwrap(); + session.execute("stroke.widthPoint.set", &serde_json::json!({"id": id, "t": 0.35, "left": 12.0, "right": 3.0})).unwrap(); + session.execute("stroke.widthProfile.add", &serde_json::json!({"name": "Mine"})).unwrap(); + let order = |panel: &mut crate::tests::panel_harness::Panel| panel.app().session.profile_entries().map(|e| e.id.to_owned()).collect::>(); + + let app = crate::VectorcraftApp::new(session, Default::default()); + let mut panel = crate::tests::panel_harness::Panel::new(app, super::stroke::profile_select); + let open = |panel: &mut crate::tests::panel_harness::Panel| { + if !panel.shows("Lens") { + panel.click_role("Profile", Role::COMBO_BOX); + } + }; + + // Uniform's row does not drag, and nothing lands above it. + open(&mut panel); + let first = order(&mut panel); + panel.drag("Uniform", "Wave", Modifiers::NONE); + open(&mut panel); + let uniform = panel.rect("Uniform"); + panel.drag_to("Wave", pos2(uniform.center().x, uniform.top() + 1.0), Modifiers::NONE); + assert_eq!(order(&mut panel), first, "Uniform stays first"); + + // A saved row dropped on the top edge of Lens's row goes right after Uniform. + open(&mut panel); + let lens = panel.rect("Lens"); + panel.drag_to("Mine", pos2(lens.center().x, lens.top() + 1.0), Modifiers::NONE); + let moved = order(&mut panel); + assert_eq!(&moved[..3], ["uniform", "Mine", "lens"], "{moved:?}"); + assert_eq!(panel.app().session.prefs.width_profile_order.first().map(String::as_str), Some("Mine")); + + // A built-in moves past the saved profile the same way. + open(&mut panel); + let mine = panel.rect("Mine"); + panel.drag_to("Wave", pos2(mine.center().x, mine.top() + 1.0), Modifiers::NONE); + let moved = order(&mut panel); + assert_eq!(&moved[..3], ["uniform", "wave", "Mine"], "{moved:?}"); +} + #[test] fn dropdown_expands_into_available_vertical_space() { use craft::ui::contract::Role; diff --git a/docs/mcp.md b/docs/mcp.md index 22a9ccaf8e..b9fb9faf06 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9157,14 +9157,20 @@ The Profile list holds the built-in variable-width profiles (`uniform`, `lens`, right]`) and `current`, the selected stroke's profile (`"custom"` when it isn't listed). `stroke.widthProfile.add {name?}` saves the selected stroke's variable width (default name "Width Profile N"), `stroke.widthProfile.delete {name?}` removes a saved one (default: the selected stroke's; built-ins can't be deleted) -and `stroke.widthProfile.reset` removes every saved one. `stroke.set {profile}` takes a built-in id or a saved name. +and `stroke.widthProfile.reset` removes every saved one and puts the built-ins back in their first order. +`stroke.widthProfile.move {name, to}` moves a built-in or saved profile, named by its id or label, to place `to` among +the rows after Uniform (0 is right after Uniform); Uniform stays first, and a `to` past the last row is refused. The +order is kept with the preferences, and a profile saved later goes to the end of the list. `stroke.set {profile}` +takes a built-in id or a saved name. In the app, the footer of the Profile drop-down (in the Stroke panel, the Control bar and the Properties panel) runs the same three commands: Add to Profiles asks for a name first, Delete Profile removes the selected stroke's saved -profile, and Reset Profiles asks for confirmation. Right-clicking a saved profile's row offers Delete Profile for it. +profile, and Reset Profiles asks for confirmation. Right-clicking a saved profile's row offers Delete Profile for it, +and dragging any row but Uniform's moves it. ```json {"name":"run_command","arguments":{"command":"stroke.widthProfile.add","params":{"name":"Ribbon"}}} {"name":"run_command","arguments":{"command":"stroke.set","params":{"ids":[9],"profile":"Ribbon"}}} +{"name":"run_command","arguments":{"command":"stroke.widthProfile.move","params":{"name":"Ribbon","to":0}}} ``` ## Arrowheads