mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 10:51:11 +01:00
Preview plug-in parameter edits from the visible dialog controls
This commit is contained in:
1 parent
0e6f90cb3f
commit
ef32fe3338
3 files changed
+41
-5
No files matched your search
@@ -711,7 +711,13 @@ impl VectorcraftApp {
|
||||
export_progress::show(self, ui);
|
||||
// After every window this pass may open, and before the palette's field takes the keyboard.
|
||||
panel_docking::close_overlays_for_modal(self, &ctx);
|
||||
let drawn_document = self.session.active().map(|st| (st.uid, st.revision));
|
||||
dialogs::host::pump(self, &ctx);
|
||||
// The canvas has already painted. A dialog can apply or roll back its preview
|
||||
// on the final input frame, with no further mouse movement to wake the window.
|
||||
if self.session.active().map(|st| (st.uid, st.revision)) != drawn_document {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
prefs_dialog::show(self, ui);
|
||||
crate::shortcut_editor::show(self, ui);
|
||||
credits::open_taken_link(self);
|
||||
|
||||
@@ -42,7 +42,7 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use craft::menu::Node;
|
||||
use craft::ui::contract::Show as _;
|
||||
use craft::ui::contract::{Bind, Show as _};
|
||||
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, Prompt, StackDialog, dialog_id};
|
||||
use craft::ui::display::{Shade, Text};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog};
|
||||
@@ -548,7 +548,13 @@ pub(super) fn heading(plugin: &str, command: Option<&str>, gone: &str) -> String
|
||||
/// The builder of a hosted plug-in dialog over its values: the rows of `all` whose parameter is
|
||||
/// shown for the values (`m.visible`), after the description. The rows are made again in the UI
|
||||
/// language when it changes while the dialog is open; the field values stay as they are.
|
||||
fn build(key: &'static str, m: Manifest, all: Arc<[Param]>, look: Look) -> impl for<'b> Fn(&'b mut DialogFields) -> ParamDialog<'b> + Send + 'static {
|
||||
fn build(
|
||||
key: &'static str,
|
||||
m: Manifest,
|
||||
all: Arc<[Param]>,
|
||||
look: Look,
|
||||
canvas: Option<egui::Id>,
|
||||
) -> impl for<'b> Fn(&'b mut DialogFields) -> ParamDialog<'b> + Send + 'static {
|
||||
let rows_in = std::sync::Mutex::new((lang(), all));
|
||||
move |fields| {
|
||||
let all = {
|
||||
@@ -564,7 +570,10 @@ fn build(key: &'static str, m: Manifest, all: Arc<[Param]>, look: Look) -> impl
|
||||
rows.push(Param::read_only_text("description", "", look.description.clone()).full_width());
|
||||
}
|
||||
rows.extend(all.iter().filter(|p| shown.contains(p.key.as_str())).cloned());
|
||||
let mut dialog = ParamDialog::new(key, look.heading(), Cow::Owned(rows)).previews(look.previews);
|
||||
let mut dialog = ParamDialog::new(key, look.heading(), Cow::Owned(rows)).previews(look.previews).values(Bind::bound(fields));
|
||||
if let Some(canvas) = canvas.filter(|_| look.previews) {
|
||||
dialog = dialog.canvas(canvas);
|
||||
}
|
||||
if let Some(ok) = look.ok {
|
||||
dialog = dialog.ok_label(ok.into());
|
||||
}
|
||||
@@ -592,7 +601,8 @@ fn open_hosted(
|
||||
close_open(app);
|
||||
let all: Arc<[Param]> = form::plugin_params(&m, &values).into();
|
||||
let fields = form::fields_of(&all, &values);
|
||||
let dialog = HostedParamDialog::new(&ctx, key, fields, build(key, m, Arc::clone(&all), look)).instance(instance.to_string());
|
||||
let canvas = crate::doc_windows::current(app).map(crate::canvas::canvas_id);
|
||||
let dialog = HostedParamDialog::new(&ctx, key, fields, build(key, m, Arc::clone(&all), look, canvas)).instance(instance.to_string());
|
||||
let id = dialogs.with(|host| host.open(dialog));
|
||||
Ok((id, all))
|
||||
}
|
||||
|
||||
@@ -181,7 +181,9 @@ fn plugins_are_listed_in_the_object_and_effect_menus() {
|
||||
|
||||
#[test]
|
||||
fn filter_dialog_previews_and_commits_one_undo_step() {
|
||||
let mut h = window(app());
|
||||
let mut app = app();
|
||||
app.canvas.worker_started = true; // Canvas uploads finish within the frame being asserted.
|
||||
let mut h = window(app);
|
||||
h.state_mut().run("plugin.install", json!({"dataBase64": vectorcraft_format::base64_encode(DESATURATE)})).unwrap();
|
||||
let id = red_rect(h.state_mut());
|
||||
let undo = h.state().session.doc().unwrap().history.undo.len();
|
||||
@@ -189,12 +191,30 @@ fn filter_dialog_previews_and_commits_one_undo_step() {
|
||||
step(&mut h);
|
||||
assert!(top(h.state()).is_some(), "dialog open");
|
||||
assert_eq!(fields(h.state())["amount"], json!(100.0));
|
||||
// A click in the visible slider must reach the same values the live preview reads.
|
||||
use egui_kittest::kittest::Queryable as _;
|
||||
let at = h.get_by_role(egui::accesskit::Role::Dialog).get_by_role(egui::accesskit::Role::Slider).rect().center();
|
||||
h.input_mut().events.push(egui::Event::PointerMoved(at));
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(egui::Event::PointerButton {
|
||||
pos: at,
|
||||
button: egui::PointerButton::Primary,
|
||||
pressed,
|
||||
modifiers: Default::default(),
|
||||
});
|
||||
step(&mut h);
|
||||
}
|
||||
assert!(fields(h.state())["amount"].as_f64().is_some_and(|amount| amount > 0.0 && amount < 100.0));
|
||||
// Agents set fields like `ui.dialog.set` does; the frame previews them.
|
||||
set_field(&mut h, "amount", json!(50)).unwrap();
|
||||
step(&mut h);
|
||||
assert!(h.state().session.in_interaction(), "previewing");
|
||||
let [r, g, _] = fill_rgb(h.state(), id);
|
||||
assert!(r < 1.0 && g > 0.0, "half desaturated on the canvas: {r} {g}");
|
||||
step(&mut h);
|
||||
let (shown, _) = h.state().canvas.shown.as_ref().expect("a rendered canvas frame");
|
||||
let shown_fill = shown.node(id).unwrap().appearance.fill_paint().color().unwrap().to_rgb_uncalibrated();
|
||||
assert_eq!(shown_fill, fill_rgb(h.state(), id), "the canvas showed the preview before OK");
|
||||
answer(&mut h, true);
|
||||
assert!(top(h.state()).is_none());
|
||||
let st = h.state().session.doc().unwrap();
|
||||
|
||||
Reference in new issue
Block a user