mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 10:51:11 +01:00
Anchor Stroke and Opacity panels to the clicked field and remove fade seams
This commit is contained in:
1 parent
86a4421090
commit
97fdd3ed8f
7 files changed
+50
-24
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<bool>)>,
|
||||
/// 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<f64>) -> Option<NumberOutput> {
|
||||
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<f64>,
|
||||
) -> (egui::Response, Option<NumberOutput>) {
|
||||
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<f64>) {
|
||||
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 {
|
||||
|
||||
@@ -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<crate::panels::PaintPopover>,
|
||||
/// The individual Stroke or Opacity field whose linked panel is open.
|
||||
#[serde(skip)]
|
||||
pub option_panel: Option<egui::Id>,
|
||||
/// 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(),
|
||||
|
||||
Reference in new issue
Block a user