mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Keep Appearance rows in their source document during drags
This commit is contained in:
1 parent
f040538a39
commit
efde159b33
3 files changed
+43
-3
No files matched your search
@@ -429,7 +429,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let order = rows.keys();
|
||||
let sel = current_sel(app, node.as_deref());
|
||||
let mut selection = node.as_deref().map_or_else(Selection::default, |n| list_selection(app, n, sel));
|
||||
let list_id = ui.scope_id().with("appearance-rows");
|
||||
let document = app.session.active().map(|st| st.uid);
|
||||
let list_id = ui.scope_id().with(("appearance-rows", document));
|
||||
let has = node.is_some();
|
||||
// A dragged fill/stroke or effect row lights Duplicate and Delete up, also with nothing picked.
|
||||
let dragged = craft::ui::runtime::drag::active::<ListDrag<RowKey>>(ui.ctx())
|
||||
@@ -490,6 +491,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
if let (Some(dropped), Some(n)) = (&out.dropped, node.as_deref())
|
||||
&& let Some(drag) = dropped.payload::<ListDrag<RowKey>>()
|
||||
&& drag.list == list_id
|
||||
{
|
||||
drop_on_footer(app, n, sel, &drag.keys, dropped.index == DUPLICATE);
|
||||
}
|
||||
|
||||
@@ -163,6 +163,39 @@ fn alt_dragging_an_item_duplicates_it_and_several_items_delete_together() {
|
||||
assert_eq!(kinds(&panel).len(), 3, "one undo step");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_appearance_row_drop_after_next_document_leaves_the_new_stack_alone() {
|
||||
use craft::ui::runtime::drag;
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
let mut app = app_with_rect();
|
||||
let first = app.session.active().unwrap().uid;
|
||||
run(&mut app, "file.new", json!({"width": 400, "height": 300}));
|
||||
run(&mut app, "shape.rectangle", json!({"x": 20, "y": 30, "width": 50, "height": 30}));
|
||||
let second = app.session.active().unwrap().uid;
|
||||
let kinds = |app: &VectorcraftApp| first_selected(app).unwrap().appearance.items.iter().map(|item| item.kind_name()).collect::<Vec<_>>();
|
||||
let before = kinds(&app);
|
||||
assert_eq!(before, ["fill", "stroke"]);
|
||||
assert!(app.session.set_active(0));
|
||||
|
||||
let mut panel = Panel::new(app, appearance::show);
|
||||
let from = row_spot(&mut panel, "Stroke:");
|
||||
let to = panel.rect("Delete Selected Item").center();
|
||||
panel.drag_hold_between(from, to);
|
||||
assert!(drag::mark(panel.ctx()).is_some(), "the footer accepts the stroke before switching documents");
|
||||
panel.key(Key::F6, Modifiers::COMMAND);
|
||||
assert_eq!(panel.app().session.active().unwrap().uid, second);
|
||||
assert!(drag::mark(panel.ctx()).is_none(), "the footer withdraws the drop indicator after the document switch");
|
||||
panel.release();
|
||||
assert_eq!(kinds(&panel.app()), before, "the active document's stroke stays in its own stack");
|
||||
|
||||
drag_row(&mut panel, "Stroke:", "Delete Selected Item", Modifiers::NONE);
|
||||
assert_eq!(kinds(&panel.app()), ["fill"], "a stroke from the active document can still be removed by dragging");
|
||||
panel.key(Key::F6, Modifiers::COMMAND);
|
||||
assert_eq!(panel.app().session.active().unwrap().uid, first);
|
||||
assert_eq!(kinds(&panel.app()), ["fill", "stroke"], "the original document keeps its stroke");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stroke_rows_note_dashes_brushes_and_show_all_hidden_attributes() {
|
||||
let mut panel = Panel::new(app_with_rect(), appearance::show);
|
||||
|
||||
@@ -182,8 +182,13 @@ impl Panel {
|
||||
/// the name (a slider beside its number box).
|
||||
pub(crate) fn drag_hold_role(&mut self, name: &str, role: craft::ui::contract::Role, by: Vec2) {
|
||||
self.frame();
|
||||
let target = self.look_role(name, role);
|
||||
self.fixture.drag_hold_at(target.center(), by);
|
||||
let from = self.look_role(name, role).center();
|
||||
self.drag_hold_between(from, from + by);
|
||||
}
|
||||
|
||||
/// Drags from `from` to `to`, keeping the button down for another input before release.
|
||||
pub(crate) fn drag_hold_between(&mut self, from: Pos2, to: Pos2) {
|
||||
self.fixture.drag_hold_at(from, to - from);
|
||||
self.after();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user