From 97fdd3ed8f0f6f43a9f106b85d2a553656ecbe77 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 13:40:09 +0100 Subject: [PATCH] Anchor Stroke and Opacity panels to the clicked field and remove fade seams --- crates/doc/src/arrow.rs | 4 +--- crates/effects/src/stroke.rs | 2 +- crates/ui-egui/src/canvas/marks.rs | 5 ++--- crates/ui-egui/src/chrome/control_bar.rs | 12 ++++++------ crates/ui-egui/src/panels.rs | 23 +++++++++++++++++++++++ crates/ui-egui/src/panels/stroke.rs | 24 +++++++++++++----------- crates/ui-egui/src/state.rs | 4 ++++ 7 files changed, 50 insertions(+), 24 deletions(-) diff --git a/crates/doc/src/arrow.rs b/crates/doc/src/arrow.rs index dba57d8720..37add2c3d8 100644 --- a/crates/doc/src/arrow.rs +++ b/crates/doc/src/arrow.rs @@ -12,8 +12,8 @@ use std::borrow::Cow; use std::f64::consts::{FRAC_1_SQRT_2, FRAC_PI_2, PI}; -use kurbo::{Affine, BezPath, ParamCurve, ParamCurveArclen, PathSeg, Point, Shape, Vec2}; use crate::{ArrowAlign, Arrowhead, LineCap, StrokeLayer}; +use kurbo::{Affine, BezPath, ParamCurve, ParamCurveArclen, PathSeg, Point, Shape, Vec2}; use vectorcraft_geom::bez::{segments, subpaths, tangent, unit}; @@ -54,8 +54,6 @@ pub fn push_seg(out: &mut BezPath, seg: &PathSeg) { } } - - /// One arrowhead. #[derive(Clone, Debug, PartialEq)] pub struct Arrow { diff --git a/crates/effects/src/stroke.rs b/crates/effects/src/stroke.rs index 770c3b3aa0..55c8fbe297 100644 --- a/crates/effects/src/stroke.rs +++ b/crates/effects/src/stroke.rs @@ -21,8 +21,8 @@ use kurbo::{BezPath, ParamCurve, ParamCurveNearest, PathEl, PathSeg, Rect, Shape use vectorcraft_doc::{LineCap, LineJoin, StrokeAlign, StrokeLayer}; pub(crate) use vectorcraft_geom::bez::{kink, segments, subpaths, tangent, unit}; -pub use arrow::{Arrow, StrokePieces, cap_extent, stroke_pieces}; pub(crate) use arrow::push_seg; +pub use arrow::{Arrow, StrokePieces, cap_extent, stroke_pieces}; pub use dash::{Dashed, Dot, dash, dash_kept, dot_outline}; pub use gradient::{Slice, WrittenSlices, gradient_meshes, gradient_slices, written_slices}; pub use outline::{OUTLINE_TOL, Written, WrittenShape, for_writer, is_plain, outline_region}; diff --git a/crates/ui-egui/src/canvas/marks.rs b/crates/ui-egui/src/canvas/marks.rs index abe7c5a6db..2c8b5dc237 100644 --- a/crates/ui-egui/src/canvas/marks.rs +++ b/crates/ui-egui/src/canvas/marks.rs @@ -600,9 +600,8 @@ impl Component for ArtMarks<'_> { fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { let style = &cx.style; let draw = ui.draw(); - for quad in self.fade { - draw.data_fill(&PaintShape::Polygon(quad.to_vec()), FADE_OUTSIDE); - } + let pieces: Vec<_> = self.fade.iter().map(|quad| quad.to_vec()).collect(); + draw.data_fill_tiled(&pieces, FADE_OUTSIDE); let bleed = self.bleed.iter().map(|path| (path, style.bleed)); for (path, color) in bleed.chain(self.artboard_marks.iter().map(|path| (path, style.marks))) { for (points, closed) in path_runs(&self.view, path) { diff --git a/crates/ui-egui/src/chrome/control_bar.rs b/crates/ui-egui/src/chrome/control_bar.rs index 82dba96e51..fd7baf16e0 100644 --- a/crates/ui-egui/src/chrome/control_bar.rs +++ b/crates/ui-egui/src/chrome/control_bar.rs @@ -284,18 +284,18 @@ fn fill_and_stroke(app: &mut VectorcraftApp, ui: &mut Ui) { /// field, showing `opacity`. Only a selection takes the edit. fn opacity_field(app: &mut VectorcraftApp, ui: &mut Ui, opacity: f32, selected: bool) { let label = tl!("Opacity:"); - let (mut link, mut typed) = (false, None); + let mut typed = None; group(ui, rank::OPACITY, |ui| { - Field::new(label).side(SideLabel::new().link().scrub(true)).show(ui, |ui, _| { + let field = Field::new(label).side(SideLabel::new().link().scrub(true)).show(ui, |ui, _| { let number = NumberField::new(label, Bind::given(Some(f64::from(opacity) * 100.0))).range(0.0..=100.0).unit("%").scrub_by_label().show(ui); - link |= number.link; typed = number.edit.events.committed().copied().flatten().or(typed); + number.link }); + if let Some(clicked) = field.inner { + crate::panels::linked_panel(app, ui, &field.output, clicked, tl!("Transparency"), crate::panels::transparency::show); + } }); - if link { - app.ui.open_panel = Some("transparency".into()); - } if let Some(o) = typed.filter(|_| selected) { app.run("transparency.set", json!({"opacity": o.clamp(0.0, 100.0)})).ok(); } diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 2ebca9a8bc..0ac94e9875 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -1347,3 +1347,26 @@ mod tests_style_libraries; mod tests_symbol_libraries; #[cfg(test)] mod tests_units; + +/// Open the panel below the particular field whose link fired. Multiple bars can show the same setting. +pub(crate) fn linked_panel( + app: &mut VectorcraftApp, + ui: &mut Ui, + opener: &egui::Response, + activated: bool, + label: &'static str, + body: fn(&mut VectorcraftApp, &mut Ui), +) { + if ui.is_sizing_pass() { + return; + } + let mut open = app.ui.option_panel == Some(opener.id); + if activated { + open = !open; + app.ui.option_panel = open.then_some(opener.id); + } + Popover::new(label, Bind::bound(&mut open)).opened_by(opener).show(ui, |ui, _| body(app, ui)); + if !open && app.ui.option_panel == Some(opener.id) { + app.ui.option_panel = None; + } +} diff --git a/crates/ui-egui/src/panels/stroke.rs b/crates/ui-egui/src/panels/stroke.rs index 7ea1db6e49..aff64bef77 100644 --- a/crates/ui-egui/src/panels/stroke.rs +++ b/crates/ui-egui/src/panels/stroke.rs @@ -17,7 +17,6 @@ use craft::ui::layout_components::{Grid, Row}; use craft::ui::list::ThumbAspect; use craft::ui::menu::PanelRow; use craft::ui::pickers::Select; -use craft::ui::popover::Popover; use craft::ui::primitives::{ContentPainterCx, Revision, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails}; use craft::ui::runtime::commands::{CommandState, CommandStates}; use craft::ui::runtime::env::{LengthUnits, UnitKind}; @@ -55,8 +54,6 @@ pub(crate) struct StrokePanel { pub scale_linked: bool, /// The cache of [`brush_keeps_size`], keyed by (document uid, revision, active Appearance row). pub brushed: Option<(BrushedKey, Option)>, - /// The Stroke popover of the weight's link label is open. - pub link_open: bool, } /// The stroke a weight edit goes to. @@ -358,8 +355,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 output of the number field, none when /// the row's body did not run. -fn weight_row(app: &VectorcraftApp, ui: &mut Ui, label: &'static str, side: SideLabel, weight: Option) -> Option { - Field::new(label).side(side).id_salt("weight").sizing(Sizing::Content).show(ui, |ui, _| weight_number(app, weight).show(ui)).inner +fn weight_row( + app: &VectorcraftApp, + ui: &mut Ui, + label: &'static str, + side: SideLabel, + weight: Option, +) -> (egui::Response, Option) { + let field = Field::new(label).side(side).id_salt("weight").sizing(Sizing::Content).show(ui, |ui, _| weight_number(app, weight).show(ui)); + (field.output, field.inner) } /// The weight field whose link side label (`label`: the Control bar's "Stroke:", the Properties panel's "Stroke") @@ -367,13 +371,11 @@ fn weight_row(app: &VectorcraftApp, ui: &mut Ui, label: &'static str, side: Side /// 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) { let side = SideLabel::new().scrub(true).link().role(FieldLabelRole::Describes).tooltip(TooltipSpec::new(tl!("Stroke options"))); - let mut open = app.ui.stroke_panel.link_open; - if let Some(out) = weight_row(app, ui, label, side, weight) { + let (opener, out) = weight_row(app, ui, label, side, weight); + if let Some(out) = out { apply_weight(app, &out, WeightTarget::Shown); - open ^= out.link; + super::linked_panel(app, ui, &opener, out.link, tl!("Stroke"), show); } - Popover::new(tl!("Stroke"), Bind::bound(&mut open)).show(ui, |ui, _| show(app, ui)); - app.ui.stroke_panel.link_open = open; } /// The Stroke panel: the weight, the stroke editor (cap, corner, align, dashes), arrowheads, scale, align and the @@ -401,7 +403,7 @@ 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) { + if let Some(out) = weight_row(app, ui, tl!("Weight"), SideLabel::new().scrub(true), weight).1 { apply_weight(app, &out, WeightTarget::Shown); } if app.ui.stroke_panel.hide_options { diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index eeef403f06..5cb7a75706 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -1098,6 +1098,9 @@ pub struct UiState { /// The open Fill/Stroke chip popover of the Control bar or the Properties panel. Not saved. #[serde(skip)] pub paint_popover: Option, + /// The individual Stroke or Opacity field whose linked panel is open. + #[serde(skip)] + pub option_panel: Option, /// The Image Trace panel's shown settings and preset picker. Not saved. #[serde(skip)] pub(crate) image_trace_panel: crate::panels::image_trace::ImageTraceUi, @@ -1630,6 +1633,7 @@ impl Default for UiState { transform_panel: Default::default(), hidden_parts: BTreeSet::new(), paint_popover: None, + option_panel: None, image_trace_panel: Default::default(), asset_export_panel: Default::default(), pattern_options_panel: Default::default(),