mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Fix #10706: Blend Options and other preview dialogs leave the canvas undimmed
A dialog's modal layer dims everything but the canvas the dialog registers. Blend Options, the envelope and path dialogs, Split Into Grid, Flare Tool Options, Justification, Proof Setup, Swatch Options, the Tangent Circle radius dialog, the add-on dialogs and the command dialogs with a Preview box registered no canvas, so the art they previewed was shown dimmed and the wheel over it did not scroll the view. dialogs::host::preview_canvas gives the current window's canvas, and PreviewsOn::previews_on registers it when the dialog previews. The add-on dialog host registers it for every add-on dialog. Blend Options with no blend selected sets the defaults for new blends and previews nothing, so it still dims the canvas. Part of #10590.
This commit is contained in:
1 parent
5ee0ebc7be
commit
8a546bbdc5
20 files changed
+170
-35
No files matched your search
@@ -149,7 +149,15 @@ pub(crate) fn open_with(
|
||||
previewing: bool,
|
||||
) -> Result<Value, String> {
|
||||
let ctx = app.ui_ctx.clone().ok_or("no window")?;
|
||||
let dialog = HostedParamDialog::new(&ctx, spec.command, fields, build);
|
||||
// Each add-on dialog previews on the canvas, so the scrim leaves the canvas undimmed (#10706).
|
||||
let canvas = crate::dialogs::host::preview_canvas(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, spec.command, fields, move |fields| {
|
||||
let dialog = build(fields);
|
||||
match canvas {
|
||||
Some(canvas) => dialog.canvas(canvas),
|
||||
None => dialog,
|
||||
}
|
||||
});
|
||||
let dialog = if previewing { dialog } else { dialog.preview_off() };
|
||||
let host = app.dialogs().ok_or("no window")?;
|
||||
close_open(app);
|
||||
|
||||
@@ -16,7 +16,7 @@ use vectorcraft_tools::addons::tangent_circle;
|
||||
|
||||
use crate::VectorcraftApp;
|
||||
use crate::canvas::rulers::general_lengths;
|
||||
use crate::dialogs::host::{HeldOptions, open_held_with};
|
||||
use crate::dialogs::host::{HeldOptions, PreviewsOn as _, open_held_with, preview_canvas};
|
||||
use crate::dialogs::preview::LivePreview;
|
||||
|
||||
/// The dialog's kind.
|
||||
@@ -64,9 +64,10 @@ pub(crate) fn open(app: &mut VectorcraftApp, p: &Value) {
|
||||
let lengths = general_lengths(app);
|
||||
let fields = DialogFields::from_pairs([("radius", FieldValue::Number(radius))]);
|
||||
// The field has no bounds: a radius typed outside the tool's range is kept as typed and shows [`RADIUS_RANGE`].
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |fields| {
|
||||
let rows = vec![Param::number("radius", tl!("Radius:"), radius, 1.0, 2).length(lengths)];
|
||||
ParamDialog::new(KIND, tl!("Tangent Circle"), rows).values(Bind::bound(fields)).previews(true)
|
||||
ParamDialog::new(KIND, tl!("Tangent Circle"), rows).values(Bind::bound(fields)).previews_on(true, canvas)
|
||||
});
|
||||
let cancel: Box<dyn FnOnce(&mut VectorcraftApp)> = Box::new(|app| {
|
||||
if let Some(mut open) = app.addon_dialogs.tangent_radius.take() {
|
||||
|
||||
@@ -19,7 +19,7 @@ use craft::ui::runtime::env::LengthUnits;
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::{NodeId, Selection};
|
||||
|
||||
use super::host::{HeldOptions, open_held_with};
|
||||
use super::host::{HeldOptions, PreviewsOn as _, open_held_with, preview_canvas};
|
||||
use super::preview::LivePreview; // PLAN: assumed path of wg.A20's `LivePreview`
|
||||
use crate::VectorcraftApp;
|
||||
use crate::canvas::general_lengths;
|
||||
@@ -119,7 +119,8 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let opening = Arc::new(());
|
||||
let cancelled = Arc::clone(&opening);
|
||||
let document = app.session.active().map(|st| (st.uid, st.reverts));
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |fields| dialog(on_blend, lengths).values(Bind::bound(fields)));
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |fields| dialog(on_blend, lengths, canvas).values(Bind::bound(fields)));
|
||||
let cancel: Box<dyn FnOnce(&mut VectorcraftApp)> = Box::new(move |app| {
|
||||
if app.object_dialogs.blend.as_ref().is_some_and(|open| Arc::ptr_eq(&open.opening, &cancelled))
|
||||
&& let Some(open) = app.object_dialogs.blend.take()
|
||||
@@ -138,7 +139,8 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
}
|
||||
|
||||
/// The dialog over its rows; Steps shows (disabled for Smooth Color) with the two modes that have a count of steps.
|
||||
fn dialog<'a>(on_blend: bool, lengths: LengthUnits) -> ParamDialog<'a> {
|
||||
/// It previews a blend on `canvas`.
|
||||
fn dialog<'a>(on_blend: bool, lengths: LengthUnits, canvas: Option<egui::Id>) -> ParamDialog<'a> {
|
||||
let spacing = SPACING.iter().map(|(value, label)| ((*value).to_owned(), tl!(label).into())).collect();
|
||||
let params = vec![
|
||||
Param::new("spacing", tl!("Spacing:"), ParamKind::choice(spacing, None)),
|
||||
@@ -148,7 +150,7 @@ fn dialog<'a>(on_blend: bool, lengths: LengthUnits) -> ParamDialog<'a> {
|
||||
Param::number("distance", tl!("Distance"), 10.0, 1.0, 3).length(lengths).bounds(Some(0.001), None).visible_when("spacing", "distance"),
|
||||
Param::custom("orientation", tl!("Orientation:"), orientation_row),
|
||||
];
|
||||
ParamDialog::new(KIND, tl!("Blend Options"), params).previews(on_blend)
|
||||
ParamDialog::new(KIND, tl!("Blend Options"), params).previews_on(on_blend, canvas)
|
||||
}
|
||||
|
||||
/// The orientation the fields hold: `page` unless it is `path`.
|
||||
|
||||
@@ -47,7 +47,7 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
fields.set("name", g.name.as_str());
|
||||
let ctx = app.ui_ctx.clone().ok_or(NO_WINDOW)?;
|
||||
let rows = vec![Param::new("name", field_label(tl!("Name:")), ParamKind::text(""))];
|
||||
let dialog = hosted(&ctx, KIND, tl!("Color Group Options"), fields, rows, false);
|
||||
let dialog = hosted(&ctx, KIND, tl!("Color Group Options"), fields, rows, false, None);
|
||||
let ok = move |app: &mut VectorcraftApp, answer: &ParamResult| -> Result<(), String> {
|
||||
// A different document, a revert, or a different group closes the draft without renaming.
|
||||
if !same_group(app, &identity) {
|
||||
|
||||
@@ -54,7 +54,7 @@ pub fn open(app: &mut VectorcraftApp) {
|
||||
})
|
||||
.response
|
||||
});
|
||||
let dialog = hosted(&ctx, KIND, tl!("Color Guide Options"), fields, vec![steps, variations], false);
|
||||
let dialog = hosted(&ctx, KIND, tl!("Color Guide Options"), fields, vec![steps, variations], false, None);
|
||||
let ok = |app: &mut VectorcraftApp, answer: &ParamResult| -> Result<(), String> {
|
||||
app.ui.color_guide = options(app.ui.color_guide, &answer.fields);
|
||||
Ok(())
|
||||
|
||||
@@ -10,7 +10,7 @@ use craft::ui::runtime::env::{Label, LengthUnits, UnitKind};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use super::form;
|
||||
use super::host::{HeldOptions, open_held_with};
|
||||
use super::host::{HeldOptions, PreviewsOn as _, open_held_with, preview_canvas};
|
||||
use super::preview::LivePreview;
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
@@ -119,11 +119,12 @@ pub(crate) fn open(app: &mut VectorcraftApp, command: &str, label: &str, mut par
|
||||
let setting = Setting::of(app);
|
||||
let fields = form::fields_of(&command_params(command, ¶ms, setting), ¶ms);
|
||||
let token = Arc::new(());
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = {
|
||||
let (key, heading, opening) = (command.to_string(), heading_label(label), params.clone());
|
||||
HostedParamDialog::command(&ctx, command, fields, move |fields| {
|
||||
ParamDialog::command(key.clone(), heading.clone(), command_params(&key, &opening, setting))
|
||||
.previews(previews)
|
||||
.previews_on(previews, canvas)
|
||||
.values(craft::ui::contract::Bind::bound(fields))
|
||||
})
|
||||
// The Preview box starts off, as production's dialogs did (#5360).
|
||||
|
||||
@@ -36,7 +36,7 @@ use serde_json::{Map, Value, json};
|
||||
use vectorcraft_doc::{EnvelopeKind, NodeKind};
|
||||
|
||||
use super::form::{fields_of, json_of};
|
||||
use super::host::{HeldOptions, open_held_with};
|
||||
use super::host::{HeldOptions, PreviewsOn as _, open_held_with, preview_canvas};
|
||||
use super::preview::LivePreview;
|
||||
use super::warp_effect::{percent_param, row_label, static_style, style_entries, style_param};
|
||||
use crate::VectorcraftApp;
|
||||
@@ -195,9 +195,12 @@ fn open_dialog(app: &mut VectorcraftApp, kind: &'static str, values: Map<String,
|
||||
}
|
||||
}
|
||||
let fields = fields_of(¶ms(kind, &DialogFields::new()), &values);
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = HostedParamDialog::command(&ctx, kind, fields, move |fields| {
|
||||
let reset = fields.bool("reset").unwrap_or(false);
|
||||
ParamDialog::command(kind, heading(kind, reset), params(kind, fields)).previews(kind != OPTIONS || envelope).values(Bind::bound(fields))
|
||||
ParamDialog::command(kind, heading(kind, reset), params(kind, fields))
|
||||
.previews_on(kind != OPTIONS || envelope, canvas)
|
||||
.values(Bind::bound(fields))
|
||||
});
|
||||
let generation = OPENED.fetch_add(1, Ordering::Relaxed);
|
||||
let cancel = Box::new(move |app: &mut VectorcraftApp| {
|
||||
|
||||
@@ -26,7 +26,7 @@ use vectorcraft_geom::Point;
|
||||
use vectorcraft_tools::extra::{FLARE_OPTIONS, flare_params};
|
||||
|
||||
use super::form;
|
||||
use super::host::{HeldOptions, open_held_with};
|
||||
use super::host::{HeldOptions, PreviewsOn as _, open_held_with, preview_canvas};
|
||||
use super::preview::LivePreview;
|
||||
use super::tool_options;
|
||||
use crate::VectorcraftApp;
|
||||
@@ -129,8 +129,12 @@ pub fn open(app: &mut VectorcraftApp, at: Option<Point>) -> Value {
|
||||
}
|
||||
});
|
||||
let held = HeldOptions { parent: None, cancel: Some(cancel) };
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |fields| {
|
||||
ParamDialog::new(KIND, tl!("Flare Tool Options"), params(lengths)).values(Bind::bound(fields)).previews(previews).reset_to(defaults.clone())
|
||||
ParamDialog::new(KIND, tl!("Flare Tool Options"), params(lengths))
|
||||
.values(Bind::bound(fields))
|
||||
.previews_on(previews, canvas)
|
||||
.reset_to(defaults.clone())
|
||||
});
|
||||
let document = app.session.active().map(|st| (st.uid, st.reverts));
|
||||
match open_held_with(app, dialog, ok, held) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//! module and every held dialog.
|
||||
|
||||
use craft::ui::dialog::{DialogId, DialogResult, HoldsOk};
|
||||
use craft::ui::patterns::form_dialogs::ParamDialog;
|
||||
use craft::ui::runtime::env::WindowKey;
|
||||
use craft::ui::shell::WindowDialogs;
|
||||
use serde_json::Value;
|
||||
@@ -140,6 +141,28 @@ pub(crate) fn open_held_with<D: HoldsOk>(
|
||||
Some(id)
|
||||
}
|
||||
|
||||
/// The canvas of the window that shows the active document, for a dialog that previews on it.
|
||||
pub(crate) fn preview_canvas(app: &VectorcraftApp) -> Option<egui::Id> {
|
||||
crate::doc_windows::current(app).map(crate::canvas::canvas_id)
|
||||
}
|
||||
|
||||
/// A parameter dialog's Preview box over a document canvas.
|
||||
pub(crate) trait PreviewsOn {
|
||||
/// Shows the Preview box when `on`, and then registers `canvas` (from [`preview_canvas`]): the modal layer's
|
||||
/// scrim leaves that canvas undimmed, so the preview shows its true colors, and the wheel still moves the view.
|
||||
fn previews_on(self, on: bool, canvas: Option<egui::Id>) -> Self;
|
||||
}
|
||||
|
||||
impl PreviewsOn for ParamDialog<'_> {
|
||||
fn previews_on(self, on: bool, canvas: Option<egui::Id>) -> Self {
|
||||
let dialog = self.previews(on);
|
||||
match canvas.filter(|_| on) {
|
||||
Some(canvas) => dialog.canvas(canvas),
|
||||
None => dialog,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The dialog on top of the stack.
|
||||
pub(crate) fn top_dialog(app: &VectorcraftApp) -> Option<DialogId> {
|
||||
// `open_dialogs` lists in opening order, the top one last.
|
||||
|
||||
@@ -24,6 +24,7 @@ use craft::ui::runtime::env::UnitKind;
|
||||
use serde_json::{Map, Value, json};
|
||||
use vectorcraft_doc::{JustificationOptions, SingleWordJustify};
|
||||
|
||||
use super::host::{PreviewsOn as _, preview_canvas};
|
||||
use super::preview::LivePreview;
|
||||
use super::warichu::set_shared;
|
||||
use crate::VectorcraftApp;
|
||||
@@ -92,8 +93,8 @@ fn problem(fields: &DialogFields) -> Option<&'static str> {
|
||||
}
|
||||
|
||||
/// The dialog over its values: three titled groups of Minimum, Desired and Maximum, Auto Leading and
|
||||
/// Single Word Justification. Preview starts off ([`HostedParamDialog::preview_off`]).
|
||||
fn form(fields: &mut DialogFields) -> ParamDialog<'_> {
|
||||
/// Single Word Justification. Preview starts off ([`HostedParamDialog::preview_off`]) and shows on `canvas`.
|
||||
fn form(fields: &mut DialogFields, canvas: Option<egui::Id>) -> ParamDialog<'_> {
|
||||
let titles = [tl!("Word Spacing"), tl!("Letter Spacing"), tl!("Glyph Scaling")];
|
||||
let columns = [tl!("Minimum"), tl!("Desired"), tl!("Maximum")];
|
||||
let mut rows = Vec::new();
|
||||
@@ -108,7 +109,7 @@ fn form(fields: &mut DialogFields) -> ParamDialog<'_> {
|
||||
let options = single_word_choices().into_iter().map(|(id, label)| (id.to_owned(), label.into())).collect();
|
||||
rows.push(Param::new("singleWord", tl!("Single Word Justification:"), ParamKind::choice(options, Some("fullJustify".to_owned()))));
|
||||
let reason = problem(fields);
|
||||
let dialog = ParamDialog::new(KIND, tl!("Justification"), rows).previews(true).values(Bind::bound(fields));
|
||||
let dialog = ParamDialog::new(KIND, tl!("Justification"), rows).previews_on(true, canvas).values(Bind::bound(fields));
|
||||
match reason {
|
||||
Some(why) => dialog.ok_enabled(false).ok_reason(why.into()),
|
||||
None => dialog,
|
||||
@@ -145,7 +146,8 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
set_shared(&mut fields, "autoLeading", crate::panels::paragraph::shared_justification_f64(app, |j| j.auto_leading));
|
||||
set_shared(&mut fields, "singleWord", crate::panels::paragraph::shared_single_word_justify(app).map(single_word_name));
|
||||
let ctx = app.ui_ctx.clone().ok_or("no window")?;
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields.clone(), form).preview_off();
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields.clone(), move |fields| form(fields, canvas)).preview_off();
|
||||
let id = super::host::open_held(app, dialog, |app, result| {
|
||||
let Some(open) = app.justification.take() else { return Ok(()) };
|
||||
if !open.in_opening_document(app) {
|
||||
|
||||
@@ -36,7 +36,7 @@ pub fn open(app: &mut VectorcraftApp, swatches: Vec<String>) -> Result<Value, St
|
||||
Param::new("toGlobal", tl!("Convert Process to Global").to_owned(), ParamKind::bool(true)).enabled_when("from", "artwork"),
|
||||
Param::new("includeTints", tl!("Include Swatches for Tints").to_owned(), ParamKind::bool(false)).enabled_when("from", "artwork"),
|
||||
];
|
||||
let dialog = hosted(&ctx, KIND, tl!("New Color Group"), fields, rows, false);
|
||||
let dialog = hosted(&ctx, KIND, tl!("New Color Group"), fields, rows, false, None);
|
||||
let ok = move |app: &mut VectorcraftApp, answer: &ParamResult| -> Result<(), String> {
|
||||
let Some(source) = app.session.active().filter(|active| active.uid == document) else {
|
||||
return Err(tl!("Create this color group in the document that opened the dialog.").to_owned());
|
||||
|
||||
@@ -49,7 +49,7 @@ pub fn open(app: &mut VectorcraftApp, spot: bool, global: bool, group: Option<&s
|
||||
other => (vec![name_row()], Some(crate::panels::swatch_paint_params(other))),
|
||||
};
|
||||
let ctx = app.ui_ctx.clone().ok_or(NO_WINDOW)?;
|
||||
let dialog = hosted(&ctx, KIND, tl!("New Swatch"), fields, rows, false);
|
||||
let dialog = hosted(&ctx, KIND, tl!("New Swatch"), fields, rows, false, None);
|
||||
let group = group.unwrap_or_default().to_owned();
|
||||
let ok = move |app: &mut VectorcraftApp, answer: &ParamResult| -> Result<(), String> {
|
||||
let active =
|
||||
|
||||
@@ -26,7 +26,7 @@ use vectorcraft_geom::PathData;
|
||||
|
||||
use super::form;
|
||||
// PLAN: assumed `LivePreview` is exported by `dialogs::form` (wg.A20, widgets-w11).
|
||||
use super::host::{HeldOptions, open_held, open_held_with};
|
||||
use super::host::{HeldOptions, PreviewsOn as _, open_held, open_held_with, preview_canvas};
|
||||
use super::preview::LivePreview;
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
@@ -445,13 +445,14 @@ fn open_dialog(app: &mut VectorcraftApp, op: PathOp, fields: DialogFields, remem
|
||||
let lengths = crate::canvas::general_lengths(app);
|
||||
let opening = op.opening();
|
||||
let key = op.key();
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, key, fields, move |f| {
|
||||
let mut d = ParamDialog::new(key, op.title(), rows(op, &opening, lengths)).values(Bind::bound(f));
|
||||
if let Some(k) = remember.clone() {
|
||||
d = d.remember(k);
|
||||
}
|
||||
if op.previews() {
|
||||
d = d.previews(true);
|
||||
d = d.previews_on(true, canvas);
|
||||
}
|
||||
if op == PathOp::Simplify { d.below(counts_row) } else { d }
|
||||
});
|
||||
@@ -531,8 +532,9 @@ pub(crate) fn open_split(app: &mut VectorcraftApp) {
|
||||
let reverts = state.reverts;
|
||||
let (width, height) = state.doc.bounds_of(&state.selection.objects, false).map_or((0.0, 0.0), |b| (b.width(), b.height()));
|
||||
let lengths = crate::canvas::general_lengths(app);
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, SPLIT_COMMAND, split_fields(width, height), move |f| {
|
||||
ParamDialog::new(SPLIT_COMMAND, tl!("Split Into Grid"), split_rows(lengths)).values(Bind::bound(f)).previews(true)
|
||||
ParamDialog::new(SPLIT_COMMAND, tl!("Split Into Grid"), split_rows(lengths)).values(Bind::bound(f)).previews_on(true, canvas)
|
||||
});
|
||||
let ok = |app: &mut VectorcraftApp, result: &craft::ui::patterns::form_dialogs::ParamResult| {
|
||||
let Some(mut record) = app.object_dialogs.split.take() else { return Err(tl!("The Split Into Grid dialog is closed.").to_owned()) };
|
||||
|
||||
@@ -30,7 +30,7 @@ use vectorcraft_color::cms::{self, Intent, ProfileKind, ProofTarget};
|
||||
use vectorcraft_engine::cmd::colormgmt::proof_file::{self, EXT};
|
||||
use vectorcraft_render::proof;
|
||||
|
||||
use super::host::{HeldOptions, open_held_with};
|
||||
use super::host::{HeldOptions, PreviewsOn as _, open_held_with, preview_canvas};
|
||||
use crate::VectorcraftApp;
|
||||
use crate::file_asks::{Owner, ask, ask_while};
|
||||
use crate::menus::Node;
|
||||
@@ -88,7 +88,8 @@ pub fn open(app: &mut VectorcraftApp) {
|
||||
("simulatePaper", FieldValue::Bool(s.simulate_paper)),
|
||||
("simulateBlack", FieldValue::Bool(s.simulate_black)),
|
||||
]);
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, build);
|
||||
let canvas = preview_canvas(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |fields| build(fields, canvas));
|
||||
let options = HeldOptions { cancel: Some(Box::new(cancel)), ..Default::default() };
|
||||
match open_held_with(app, dialog, |app, result: &ParamResult| confirm(app, &result.fields), options) {
|
||||
Some(id) => app.ui.proof_setup = Some(Open { id, opening: Arc::new(()), before, shown: None, sent: None }),
|
||||
@@ -114,13 +115,13 @@ fn rgb_device(device: &str) -> bool {
|
||||
device.starts_with("rgb:")
|
||||
}
|
||||
|
||||
/// The dialog over the host's values, made again every pass.
|
||||
fn build(fields: &mut DialogFields) -> ParamDialog<'_> {
|
||||
/// The dialog over the host's values, made again every pass, previewing on `canvas`.
|
||||
fn build(fields: &mut DialogFields, canvas: Option<egui::Id>) -> ParamDialog<'_> {
|
||||
let footer = vec![
|
||||
(SAVE.to_string(), FooterButton::new(tl!("Save…").to_string(), DialogRole::Other).stays_open(true)),
|
||||
(LOAD_BUTTON.to_string(), FooterButton::new(tl!("Load…").to_string(), DialogRole::Other).stays_open(true)),
|
||||
];
|
||||
ParamDialog::new(KIND, tl!("Proof Setup").to_string(), rows(fields)).values(Bind::bound(fields)).previews(true).extra_buttons(footer)
|
||||
ParamDialog::new(KIND, tl!("Proof Setup").to_string(), rows(fields)).values(Bind::bound(fields)).previews_on(true, canvas).extra_buttons(footer)
|
||||
}
|
||||
|
||||
/// The rows for the values `fields` hold now.
|
||||
|
||||
@@ -39,7 +39,7 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
fields.set("limitTo", limit.clone());
|
||||
fields.set(OPENING, FieldValue::Json(json!({"uid": document, "reverts": reverts, "colors": colors})));
|
||||
let rows = vec![Param::new("limitTo", field_label(tl!("Limit to Library:")), ParamKind::choice(options, Some(limit)))];
|
||||
let dialog = hosted(&ctx, KIND, tl!("Recolor with Preset"), fields, rows, false);
|
||||
let dialog = hosted(&ctx, KIND, tl!("Recolor with Preset"), fields, rows, false, None);
|
||||
// Recolor Artwork takes the dialog's place; when it cannot open, this dialog stays.
|
||||
let ok = |app: &mut VectorcraftApp, answer: &ParamResult| -> Result<(), String> {
|
||||
let Some(FieldValue::Json(opening)) = answer.fields.get(OPENING) else { return Err("the Recolor with Preset target is missing".into()) };
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
fields.set("values", id(use_lab));
|
||||
let options = CHOICES.iter().map(|(lab, text, help)| (id(*lab).to_owned(), tl!(text).to_owned().into(), tl!(help).to_owned().into())).collect();
|
||||
let rows = vec![Param::new("values", field_label(tl!("Lab Spot Colors:")), ParamKind::radio_with_details(options, Some(id(true).to_owned())))];
|
||||
let dialog = hosted(&ctx, KIND, tl!("Spot Colors"), fields, rows, false);
|
||||
let dialog = hosted(&ctx, KIND, tl!("Spot Colors"), fields, rows, false, None);
|
||||
let ok = |app: &mut VectorcraftApp, answer: &ParamResult| -> Result<(), String> {
|
||||
let use_lab = answer.fields.text("values") == Some(id(true));
|
||||
app.run("swatch.spotOptions", json!({ "useLab": use_lab })).map(|_| ())
|
||||
|
||||
@@ -31,7 +31,7 @@ use serde_json::{Value, json};
|
||||
use vectorcraft_color::cms::Model;
|
||||
use vectorcraft_color::{Color, GradientPaint, Paint};
|
||||
|
||||
use super::host::{HeldOptions, open_held_with};
|
||||
use super::host::{HeldOptions, PreviewsOn as _, open_held_with, preview_canvas};
|
||||
use crate::VectorcraftApp;
|
||||
use crate::panels::color::{color_of_values, gamut, model_values};
|
||||
|
||||
@@ -179,7 +179,8 @@ pub(super) fn name_row() -> Param {
|
||||
Param::new("name", field_label(tl!("Swatch Name:")), ParamKind::text(""))
|
||||
}
|
||||
|
||||
/// A hosted dialog for the command `key`, whose rows are `rows`: the one way the colour dialogs build theirs.
|
||||
/// A hosted dialog for the command `key`, whose rows are `rows`: the one way the colour dialogs build theirs. One
|
||||
/// that `previews` does so on `canvas`.
|
||||
pub(super) fn hosted(
|
||||
ctx: &egui::Context,
|
||||
key: &'static str,
|
||||
@@ -187,10 +188,11 @@ pub(super) fn hosted(
|
||||
fields: DialogFields,
|
||||
rows: Vec<Param>,
|
||||
previews: bool,
|
||||
canvas: Option<egui::Id>,
|
||||
) -> HostedParamDialog {
|
||||
let title = title.to_owned();
|
||||
HostedParamDialog::new(ctx, key, fields, move |values| {
|
||||
ParamDialog::new(key, title.clone(), rows.clone()).values(Bind::bound(values)).previews(previews)
|
||||
ParamDialog::new(key, title.clone(), rows.clone()).values(Bind::bound(values)).previews_on(previews, canvas)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -294,7 +296,7 @@ fn launch(app: &mut VectorcraftApp, swatch: &str, fields: DialogFields, rows: Ve
|
||||
let active = app.session.active().ok_or("no drawing")?;
|
||||
let document = (active.uid, active.reverts);
|
||||
let ctx = app.ui_ctx.clone().ok_or(NO_WINDOW)?;
|
||||
let dialog = hosted(&ctx, KIND, tl!("Swatch Options"), fields, rows, true);
|
||||
let dialog = hosted(&ctx, KIND, tl!("Swatch Options"), fields, rows, true, preview_canvas(app));
|
||||
if owns_preview(app) {
|
||||
let _ = app.session.cancel_interaction();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ pub(super) mod picks;
|
||||
mod place;
|
||||
mod plugin_runs;
|
||||
mod plugins;
|
||||
mod preview_canvas;
|
||||
mod printps;
|
||||
mod printtiling;
|
||||
mod quickpenbar;
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
//! Dialogs that preview on the canvas keep the canvas open under their modal layer (#10706): the scrim leaves it
|
||||
//! undimmed, so the preview shows its true colors, and the wheel over it still scrolls the view.
|
||||
|
||||
use serde_json::{Map, json};
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
fn step(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>) {
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 850.0));
|
||||
crate::testing::app_frame(app, ctx, egui::RawInput { screen_rect: Some(screen), events, ..Default::default() });
|
||||
}
|
||||
|
||||
/// A window on a drawing of two squares, both selected, after the frames that lay out its canvas.
|
||||
fn app() -> (VectorcraftApp, egui::Context) {
|
||||
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
|
||||
for x in [0, 200] {
|
||||
app.run("shape.rectangle", json!({"x": x, "y": 0, "width": 20, "height": 20})).unwrap();
|
||||
}
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
for _ in 0..3 {
|
||||
step(&mut app, &ctx, vec![]);
|
||||
}
|
||||
(app, ctx)
|
||||
}
|
||||
|
||||
/// Whether the wheel over the canvas scrolls the view while a dialog is open on top.
|
||||
fn wheel_scrolls_the_view(app: &mut VectorcraftApp, ctx: &egui::Context) -> bool {
|
||||
for _ in 0..3 {
|
||||
step(app, ctx, vec![]);
|
||||
}
|
||||
assert!(crate::dialogs::host::top_dialog(app).is_some(), "a dialog is open");
|
||||
let at = app.canvas_view().unwrap().rect.left_top() + egui::vec2(20.0, 20.0);
|
||||
for _ in 0..3 {
|
||||
step(app, ctx, vec![egui::Event::PointerMoved(at)]);
|
||||
}
|
||||
let before = app.canvas_view().unwrap().center;
|
||||
let wheel = egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Line,
|
||||
delta: egui::vec2(0.0, -3.0),
|
||||
phase: egui::TouchPhase::Move,
|
||||
modifiers: egui::Modifiers::default(),
|
||||
source: egui::MouseWheelSource::Unknown,
|
||||
};
|
||||
for _ in 0..5 {
|
||||
step(app, ctx, vec![egui::Event::PointerMoved(at), wheel.clone()]);
|
||||
}
|
||||
app.canvas_view().unwrap().center != before
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blend_options_on_a_blend_keeps_the_canvas_open() {
|
||||
let (mut app, ctx) = app();
|
||||
app.run("object.blend.make", json!({"smooth": true})).unwrap();
|
||||
app.run("ui.blendOptions", json!({})).unwrap();
|
||||
assert!(wheel_scrolls_the_view(&mut app, &ctx), "the wheel over the canvas scrolls the view under Blend Options");
|
||||
}
|
||||
|
||||
/// With no blend selected, Blend Options sets the defaults and has nothing to preview, so the canvas stays covered.
|
||||
#[test]
|
||||
fn blend_options_for_the_defaults_leaves_the_canvas_covered() {
|
||||
let (mut app, ctx) = app();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
app.run("ui.blendOptions", json!({})).unwrap();
|
||||
assert!(!wheel_scrolls_the_view(&mut app, &ctx), "the wheel over the canvas does not reach the view");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_add_on_dialog_keeps_the_canvas_open() {
|
||||
let (mut app, ctx) = app();
|
||||
crate::addons::dialogs::open_from_menu(&mut app, crate::addons::select::points_only::COMMAND).unwrap().unwrap();
|
||||
assert!(wheel_scrolls_the_view(&mut app, &ctx), "the wheel over the canvas scrolls the view under Edit Points Only");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_previewing_command_dialog_keeps_the_canvas_open() {
|
||||
let (mut app, ctx) = app();
|
||||
crate::dialogs::command::open(&mut app, crate::addons::pathtools::BOUNDING_RECTANGLE, "Bounding Rectangle", Map::new()).unwrap();
|
||||
assert!(wheel_scrolls_the_view(&mut app, &ctx), "the wheel over the canvas scrolls the view under the command's dialog");
|
||||
}
|
||||
@@ -17537,6 +17537,9 @@ without `spacing` are errors that change
|
||||
nothing, and a call that changes no blend records no undo step. With no blend selected and no `id`, the call sets the
|
||||
spacing and orientation new blends start with. The Blend panel's Ramp and Shift sliders run it on the selected blends:
|
||||
a drag previews and its release records one undo step. Blend Options sends only the spacing or orientation set in the dialog.
|
||||
While Blend Options previews a selected blend, the canvas of the current window is not dimmed under the dialog, and the
|
||||
wheel over it still scrolls the view. Other dialogs with a Preview box on the canvas (envelope, path, Flare Tool,
|
||||
Justification, Proof Setup, Swatch Options, add-on and command dialogs) work the same way.
|
||||
|
||||
`object.blend.setEasing {id?, easingType?, ramp?, colorShift?}` sets one blend's easing and color shift (the
|
||||
first selected blend without `id`) and returns `{id, easingType, ramp, colorShift, changed}`; omitted values are kept.
|
||||
|
||||
Reference in new issue
Block a user