mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 21:42:59 -05:00
Merge pull request #10955 from dotCooCoo/fix/stroke-weight-draft-target
Stroke: drop an unfinished value when the stroke it edits changes
This commit is contained in:
8 files changed
+1465
-21
No files matched your search
@@ -63,6 +63,7 @@ pub(crate) fn silent(s: &mut Session, f: impl FnOnce(&mut PerspectiveGrid)) -> R
|
||||
store_grid(Arc::make_mut(&mut st.doc), &g);
|
||||
if let Some(it) = &mut st.interaction {
|
||||
store_grid(Arc::make_mut(&mut it.doc), &g);
|
||||
it.revision = st.revision + 1;
|
||||
}
|
||||
st.revision += 1;
|
||||
Ok(g)
|
||||
@@ -745,6 +746,7 @@ pub(crate) fn finish_edit_text(st: &mut crate::DocState, id: NodeId) {
|
||||
}
|
||||
if let Some(it) = &mut st.interaction {
|
||||
clear(&mut it.doc);
|
||||
it.revision = st.revision + 1;
|
||||
}
|
||||
st.revision += 1;
|
||||
}
|
||||
@@ -7,6 +7,11 @@ use vectorcraft_geom::Rect;
|
||||
|
||||
use crate::Session;
|
||||
|
||||
/// The new-art paint state before the running preview, or its current value without a preview.
|
||||
pub fn new_art_paint_before_preview(s: &Session) -> &vectorcraft_tools::PaintDefaults {
|
||||
s.active().and_then(|st| st.interaction.as_ref()).map_or(&s.paint, |it| &it.paint)
|
||||
}
|
||||
|
||||
pub(crate) fn rect_json(r: Option<vectorcraft_geom::Rect>) -> Value {
|
||||
match r {
|
||||
Some(r) => json!({ "x": r.x0, "y": r.y0, "width": r.width(), "height": r.height() }),
|
||||
|
||||
@@ -11,8 +11,8 @@ pub struct Interaction {
|
||||
/// The selection the previews start from (shared, so a preview frame copies nothing).
|
||||
pub selection: Arc<Selection>,
|
||||
pub(crate) active_appearance_item: Option<PreviewAppearanceItem>,
|
||||
/// The document's [`crate::DocState::revision`] when the interaction began. The previews change the document's
|
||||
/// revision, and this value stays the same until the interaction ends.
|
||||
/// The baseline document's [`crate::DocState::revision`]. Previews keep this value; replacing or changing the
|
||||
/// baseline advances it to the document's next revision.
|
||||
pub revision: u64,
|
||||
pub preview: Option<(String, Value)>,
|
||||
/// The active tool began it (a drag): a command from outside the tool runs as a step of its
|
||||
|
||||
@@ -522,6 +522,8 @@ impl Session {
|
||||
return;
|
||||
}
|
||||
let began = std::mem::replace(&mut it.doc, st.doc.clone());
|
||||
st.revision += 1;
|
||||
it.revision = st.revision;
|
||||
// The drag acts on the objects it began with: a selection the command made (a paste, a
|
||||
// duplicate, Select All) does not change what the drag moves. A dialog's preview acts on
|
||||
// the selection the command left, and its dialog previews again on its next pass, from the
|
||||
|
||||
@@ -846,3 +846,58 @@ fn a_command_during_a_quick_pen_press_runs_inside_it() {
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "{at}: no step of its own during the press");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rebased_drag_advances_its_baseline_revision() {
|
||||
for real_time in [true, false] {
|
||||
let (mut s, _, other) = two_squares(real_time);
|
||||
s.select_tool("selection", view()).unwrap();
|
||||
pointer(&mut s, PointerKind::Down, 120.0, 120.0);
|
||||
pointer(&mut s, PointerKind::Drag, 140.0, 130.0);
|
||||
let revision = s.doc().unwrap().interaction.as_ref().unwrap().revision;
|
||||
pointer(&mut s, PointerKind::Drag, 150.0, 140.0);
|
||||
assert_eq!(s.doc().unwrap().interaction.as_ref().unwrap().revision, revision, "previews keep the baseline revision");
|
||||
s.execute("appearance.setItem", &json!({"ids": [other.0], "index": 1, "weight": 3})).unwrap();
|
||||
let rebased = s.doc().unwrap().interaction.as_ref().unwrap().revision;
|
||||
assert!(rebased > revision, "an outside document edit advances the baseline revision");
|
||||
pointer(&mut s, PointerKind::Drag, 160.0, 150.0);
|
||||
assert_eq!(s.doc().unwrap().interaction.as_ref().unwrap().revision, rebased, "later previews keep the rebased revision");
|
||||
s.cancel_interaction().unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.node(other).unwrap().appearance.stroke().unwrap().width, 3.0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_grid_change_during_an_interaction_advances_its_baseline_revision() {
|
||||
let (mut s, _) = session(true);
|
||||
s.begin_interaction("Grid").unwrap();
|
||||
let revision = s.doc().unwrap().interaction.as_ref().unwrap().revision;
|
||||
crate::cmd::distortcmds::silent(&mut s, |grid| grid.visible = !grid.visible).unwrap();
|
||||
let st = s.doc().unwrap();
|
||||
let it = st.interaction.as_ref().unwrap();
|
||||
assert!(it.revision > revision, "a direct baseline change advances its revision");
|
||||
assert_eq!(crate::cmd::distortcmds::grid_of(&it.doc).visible, crate::cmd::distortcmds::grid_of(&st.doc).visible);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaving_perspective_type_editing_during_an_interaction_advances_its_baseline_revision() {
|
||||
let (mut s, _) = crate::tests_persp_select::persp_session();
|
||||
let r = s.execute("text.create", &json!({"x": 430, "y": 400, "text": "HELLO", "size": 48})).unwrap();
|
||||
let id = NodeId(r["id"].as_u64().unwrap());
|
||||
s.execute("perspective.attach", &json!({"ids": [id.0], "plane": "right"})).unwrap();
|
||||
s.execute("perspective.editText", &json!({"id": id.0})).unwrap();
|
||||
s.begin_interaction("Edit").unwrap();
|
||||
let it = s.doc().unwrap().interaction.as_ref().unwrap();
|
||||
let revision = it.revision;
|
||||
let text = it.doc.node(id).unwrap();
|
||||
assert!(text.extras().perspective.as_deref().unwrap().editing, "the baseline starts in Edit Text mode");
|
||||
assert!(text.projection().is_none(), "the baseline text is flat while editing");
|
||||
crate::cmd::distortcmds::finish_edit_text(s.doc_mut().unwrap(), id);
|
||||
let st = s.doc().unwrap();
|
||||
let it = st.interaction.as_ref().unwrap();
|
||||
let text = it.doc.node(id).unwrap();
|
||||
assert!(!text.extras().perspective.as_deref().unwrap().editing, "the baseline leaves Edit Text mode");
|
||||
assert!(text.projection().is_some(), "the baseline text is projected again");
|
||||
assert!(it.revision > revision, "leaving Edit Text advances the baseline revision");
|
||||
assert_eq!(it.revision, st.revision, "the baseline revision is the document's new revision");
|
||||
}
|
||||
@@ -452,9 +452,11 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let copy = craft::ui::runtime::pointer::frame(ui.ctx()).mods.alt;
|
||||
let pass = RefCell::new(Pass::default());
|
||||
let footer = RefCell::new(None);
|
||||
let shown_target = stroke::target_key(&stroke::edit_target(app, ui.ctx()));
|
||||
let shared: &VectorcraftApp = app;
|
||||
let cx = RowCx {
|
||||
app: shared,
|
||||
shown_target,
|
||||
node: node.as_deref(),
|
||||
new_art: &new_art,
|
||||
mix,
|
||||
@@ -751,6 +753,7 @@ struct Pass {
|
||||
/// What a row reads to build itself.
|
||||
struct RowCx<'a> {
|
||||
app: &'a VectorcraftApp,
|
||||
shown_target: u64,
|
||||
node: Option<&'a Node>,
|
||||
new_art: &'a Appearance,
|
||||
mix: Option<&'a Mixed>,
|
||||
@@ -860,10 +863,12 @@ fn item_row<'r>(cx: &'r RowCx<'_>, key: RowKey, i: usize) -> ListRow<'r> {
|
||||
}
|
||||
if let Some(st) = stroke_layer {
|
||||
let target = if new_art { WeightTarget::Shown } else { WeightTarget::Item(i) };
|
||||
let field =
|
||||
if new_art { row_weight(cx.app, Some(st.width), &cx.shown_target) } else { row_weight(cx.app, Some(st.width), &(cx.shown_target, i)) };
|
||||
let pass = cx.pass;
|
||||
row = row.trailing_field(row_weight(cx.app, Some(st.width)), move |out| pass.borrow_mut().acts.push(Act::Weight(target, Box::new(out))));
|
||||
row = row.trailing_field(field, move |out| pass.borrow_mut().acts.push(Act::Weight(target, Box::new(out))));
|
||||
} else {
|
||||
row = row.trailing_space(row_weight(cx.app, None));
|
||||
row = row.trailing_space(row_weight(cx.app, None, &()));
|
||||
}
|
||||
let painted = if new_art { Painted::NewArt { fill } } else { Painted::Item(i) };
|
||||
let pass = cx.pass;
|
||||
@@ -894,8 +899,8 @@ fn paint_swatch(fill: bool, paint: &Paint) -> Swatch {
|
||||
/// The weight field of a stroke row, or the room it takes in a fill row: the Stroke panel's field as a small control,
|
||||
/// as the row's swatch is, without the presets list (a step still stops at each preset), so the row's label shows
|
||||
/// whole in the narrowest group.
|
||||
fn row_weight(app: &VectorcraftApp, weight: Option<f64>) -> NumberField<'static> {
|
||||
stroke::steps_weight(app, weight).size(ControlSize::Sm)
|
||||
fn row_weight(app: &VectorcraftApp, weight: Option<f64>, target: &impl egui::AsIdSalt) -> NumberField<'static> {
|
||||
stroke::steps_weight(app, weight, target).size(ControlSize::Sm)
|
||||
}
|
||||
|
||||
/// A stroke row's notes after the weight: its brush and "Dashed".
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// PLAN: import paths of craft_ui / craft_draw items are assumed from the crates' own module layout (craft_draw is
|
||||
// not yet a dependency of ui-egui; its owner adds it to Cargo.toml).
|
||||
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
mod profile_picker;
|
||||
@@ -32,7 +33,9 @@ use craft::ui::text::{NumberField, NumberOutput, NumberPick, StepArrows};
|
||||
use egui::{Rect, Response, Ui, pos2};
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::{Appearance, ArrowAlign, Arrowhead, Dash, Document, LineCap, LineJoin, Node, StrokeAlign, StrokeLayer, Unit, WidthProfile};
|
||||
use vectorcraft_doc::{
|
||||
Appearance, ArrowAlign, Arrowhead, Dash, Document, LineCap, LineJoin, Node, NodeId, StrokeAlign, StrokeLayer, Unit, WidthProfile,
|
||||
};
|
||||
use vectorcraft_engine::inspect::StrokeMixed;
|
||||
use vectorcraft_tools::PaintDefaults;
|
||||
|
||||
@@ -50,6 +53,15 @@ const ARROWHEAD_ASPECT: (u16, u16) = (2, 1);
|
||||
/// The key of [`StrokePanel::brushed`]: (document uid, revision, active Appearance row).
|
||||
type BrushedKey = (u64, u64, Option<usize>);
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct FieldGesture {
|
||||
held: Option<(EditTarget, EditTarget)>,
|
||||
serial: u64,
|
||||
}
|
||||
|
||||
/// Global Edit members in propagation order, with the transforms that place each member.
|
||||
type GlobalEditTarget = Option<Vec<(NodeId, [u64; 6])>>;
|
||||
|
||||
/// What the Stroke panel remembers between frames; `UiState::stroke_panel` holds it.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(crate) struct StrokePanel {
|
||||
@@ -63,6 +75,10 @@ pub(crate) struct StrokePanel {
|
||||
pub brushed: Option<(BrushedKey, Option<bool>)>,
|
||||
/// The running gesture of a Stroke panel select.
|
||||
pub select_gesture: Option<SelectGesture>,
|
||||
/// The editor gesture's starting target and targeting state.
|
||||
editor_gesture: FieldGesture,
|
||||
/// The arrow scale gesture's starting target and targeting state.
|
||||
scale_gesture: FieldGesture,
|
||||
}
|
||||
|
||||
/// The stroke a weight edit goes to.
|
||||
@@ -394,22 +410,125 @@ static BLANK_WEIGHT_STOPS: [f64; 2] = [0.25, 0.5];
|
||||
/// scrubbing by its label, blank when mixed. A plain step stops at each preset (0.52 pt goes down to 0.5 pt, not to
|
||||
/// 0 pt); Shift or Page steps the grid by ten.
|
||||
// PLAN: the sheet names `NumberField<'static, f64>`; `NumberField::length` takes `Option<f64>`.
|
||||
pub(crate) fn weight_number(app: &VectorcraftApp, weight: Option<f64>) -> NumberField<'static> {
|
||||
let field = steps_weight(app, weight);
|
||||
pub(crate) fn weight_number(app: &VectorcraftApp, weight: Option<f64>, target: &EditTarget) -> NumberField<'static> {
|
||||
let field = steps_weight(app, weight, target);
|
||||
match weight_ladder(app) {
|
||||
Some(l) => field.presets(&l.rows),
|
||||
None => field,
|
||||
}
|
||||
}
|
||||
|
||||
/// The document edit state and session destination before a preview.
|
||||
/// A field drops its unfinished value when either changes.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub(crate) struct Target {
|
||||
/// The document.
|
||||
doc: u64,
|
||||
/// How many times File > Revert replaced the document's content.
|
||||
reverts: u64,
|
||||
/// The revision of the document that the next preview builds on.
|
||||
revision: u64,
|
||||
/// The pre-preview new-art paint state.
|
||||
new_art: u64,
|
||||
/// Whether new art uses a basic appearance.
|
||||
new_art_basic: bool,
|
||||
/// The selected objects and subjects, in targeting order.
|
||||
objects: Vec<NodeId>,
|
||||
subjects: Vec<NodeId>,
|
||||
/// The active appearance row.
|
||||
row: Option<usize>,
|
||||
/// The selected object inside a dynamic symbol instance: its instance and path through the symbol's art.
|
||||
symbol_part: Option<(NodeId, Vec<u32>)>,
|
||||
/// Whether the Live Paint Bucket's stroke is edited.
|
||||
bucket: bool,
|
||||
/// The type object and characters the Type tool has selected.
|
||||
characters: Option<(NodeId, usize, usize)>,
|
||||
/// The frame ids in thread order when the Type tool has selected the whole story.
|
||||
story: Option<Vec<NodeId>>,
|
||||
/// The members and placement transforms used to propagate Global Edit changes.
|
||||
global_edit: GlobalEditTarget,
|
||||
/// Distinguishes a canceled gesture from a replacement with the same starting content.
|
||||
gesture: u64,
|
||||
}
|
||||
|
||||
/// The edit target of the Stroke panel's fields, `None` without a document.
|
||||
pub(crate) type EditTarget = Option<Target>;
|
||||
|
||||
/// The [`EditTarget`] of the active document.
|
||||
pub(crate) fn edit_target(app: &VectorcraftApp, _ctx: &egui::Context) -> EditTarget {
|
||||
let st = app.session.active()?;
|
||||
Some(Target {
|
||||
doc: st.uid,
|
||||
reverts: st.reverts,
|
||||
revision: st.interaction.as_ref().map_or(st.revision, |it| it.revision),
|
||||
new_art: if may_edit_new_art(app) {
|
||||
paint_digest(vectorcraft_engine::inspect::new_art_paint_before_preview(&app.session))
|
||||
} else {
|
||||
vectorcraft_engine::inspect::new_art_paint_before_preview(&app.session).stroke_width.to_bits()
|
||||
},
|
||||
new_art_basic: app.session.prefs.new_art_basic,
|
||||
objects: st.selection.objects.clone(),
|
||||
subjects: st.selection.subjects().to_vec(),
|
||||
row: app.session.appearance_item(),
|
||||
symbol_part: st.selection.symbol_part.as_ref().map(|part| (part.instance, part.path.clone())),
|
||||
bucket: app.session.tool_paints(true),
|
||||
characters: character::text_editing(app),
|
||||
story: character::text_story(app),
|
||||
global_edit: st.global_edit.as_ref().map(|ge| ge.members.iter().map(|(id, xf)| (*id, xf.as_coeffs().map(f64::to_bits))).collect()),
|
||||
gesture: 0,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn target_key(target: &EditTarget) -> u64 {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
target.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
||||
/// Whether the fields can edit the new-art paint. A selected path the Stroke panel edits directly
|
||||
/// (not a guide, a clipping path or a Live Paint part) is always a target, so with one selected
|
||||
/// the fields edit objects and the target skips formatting the new-art paint.
|
||||
fn may_edit_new_art(app: &VectorcraftApp) -> bool {
|
||||
use vectorcraft_tools::builder::{SOURCES_NAME, is_live_paint};
|
||||
let Some(st) = app.session.active() else { return true };
|
||||
if app.session.tool_paints(true) {
|
||||
return true;
|
||||
}
|
||||
let d = &st.doc;
|
||||
let edited_path = |id: NodeId| {
|
||||
d.node(id).is_some_and(|n| matches!(n.kind, vectorcraft_doc::NodeKind::Path { guide: false, clipping: false, .. }) && !n.is_ruler_guide())
|
||||
&& d.parent_of(id).and_then(|p| d.node(p)).is_none_or(|p| !is_live_paint(p) && p.name.as_deref() != Some(SOURCES_NAME))
|
||||
};
|
||||
!st.selection.objects.iter().any(|id| edited_path(*id))
|
||||
}
|
||||
|
||||
fn paint_digest(paint: &impl std::fmt::Debug) -> u64 {
|
||||
use std::fmt::Write as _;
|
||||
|
||||
struct HashSink(DefaultHasher);
|
||||
impl std::fmt::Write for HashSink {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
self.0.write(s.as_bytes());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let mut sink = HashSink(DefaultHasher::new());
|
||||
let _ = write!(sink, "{paint:?}");
|
||||
sink.0.finish()
|
||||
}
|
||||
|
||||
/// [`weight_number`] without the presets list: a plain step still stops at each preset.
|
||||
pub(crate) fn steps_weight(app: &VectorcraftApp, weight: Option<f64>) -> NumberField<'static> {
|
||||
pub(crate) fn steps_weight(app: &VectorcraftApp, weight: Option<f64>, target: &impl egui::AsIdSalt) -> NumberField<'static> {
|
||||
let unit = app.session.stroke_unit();
|
||||
let lengths =
|
||||
crate::fields::bare_points(LengthUnits::new(UnitKind::Points, shown_kind(unit), 72.0), app.session.prefs.numbers_without_units_are_points);
|
||||
let ladder = weight_ladder(app);
|
||||
let field =
|
||||
NumberField::length(tl!("Weight"), Bind::given(weight), lengths).range(0.0..=1000.0).step_arrows(StepArrows::Leading).scrub_by_label();
|
||||
let field = NumberField::length(tl!("Weight"), Bind::given(weight), lengths)
|
||||
.range(0.0..=1000.0)
|
||||
.step_arrows(StepArrows::Leading)
|
||||
.scrub_by_label()
|
||||
.edit_target(target);
|
||||
// The stepper steps the number the field shows; the ladders are in points.
|
||||
let in_points = move |stops: &'static [f64], blank: bool| {
|
||||
let step = crate::fields::stops_stepper(1.0, stops, move |pt| unit.format(pt));
|
||||
@@ -452,8 +571,15 @@ pub(crate) fn apply_weight(app: &mut VectorcraftApp, out: &NumberOutput, target:
|
||||
|
||||
/// The weight field in a row labelled `label` with the side label `side`: the field response and the output of
|
||||
/// the number field when the row's body ran.
|
||||
fn weight_row(app: &VectorcraftApp, ui: &mut Ui, label: &'static str, side: SideLabel, weight: Option<f64>) -> Inner<Response, NumberOutput> {
|
||||
Field::new(label).side(side).id_salt("weight").sizing(Sizing::Content).show(ui, |ui, _| weight_number(app, weight).show(ui))
|
||||
fn weight_row(
|
||||
app: &VectorcraftApp,
|
||||
ui: &mut Ui,
|
||||
label: &'static str,
|
||||
side: SideLabel,
|
||||
weight: Option<f64>,
|
||||
target: &EditTarget,
|
||||
) -> Inner<Response, NumberOutput> {
|
||||
Field::new(label).side(side).id_salt("weight").sizing(Sizing::Content).show(ui, |ui, _| weight_number(app, weight, target).show(ui))
|
||||
}
|
||||
|
||||
/// The weight field whose link side label (`label`: the Control bar's "Stroke:", the Properties panel's "Stroke")
|
||||
@@ -461,7 +587,8 @@ fn weight_row(app: &VectorcraftApp, ui: &mut Ui, label: &'static str, side: Side
|
||||
/// Weight: the label beside the Stroke chip says which paint it is the weight of.
|
||||
pub(crate) fn link_field(app: &mut VectorcraftApp, ui: &mut Ui, label: &'static str, weight: Option<f64>) {
|
||||
let side = SideLabel::new().scrub(true).link().role(FieldLabelRole::Describes).tooltip(TooltipSpec::new(tl!("Stroke options")));
|
||||
let field = weight_row(app, ui, label, side, weight);
|
||||
let target = edit_target(app, ui.ctx());
|
||||
let field = weight_row(app, ui, label, side, weight, &target);
|
||||
let open_id = field.output.id.with("stroke_popover_open");
|
||||
let mut open = ui.data(|d| d.get_temp::<bool>(open_id).unwrap_or(false));
|
||||
if let Some(out) = field.inner {
|
||||
@@ -492,30 +619,66 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps a group's starting key while its own gesture runs in the same targeting state.
|
||||
fn gesture_target(gesture: &mut FieldGesture, target: EditTarget) -> EditTarget {
|
||||
let changed = gesture.held.as_ref().is_some_and(|(_, produced)| produced != &target);
|
||||
if changed {
|
||||
gesture.held = None;
|
||||
gesture.serial = gesture.serial.wrapping_add(1);
|
||||
}
|
||||
let mut target = gesture.held.as_ref().map_or(target, |(target, _)| target.clone());
|
||||
if let Some(target) = &mut target {
|
||||
target.gesture = gesture.serial;
|
||||
}
|
||||
target
|
||||
}
|
||||
|
||||
/// Keeps the starting target and the content produced after the component's edits are applied.
|
||||
fn remember_gesture<T>(gesture: &mut FieldGesture, target: &EditTarget, events: &craft::behavior::EditEvents<T>, produced: EditTarget) {
|
||||
for event in events.iter() {
|
||||
match event {
|
||||
EditEvent::Begin { .. } => gesture.held = Some((target.clone(), produced.clone())),
|
||||
EditEvent::Commit { .. } | EditEvent::Cancel { .. } => gesture.held = None,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if let Some((_, last)) = &mut gesture.held {
|
||||
*last = produced;
|
||||
}
|
||||
}
|
||||
|
||||
/// The rows of [`show`].
|
||||
fn rows(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let st = current_stroke(app);
|
||||
let mixed = stroke_mixed(app, ui.ctx());
|
||||
let weight = shown_weight(app, st.as_ref(), &mixed);
|
||||
if let Some(out) = weight_row(app, ui, tl!("Weight"), SideLabel::new().scrub(true), weight).inner {
|
||||
let mut target = edit_target(app, ui.ctx());
|
||||
if let Some(out) = weight_row(app, ui, tl!("Weight"), SideLabel::new().scrub(true), weight, &target).inner {
|
||||
apply_weight(app, &out, WeightTarget::Shown);
|
||||
target = edit_target(app, ui.ctx());
|
||||
}
|
||||
if app.ui.stroke_panel.hide_options {
|
||||
app.ui.stroke_panel.editor_gesture.held = None;
|
||||
app.ui.stroke_panel.scale_gesture.held = None;
|
||||
return;
|
||||
}
|
||||
let style = style_of(st.as_ref());
|
||||
let editor_target = gesture_target(&mut app.ui.stroke_panel.editor_gesture, target.clone());
|
||||
let editor = StrokeEditor::new(tl!("Stroke"), Bind::given(style.clone()))
|
||||
.sections(StrokeSections::PANEL | StrokeSections::DASH_ALIGN)
|
||||
.closed(mixed.can_align)
|
||||
.caps_on_closed(true)
|
||||
.mixed(&mixed_of(&mixed))
|
||||
.host_labels(true);
|
||||
.host_labels(true)
|
||||
.edit_target(&editor_target);
|
||||
let output = editor.show(ui);
|
||||
if let (Some(new), Some(field)) = (output.events.landed(), output.field) {
|
||||
apply_style(app, &style, new.clone(), field);
|
||||
target = edit_target(app, ui.ctx());
|
||||
}
|
||||
remember_gesture(&mut app.ui.stroke_panel.editor_gesture, &editor_target, &output.events, target.clone());
|
||||
Divider::horizontal().show(ui);
|
||||
arrow_rows(app, ui, st.as_ref());
|
||||
arrow_rows(app, ui, st.as_ref(), target);
|
||||
Divider::horizontal().show(ui);
|
||||
Field::new(tl!("Profile")).show(ui, |ui, _| {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
@@ -525,8 +688,11 @@ fn rows(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The arrowhead rows: the start and end heads with Swap, the two scales with their link, and the alignment.
|
||||
fn arrow_rows(app: &mut VectorcraftApp, ui: &mut Ui, st: Option<&StrokeLayer>) {
|
||||
/// The arrowhead rows: the start and end heads with Swap, the two scales with their link, and the alignment. `target`
|
||||
/// is the current edit target used to track scale gestures.
|
||||
fn arrow_rows(app: &mut VectorcraftApp, ui: &mut Ui, st: Option<&StrokeLayer>, target: EditTarget) {
|
||||
let scale_target = gesture_target(&mut app.ui.stroke_panel.scale_gesture, target.clone());
|
||||
let mut updated = false;
|
||||
let custom: Vec<Arrowhead> = app.session.arrowheads.heads().iter().cloned().map(Arrowhead::Custom).collect();
|
||||
let entries: Vec<Entry<Option<Arrowhead>>> = std::iter::once(None)
|
||||
.chain(Arrowhead::ALL.iter().cloned().map(Some))
|
||||
@@ -551,10 +717,12 @@ fn arrow_rows(app: &mut VectorcraftApp, ui: &mut Ui, st: Option<&StrokeLayer>) {
|
||||
let out = if listed { select } else { select.unlisted_label(unlisted_arrow_name(head.as_ref())) }.show(ui);
|
||||
// A custom head goes with its art, as document.inspect reports it.
|
||||
apply_select(app, key, &out, |app, a| set(app, json!({ key: a })));
|
||||
updated |= out.events.iter().next().is_some();
|
||||
}
|
||||
let swap = IconButton::new(IconId::new("arrow-left-right")).label(tl!("Swap start and end arrowheads")).enabled(st.is_some()).show(ui);
|
||||
if swap.clicked() {
|
||||
app.run("stroke.setAdvanced", json!({"swapArrows": true})).ok();
|
||||
updated = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -568,6 +736,7 @@ fn arrow_rows(app: &mut VectorcraftApp, ui: &mut Ui, st: Option<&StrokeLayer>) {
|
||||
.mode(LinkMode::Equal)
|
||||
.unit_kind(UnitKind::Percent)
|
||||
.enabled(has_head)
|
||||
.edit_target(&scale_target)
|
||||
.show(ui)
|
||||
})
|
||||
.inner;
|
||||
@@ -576,6 +745,13 @@ fn arrow_rows(app: &mut VectorcraftApp, ui: &mut Ui, st: Option<&StrokeLayer>) {
|
||||
}
|
||||
if let Some([a, b]) = out.as_ref().and_then(|out| out.edit.events.landed()).map(|p| (*p).map(|m| m.same().copied().flatten())) {
|
||||
app.run("stroke.setAdvanced", json!({"arrowScale": [a.unwrap_or(scale.0), b.unwrap_or(scale.1)]})).ok();
|
||||
updated = true;
|
||||
}
|
||||
if let Some(out) = &out {
|
||||
let produced = if updated { edit_target(app, ui.ctx()) } else { target };
|
||||
remember_gesture(&mut app.ui.stroke_panel.scale_gesture, &scale_target, &out.edit.events, produced);
|
||||
} else {
|
||||
app.ui.stroke_panel.scale_gesture.held = None;
|
||||
}
|
||||
let aligns: Vec<Entry<ArrowAlign>> = ARROW_ALIGN.iter().map(|(v, _, icon, tip)| Entry::new(*v, *tip).icon(IconId::new(icon))).collect();
|
||||
let out = Field::new(tl!("Align"))
|
||||
@@ -1021,6 +1197,15 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
#[test]
|
||||
fn paint_digest_tracks_stroke_width() {
|
||||
let paint = PaintDefaults::default();
|
||||
let mut changed = paint.clone();
|
||||
assert_eq!(paint_digest(&paint), paint_digest(&changed));
|
||||
changed.stroke_width += 1.0;
|
||||
assert_ne!(paint_digest(&paint), paint_digest(&changed));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editing_an_extended_dash_keeps_other_stroke_options_and_is_undoable() {
|
||||
use vectorcraft_engine::Session;
|
||||
@@ -1042,6 +1227,41 @@ mod tests {
|
||||
assert_eq!(current_stroke(&app).unwrap(), after);
|
||||
}
|
||||
|
||||
/// A field group's running gesture keeps the target it began with while its own edits change the stroke, and
|
||||
/// takes the current target again once the gesture ends or the selection changes.
|
||||
#[test]
|
||||
fn a_gesture_keeps_its_starting_target_until_it_ends() {
|
||||
let (mut app, path) = profiled_line(None);
|
||||
let other = app.run("shape.line", json!({"x1": 10, "y1": 80, "x2": 90, "y2": 80})).unwrap();
|
||||
app.run("select.set", json!({"ids": [path["id"]]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let shown = |target: &EditTarget| format!("{target:?}");
|
||||
let event = |e: EditEvent<f64>| craft::behavior::EditEvents::from(e);
|
||||
let id = GestureId::new(1);
|
||||
let mut gesture = FieldGesture::default();
|
||||
|
||||
let start = edit_target(&app, &ctx);
|
||||
remember_gesture(&mut gesture, &start, &event(EditEvent::begin(id, Mixed::Same(10.0), std::sync::Arc::from("Miter"), None)), start.clone());
|
||||
app.run("stroke.set", json!({"miterLimit": 22})).unwrap();
|
||||
let fresh = edit_target(&app, &ctx);
|
||||
assert_ne!(shown(&fresh), shown(&start), "the gesture's own edit changes the stroke's target");
|
||||
remember_gesture(&mut gesture, &start, &craft::behavior::EditEvents::<f64>::new(), fresh.clone());
|
||||
let held = gesture_target(&mut gesture, fresh.clone());
|
||||
assert_eq!(shown(&held), shown(&start), "the running gesture keeps its starting target");
|
||||
|
||||
remember_gesture(&mut gesture, &held, &event(EditEvent::commit(id, Mixed::Same(10.0), 22.0)), fresh.clone());
|
||||
let fresh = edit_target(&app, &ctx);
|
||||
assert_eq!(shown(&gesture_target(&mut gesture, fresh)), shown(&edit_target(&app, &ctx)), "a commit ends it");
|
||||
|
||||
let start = edit_target(&app, &ctx);
|
||||
remember_gesture(&mut gesture, &start, &event(EditEvent::begin(id, Mixed::Same(22.0), std::sync::Arc::from("Miter"), None)), start.clone());
|
||||
app.run("select.set", json!({"ids": [other["id"]]})).unwrap();
|
||||
let fresh = edit_target(&app, &ctx);
|
||||
let now = gesture_target(&mut gesture, fresh);
|
||||
assert_ne!(shown(&now), shown(&start), "another selection ends the held target");
|
||||
assert!(gesture.held.is_none());
|
||||
}
|
||||
|
||||
/// The Profile and arrowhead selects name a current value that is none of their choices on the closed face, and
|
||||
/// the open list keeps only the choices.
|
||||
#[test]
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user