mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 16:55:55 +00:00
Merge pull request #8672 from storytold/train/carry8286
#8284: restore Brush Options Key Color canvas sampling (#8286)
This commit is contained in:
@@ -463,11 +463,18 @@ impl VectorcraftApp {
|
||||
/// and the tool remembered for the toolbar group and for the Touch workspace's drawing mode
|
||||
/// stays as it was.
|
||||
pub(crate) fn try_select_tool(&mut self, id: &str) -> Result<(), String> {
|
||||
let back = self.ui.brush_key_color_pick.as_ref().map(|pick| pick.back.clone());
|
||||
crate::dialogs::cancel_brush_key_color(self, false);
|
||||
// The tip of a pen whose eraser end selected the Eraser doesn't undo this choice, and
|
||||
// neither does letting go of a held tool shortcut.
|
||||
self.pen_end.forget_tool();
|
||||
self.held_tool.clear();
|
||||
self.activate_tool(id, true)?;
|
||||
if let Err(error) = self.activate_tool(id, true) {
|
||||
if let Some(back) = back.filter(|_| self.session.tool_id() == "eyedropper") {
|
||||
self.return_to_tool(&back);
|
||||
}
|
||||
return Err(error);
|
||||
}
|
||||
let now = self.session.tool_id();
|
||||
if crate::touch::is_drawing_tool(now) {
|
||||
self.ui.touch_drawing_tool = Some(now.to_string());
|
||||
|
||||
@@ -16,8 +16,12 @@ pub(super) fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respo
|
||||
feed.bind_repaint(ui.ctx());
|
||||
}
|
||||
// A modal dialog takes the canvas's presses, finger taps, long touches and view navigation, from the frame it opens.
|
||||
let cancelled = crate::dialogs::refresh_brush_key_color(app);
|
||||
let modal = crate::panel_docking::modal_open(app, ui.ctx());
|
||||
let (pointer, m, space, hover) = wheel_view(app, ui, resp, rect, modal);
|
||||
if (cancelled && pointer.primary_pressed()) || crate::dialogs::brush_key_color_input(app, ui, resp, rect) {
|
||||
return;
|
||||
}
|
||||
let v = *app.view().unwrap_or(&View::default());
|
||||
let xf = Xf::at(rect, &v, app.canvas_ui_zoom);
|
||||
// A lifted pen or finger takes the pointer away in the frame it lifts (egui's `PointerGone`),
|
||||
|
||||
@@ -18,6 +18,7 @@ pub mod artboard_options;
|
||||
pub mod attributes_panel_options;
|
||||
pub mod blend_options;
|
||||
mod brush_art_options;
|
||||
pub(crate) use brush_art_options::{brush_key_color_canvas, brush_key_color_input, cancel_brush_key_color, refresh_brush_key_color};
|
||||
pub mod brush_delete;
|
||||
pub mod brush_options;
|
||||
pub mod brush_replace_art;
|
||||
@@ -748,6 +749,7 @@ pub(crate) fn field_set(app: &mut VectorcraftApp, field: &str, old: Option<&Valu
|
||||
/// Close the open dialog as Cancel does, rolling back a live preview and showing the dialog it was
|
||||
/// opened over (`ui.dialog.cancel`).
|
||||
pub fn cancel(app: &mut VectorcraftApp) {
|
||||
cancel_brush_key_color(app, true);
|
||||
missing_fonts::requeue_replaced(app);
|
||||
// More Settings' pop-up and Save Preset end on their own; New Document stays.
|
||||
if app.ui.dialog.as_mut().is_some_and(new_document::close_popup) {
|
||||
@@ -827,6 +829,7 @@ pub(crate) fn reset(app: &mut VectorcraftApp) -> DialogResult {
|
||||
|
||||
/// Apply the open dialog (OK).
|
||||
pub fn confirm(app: &mut VectorcraftApp) -> DialogResult {
|
||||
cancel_brush_key_color(app, true);
|
||||
missing_fonts::requeue_replaced(app);
|
||||
let Some(d) = app.ui.dialog.clone() else { return Err("no dialog open".into()) };
|
||||
// A file dialog it shows off the UI thread confirms the dialog as it is again.
|
||||
@@ -867,6 +870,7 @@ pub(crate) fn opened_by_panel(app: &mut VectorcraftApp) {
|
||||
/// Draws the active dialog and handles shared initial focus, keyboard shortcuts and actions.
|
||||
/// Inline actions and footer buttons use the same confirmation and preview rollback paths.
|
||||
pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
refresh_brush_key_color(app);
|
||||
crate::shortcuts::hold_back_keys(app, ctx);
|
||||
about::show(app, ctx);
|
||||
settle(app);
|
||||
@@ -932,7 +936,8 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
let initial = if revolves { egui::vec2((ctx.content_rect().width() / 2.0 - 226.0).max(0.0), -40.0) } else { egui::vec2(0.0, -40.0) };
|
||||
let id = egui::Id::unique(("dialog", d.kind.as_str()));
|
||||
let id = if revolves { id.with("revolve") } else { id };
|
||||
modal::show_at(ctx, &heading, id, initial, MARGIN, |ui| {
|
||||
let canvas_pick = brush_key_color_canvas(app, ctx);
|
||||
modal::show_at(ctx, &heading, id, initial, MARGIN, canvas_pick, |ui| {
|
||||
// Never wider than the window (a large UI scale in a small window): the text wraps.
|
||||
let room = (ctx.content_rect().width() - 2.0 * (f32::from(MARGIN) + EDGE_GAP)).max(EDGE_GAP);
|
||||
ui.set_min_width(spec.min_width.min(room));
|
||||
|
||||
@@ -736,12 +736,130 @@ fn tile_doc(art: &Node, w: f64, h: f64) -> Option<Document> {
|
||||
Some(doc)
|
||||
}
|
||||
|
||||
/// The private dialog marker survives with its draft, never in the brush definition.
|
||||
const KEY_COLOR_DOC: &str = "__keyColorDoc";
|
||||
|
||||
fn key_color_owner_valid(app: &VectorcraftApp) -> bool {
|
||||
let Some(pick) = app.ui.brush_key_color_pick.as_ref() else { return false };
|
||||
app.session.active().is_some_and(|doc| doc.uid == pick.doc)
|
||||
&& app.ui.dialog.as_ref().is_some_and(|dialog| {
|
||||
dialog.kind == super::brush_options::KIND
|
||||
&& dialog.str("colorization") == "hueShift"
|
||||
&& dialog.fields.get(KEY_COLOR_DOC).and_then(Value::as_u64) == Some(pick.doc)
|
||||
})
|
||||
}
|
||||
|
||||
fn key_color_pick_active(app: &VectorcraftApp) -> bool {
|
||||
key_color_owner_valid(app) && app.session.tool_id() == "eyedropper" && app.session.tool_options()["brushKeyColor"] == true
|
||||
}
|
||||
|
||||
/// Only the owned Brush Options pick opens an input aperture; other modal owners still block it.
|
||||
pub(crate) fn brush_key_color_canvas(app: &VectorcraftApp, ctx: &egui::Context) -> Option<egui::Rect> {
|
||||
(key_color_pick_active(app)
|
||||
&& !app.ui.about
|
||||
&& !app.ui.palette_open
|
||||
&& !app.file_dialog_open()
|
||||
&& !crate::updates_ui::blocks_input(app)
|
||||
&& !egui::Popup::is_any_open(ctx))
|
||||
.then_some(app.canvas_rect)
|
||||
.flatten()
|
||||
}
|
||||
|
||||
/// Clear only the transient mode owned by this dialog, including a parked eyedropper.
|
||||
pub(crate) fn cancel_brush_key_color(app: &mut VectorcraftApp, restore: bool) {
|
||||
let Some(pick) = app.ui.brush_key_color_pick.take() else { return };
|
||||
let options = Map::from_iter([("brushKeyColor".into(), json!(false)), ("stop".into(), Value::Null)]);
|
||||
app.session.set_tool_options(Some("eyedropper"), &options);
|
||||
if restore && app.session.tool_id() == "eyedropper" {
|
||||
app.return_to_tool(&pick.back);
|
||||
}
|
||||
}
|
||||
|
||||
/// Refresh before real canvas input and dialog layout, so a stale press cannot reach another tool.
|
||||
pub(crate) fn refresh_brush_key_color(app: &mut VectorcraftApp) -> bool {
|
||||
if app.ui.brush_key_color_pick.is_none() || key_color_pick_active(app) {
|
||||
return false;
|
||||
}
|
||||
let restore = !key_color_owner_valid(app) && app.session.tool_id() == "eyedropper";
|
||||
cancel_brush_key_color(app, restore);
|
||||
true
|
||||
}
|
||||
|
||||
/// A foreground color click owns its physical Down/Up; the restored tool receives neither.
|
||||
pub(crate) fn brush_key_color_input(app: &mut VectorcraftApp, ui: &egui::Ui, response: &egui::Response, rect: egui::Rect) -> bool {
|
||||
if app.ui.brush_key_color_pick.is_none() {
|
||||
return false;
|
||||
}
|
||||
let (pointer, focused, lost) = ui.input(|input| {
|
||||
let up = input
|
||||
.events
|
||||
.iter()
|
||||
.position(|event| matches!(event, egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, .. }));
|
||||
let gone = input.events.iter().position(|event| matches!(event, egui::Event::PointerGone));
|
||||
let lost = gone.is_some_and(|gone| up.is_none_or(|up| gone < up))
|
||||
|| input.events.iter().any(|event| matches!(event, egui::Event::Touch { phase: egui::TouchPhase::Cancel, .. }))
|
||||
|| input.multi_touch().is_some()
|
||||
|| response.long_touched();
|
||||
(input.pointer.clone(), input.focused, lost)
|
||||
});
|
||||
let pending = app.ui.brush_key_color_pick.as_ref().is_some_and(|pick| pick.press.is_some());
|
||||
if pending && (!focused || lost || (!pointer.primary_down() && !pointer.primary_released())) {
|
||||
cancel_brush_key_color(app, true);
|
||||
return true;
|
||||
}
|
||||
if brush_key_color_canvas(app, ui.ctx()).is_none() {
|
||||
if let Some(pick) = app.ui.brush_key_color_pick.as_mut() {
|
||||
pick.press = None;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if !focused {
|
||||
return true;
|
||||
}
|
||||
if pointer.primary_pressed()
|
||||
&& response.hovered()
|
||||
&& let Some(point) = pointer.interact_pos().filter(|point| rect.contains(*point) && ui.clip_rect().contains(*point))
|
||||
{
|
||||
let xf = crate::canvas::Xf::at(rect, app.view().unwrap_or(&crate::View::default()), app.canvas_ui_zoom);
|
||||
if let Some(pick) = app.ui.brush_key_color_pick.as_mut() {
|
||||
pick.press = Some(xf.to_doc(point));
|
||||
}
|
||||
}
|
||||
if pointer.button_released(egui::PointerButton::Primary)
|
||||
&& let Some(point) = app.ui.brush_key_color_pick.as_mut().and_then(|pick| pick.press.take())
|
||||
{
|
||||
// The existing tool returns a deferred SwitchTool request. Release Eye before applying
|
||||
// that request, so a held color click cannot start or finish a stroke in the prior tool.
|
||||
let view = app.view_info();
|
||||
let down = vectorcraft_tools::PointerEvent::new(vectorcraft_tools::PointerKind::Down, point.x, point.y);
|
||||
let up = vectorcraft_tools::PointerEvent::new(vectorcraft_tools::PointerKind::Up, point.x, point.y);
|
||||
let sampled = app.session.pointer(&down, view);
|
||||
let released = app.session.pointer(&up, view);
|
||||
crate::canvas::apply_requests(app, sampled);
|
||||
crate::canvas::apply_requests(app, released);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Key Color eyedropper: sample the next click on the art into this dialog's `keyColor`.
|
||||
fn key_color_eyedropper(app: &mut VectorcraftApp) {
|
||||
let back = app.session.tool_id();
|
||||
app.select_tool("eyedropper");
|
||||
fn key_color_eyedropper(app: &mut VectorcraftApp, dialog: &mut Dialog) {
|
||||
if app.ui.brush_key_color_pick.is_some() {
|
||||
cancel_brush_key_color(app, true);
|
||||
return;
|
||||
}
|
||||
let Some(doc) = app.session.active().map(|doc| doc.uid) else { return };
|
||||
if dialog.fields.get(KEY_COLOR_DOC).and_then(Value::as_u64).is_some_and(|owner| owner != doc) {
|
||||
return;
|
||||
}
|
||||
let back = app.session.tool_id().to_string();
|
||||
if let Err(error) = app.try_select_tool("eyedropper") {
|
||||
app.status(error);
|
||||
return;
|
||||
}
|
||||
app.session.set_tool_option("brushKeyColor", &json!(true));
|
||||
app.session.set_tool_option("stop", &json!(back));
|
||||
dialog.fields.insert(KEY_COLOR_DOC.into(), json!(doc));
|
||||
app.ui.brush_key_color_pick = Some(crate::state::BrushKeyColorPick { doc, back, press: None });
|
||||
}
|
||||
|
||||
fn colorization_body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
@@ -779,7 +897,7 @@ fn colorization_body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog
|
||||
}
|
||||
}
|
||||
if widgets::icon_button(ui, "pipette", tl!("Eyedropper: click the art to sample the key color"), false, 22.0).clicked() {
|
||||
key_color_eyedropper(app);
|
||||
key_color_eyedropper(app, d);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -787,6 +905,17 @@ fn colorization_body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog
|
||||
|
||||
/// Apply a sampled colour to the open Brush Options dialog (`brushKeyColor` tool request).
|
||||
pub(super) fn apply_key_color_sample(app: &mut VectorcraftApp, color: &Value) {
|
||||
let marked = app.ui.dialog.as_ref().is_some_and(|dialog| dialog.fields.contains_key(KEY_COLOR_DOC));
|
||||
if app.ui.brush_key_color_pick.is_some() {
|
||||
if !key_color_owner_valid(app) {
|
||||
cancel_brush_key_color(app, false);
|
||||
return;
|
||||
}
|
||||
cancel_brush_key_color(app, false);
|
||||
} else if marked {
|
||||
// A reply cannot change the draft after its owned pick was cancelled or replaced.
|
||||
return;
|
||||
}
|
||||
let Some(d) = app.ui.dialog.as_mut().filter(|d| d.kind == super::brush_options::KIND) else { return };
|
||||
if d.str("colorization") != "hueShift" {
|
||||
return;
|
||||
|
||||
@@ -14,18 +14,44 @@ use crate::theme::{self, Tokens};
|
||||
/// screen's centre until it is moved, with `margin` inside its frame. `add` draws the contents and
|
||||
/// should start with [`heading`] (or [`drag_band`]) so the window can be moved.
|
||||
pub(crate) fn show<R>(ctx: &egui::Context, title: &str, id: Id, nudge: f32, margin: i8, add: impl FnOnce(&mut egui::Ui) -> R) -> Option<R> {
|
||||
show_at(ctx, title, id, egui::vec2(0.0, nudge), margin, add)
|
||||
show_at(ctx, title, id, egui::vec2(0.0, nudge), margin, None, add)
|
||||
}
|
||||
|
||||
/// A modal that starts at a chosen offset, then keeps the user's dragged position.
|
||||
pub(crate) fn show_at<R>(ctx: &egui::Context, title: &str, id: Id, initial: Vec2, margin: i8, add: impl FnOnce(&mut egui::Ui) -> R) -> Option<R> {
|
||||
pub(crate) fn show_at<R>(
|
||||
ctx: &egui::Context,
|
||||
title: &str,
|
||||
id: Id,
|
||||
initial: Vec2,
|
||||
margin: i8,
|
||||
canvas_pick: Option<Rect>,
|
||||
add: impl FnOnce(&mut egui::Ui) -> R,
|
||||
) -> Option<R> {
|
||||
let t = Tokens::get(ctx);
|
||||
let dim = backdrop();
|
||||
egui::Area::new(dim.id).order(dim.order).fixed_pos(egui::Pos2::ZERO).show(ctx, |ui| {
|
||||
// Modal, but the canvas isn't dimmed so previews stay readable (as in the reference app).
|
||||
// Not focusable (`Sense::click()` is): Tab goes through the dialog's controls, not the backdrop.
|
||||
ui.allocate_rect(ctx.content_rect(), egui::Sense::CLICK);
|
||||
});
|
||||
if let Some(canvas) = canvas_pick {
|
||||
let screen = ctx.content_rect();
|
||||
let canvas = canvas.intersect(screen);
|
||||
// Separate areas keep their hit rectangles outside the canvas. One area around a hole
|
||||
// would still cover the canvas with its enclosing rectangle.
|
||||
let regions = [
|
||||
Rect::from_min_max(screen.min, egui::pos2(screen.right(), canvas.top())),
|
||||
Rect::from_min_max(egui::pos2(screen.left(), canvas.top()), egui::pos2(canvas.left(), canvas.bottom())),
|
||||
Rect::from_min_max(egui::pos2(canvas.right(), canvas.top()), egui::pos2(screen.right(), canvas.bottom())),
|
||||
Rect::from_min_max(egui::pos2(screen.left(), canvas.bottom()), screen.max),
|
||||
];
|
||||
for (index, region) in regions.into_iter().enumerate().filter(|(_, region)| region.width() > 0.0 && region.height() > 0.0) {
|
||||
egui::Area::new(dim.id.with(index)).order(dim.order).fixed_pos(region.min).show(ctx, |ui| {
|
||||
ui.allocate_rect(region, egui::Sense::CLICK);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
egui::Area::new(dim.id).order(dim.order).fixed_pos(egui::Pos2::ZERO).show(ctx, |ui| {
|
||||
// Modal, but the canvas isn't dimmed so previews stay readable (as in the reference app).
|
||||
// Not focusable (`Sense::click()` is): Tab goes through the dialog's controls, not the backdrop.
|
||||
ui.allocate_rect(ctx.content_rect(), egui::Sense::CLICK);
|
||||
});
|
||||
}
|
||||
let opened = opened(ctx, id);
|
||||
let shown = egui::Window::new(title)
|
||||
.id(id)
|
||||
|
||||
@@ -3844,6 +3844,124 @@ fn color_halftones_max_radius_stays_in_pixels_whatever_the_units() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A real Key Color pick returns to its initiating tool when choosing its replacement fails.
|
||||
#[test]
|
||||
fn a_failed_tool_choice_restores_the_brush_key_color_initiator() {
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, RawInput, Rect, vec2};
|
||||
|
||||
fn full_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<Event>) -> egui::FullOutput {
|
||||
let mut raw =
|
||||
RawInput { events, focused: true, screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 1100.0))), ..Default::default() };
|
||||
app.raw_input_hook(ctx, &mut raw);
|
||||
let mut output = ctx.run_ui(raw, |ui| {
|
||||
app.tick(ui.ctx());
|
||||
app.ui(ui);
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
output
|
||||
}
|
||||
|
||||
fn arm(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
for _ in 0..4 {
|
||||
let _ = full_frame(app, ctx, vec![]);
|
||||
}
|
||||
let mut bounds = None;
|
||||
for _ in 0..8 {
|
||||
let output = full_frame(app, ctx, vec![]);
|
||||
bounds = output.platform_output.accesskit_update.as_ref().and_then(|update| {
|
||||
update
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|(_, node)| node.label() == Some("Eyedropper: click the art to sample the key color"))
|
||||
.and_then(|(_, node)| node.bounds())
|
||||
});
|
||||
if bounds.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let bounds = bounds.expect("the real Brush Options pipette button");
|
||||
let at = egui::pos2(((bounds.x0 + bounds.x1) * 0.5) as f32, ((bounds.y0 + bounds.y1) * 0.5) as f32);
|
||||
let _ = full_frame(app, ctx, vec![Event::ModifiersChanged(Modifiers::NONE), Event::PointerMoved(at)]);
|
||||
for pressed in [true, false] {
|
||||
let _ = full_frame(app, ctx, vec![Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }]);
|
||||
}
|
||||
assert_eq!(app.session.tool_id(), "eyedropper");
|
||||
let pick = app.ui.brush_key_color_pick.as_ref().expect("the button owns a live pick");
|
||||
assert_eq!(pick.back, "paintbrush");
|
||||
assert_eq!(pick.doc, app.session.active().unwrap().uid);
|
||||
assert!(pick.press.is_none());
|
||||
assert_eq!(app.session.tool_options()["brushKeyColor"], true);
|
||||
assert_eq!(app.session.tool_options()["stop"], "paintbrush");
|
||||
}
|
||||
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#000000"})).unwrap();
|
||||
let art = app.run("shape.rectangle", json!({"x": 300, "y": 30, "width": 20, "height": 12})).unwrap()["id"].clone();
|
||||
let brush = "Failed tool choice fixture";
|
||||
app.run(
|
||||
"brush.new",
|
||||
json!({"type": "art", "name": brush, "ids": [art],
|
||||
"params": {"colorization": {"method": "hueShift", "key": vectorcraft_color::Color::BLACK}}}),
|
||||
)
|
||||
.unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
app.select_tool("paintbrush");
|
||||
app.ui.task_bar = false;
|
||||
app.ui.view.rulers = false;
|
||||
app.canvas.worker_started = true;
|
||||
app.session.prefs.interface_language = "en".into();
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let ctx = egui::Context::default();
|
||||
ctx.enable_accesskit();
|
||||
app.run("ui.brushOptions", json!({"name": brush})).unwrap();
|
||||
arm(&mut app, &ctx);
|
||||
let unchanged = |app: &VectorcraftApp| {
|
||||
let state = app.session.active().unwrap();
|
||||
(
|
||||
json!({"uid": state.uid, "doc": state.doc, "selection": state.selection, "revision": state.revision,
|
||||
"undo": state.history.undo.len(), "redo": state.history.redo.len()}),
|
||||
app.session.paint.clone(),
|
||||
)
|
||||
};
|
||||
let before = unchanged(&app);
|
||||
let draft = app.ui.dialog.as_ref().unwrap().fields.clone();
|
||||
let group_tools = app.ui.group_tool.clone();
|
||||
let drawing_tool = app.ui.touch_drawing_tool.clone();
|
||||
|
||||
// The existing failure hook exercises a valid replacement, not an unknown tool id.
|
||||
app.fail_next_tool_choice = Some("key-color replacement failed".into());
|
||||
assert_eq!(app.try_select_tool("rectangle"), Err(String::from("key-color replacement failed")));
|
||||
assert!(app.fail_next_tool_choice.is_none());
|
||||
assert!(app.ui.brush_key_color_pick.is_none());
|
||||
assert_eq!(app.session.tool_options_of("eyedropper")["brushKeyColor"], false);
|
||||
assert!(app.session.tool_options_of("eyedropper")["stop"].is_null());
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().fields, draft);
|
||||
assert_eq!(app.ui.group_tool, group_tools);
|
||||
assert_eq!(app.ui.touch_drawing_tool, drawing_tool);
|
||||
assert_eq!(unchanged(&app), before);
|
||||
// Before the repair, all cleanup checks above pass, but the session stays on Eyedropper.
|
||||
assert_eq!(app.session.tool_id(), "paintbrush", "a failed replacement must restore the pick's initiating tool");
|
||||
|
||||
cancel(&mut app);
|
||||
assert!(app.ui.dialog.is_none());
|
||||
assert_eq!(app.session.tool_id(), "paintbrush", "Cancel cannot return an already consumed pick twice");
|
||||
assert_eq!(unchanged(&app), before);
|
||||
app.run("ui.brushOptions", json!({"name": brush})).unwrap();
|
||||
arm(&mut app, &ctx);
|
||||
app.try_select_tool("rectangle").unwrap();
|
||||
assert_eq!(app.session.tool_id(), "rectangle", "a successful replacement stays selected");
|
||||
assert!(app.ui.brush_key_color_pick.is_none());
|
||||
assert_eq!(app.session.tool_options_of("eyedropper")["brushKeyColor"], false);
|
||||
assert!(app.session.tool_options_of("eyedropper")["stop"].is_null());
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().fields, draft);
|
||||
assert_eq!(unchanged(&app), before);
|
||||
cancel(&mut app);
|
||||
assert!(app.ui.dialog.is_none());
|
||||
assert_eq!(app.session.tool_id(), "rectangle", "Cancel must preserve the successful replacement");
|
||||
assert_eq!(unchanged(&app), before);
|
||||
}
|
||||
|
||||
/// The resolution fields of Flatten Transparency, Document Raster Effects Settings, Effect ›
|
||||
/// Rasterize, the PNG options and the PDF save dialog's Compression section show their unit in the interface
|
||||
/// language (French "ppp"), as the `{n} ppi` row writes it.
|
||||
|
||||
@@ -3252,7 +3252,7 @@ mod tests {
|
||||
app.logic(ui.ctx());
|
||||
if progress {
|
||||
let id = egui::Id::unique("test-progress");
|
||||
crate::dialogs::modal::show_at(ui.ctx(), "Progress", id, egui::Vec2::ZERO, 12, |ui| ui.label("Working"));
|
||||
crate::dialogs::modal::show_at(ui.ctx(), "Progress", id, egui::Vec2::ZERO, 12, None, |ui| ui.label("Working"));
|
||||
}
|
||||
app.ui(ui);
|
||||
if let Some(at) = above {
|
||||
|
||||
@@ -6,6 +6,14 @@ use vectorcraft_geom::Point;
|
||||
|
||||
use crate::theme::Brightness;
|
||||
|
||||
/// A Brush Options Key Color click, owned by its dialog and document until release or cancel.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BrushKeyColorPick {
|
||||
pub doc: u64,
|
||||
pub back: String,
|
||||
pub press: Option<Point>,
|
||||
}
|
||||
|
||||
/// Per-document view (camera).
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub struct View {
|
||||
@@ -592,6 +600,8 @@ pub struct UiState {
|
||||
pub tab_hid: Option<TabHid>,
|
||||
pub view: ViewFlags,
|
||||
pub dialog: Option<Dialog>,
|
||||
#[serde(skip)]
|
||||
pub brush_key_color_pick: Option<BrushKeyColorPick>,
|
||||
/// Messages to show in a dialog once the open one is closed (`dialogs::confirm::tell`), in
|
||||
/// the order they came.
|
||||
#[serde(skip)]
|
||||
@@ -1274,6 +1284,7 @@ impl Default for UiState {
|
||||
tab_hid: None,
|
||||
view: ViewFlags::default(),
|
||||
dialog: None,
|
||||
brush_key_color_pick: None,
|
||||
told: vec![],
|
||||
answering_control: false,
|
||||
flyout: None,
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
//! Regression coverage for Brush Options Key Color sampling through the real modal canvas route.
|
||||
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
||||
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, RawInput, Rect, vec2};
|
||||
use serde_json::json;
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_engine::Session;
|
||||
use vectorcraft_geom::Point;
|
||||
use vectorcraft_tools::{PointerEvent, PointerKind};
|
||||
use vectorcraft_ui_egui::{VectorcraftApp, canvas};
|
||||
|
||||
const BRUSH: &str = "Original key-color fixture";
|
||||
const PICK_KEY: &str = "Eyedropper: click the art to sample the key color";
|
||||
|
||||
fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec<Event>) -> egui::FullOutput {
|
||||
let mut raw = RawInput { events, focused: true, screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 1100.0))), ..Default::default() };
|
||||
app.raw_input_hook(ctx, &mut raw);
|
||||
ctx.run_ui(raw, |ui| {
|
||||
app.tick(ui.ctx());
|
||||
app.ui(ui);
|
||||
})
|
||||
}
|
||||
|
||||
fn settle(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
for _ in 0..4 {
|
||||
frame(app, ctx, vec![]).textures_delta.clear();
|
||||
}
|
||||
}
|
||||
|
||||
fn click_at(app: &mut VectorcraftApp, ctx: &egui::Context, at: Pos2, modifiers: Modifiers) {
|
||||
let press = |pressed| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers };
|
||||
frame(app, ctx, vec![Event::ModifiersChanged(modifiers), Event::PointerMoved(at)]).textures_delta.clear();
|
||||
frame(app, ctx, vec![press(true)]).textures_delta.clear();
|
||||
frame(app, ctx, vec![press(false)]).textures_delta.clear();
|
||||
frame(app, ctx, vec![Event::ModifiersChanged(Modifiers::NONE)]).textures_delta.clear();
|
||||
}
|
||||
|
||||
fn click_control(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) {
|
||||
let mut bounds = None;
|
||||
for _ in 0..3 {
|
||||
let mut output = frame(app, ctx, vec![]);
|
||||
if let Some(update) = &output.platform_output.accesskit_update {
|
||||
bounds = update.nodes.iter().find(|(_, node)| node.label() == Some(label)).and_then(|(_, node)| node.bounds());
|
||||
}
|
||||
output.textures_delta.clear();
|
||||
if bounds.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let bounds = bounds.unwrap_or_else(|| panic!("missing actual Brush Options control: {label}"));
|
||||
let at = egui::pos2(((bounds.x0 + bounds.x1) * 0.5) as f32, ((bounds.y0 + bounds.y1) * 0.5) as f32);
|
||||
click_at(app, ctx, at, Modifiers::NONE);
|
||||
settle(app, ctx);
|
||||
}
|
||||
|
||||
fn key_color(app: &VectorcraftApp) -> Color {
|
||||
let dialog = app.ui.dialog.as_ref().expect("Brush Options remains open");
|
||||
assert_eq!(dialog.kind, "brushOptions");
|
||||
assert_eq!(dialog.fields.get("colorization"), Some(&json!("hueShift")));
|
||||
vectorcraft_engine::cmd::color_value(dialog.fields.get("keyColor").expect("Key Color field")).unwrap()
|
||||
}
|
||||
|
||||
fn open_options(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
app.run("ui.brushOptions", json!({"name": BRUSH})).unwrap();
|
||||
settle(app, ctx);
|
||||
assert_eq!(key_color(app), Color::BLACK, "the original brush has a black key, distinct from the blue canvas sample");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_color_sampling_reaches_the_canvas_while_brush_options_stays_open() {
|
||||
vectorcraft_ui_egui::i18n::set_current(vectorcraft_ui_egui::i18n::Lang::EN);
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#000000"})).unwrap();
|
||||
let art = app.run("shape.rectangle", json!({"x": 300, "y": 30, "width": 20, "height": 12})).unwrap()["id"].clone();
|
||||
app.run(
|
||||
"brush.new",
|
||||
json!({"type": "art", "name": BRUSH, "ids": [art], "params": {"colorization": {"method": "hueShift", "key": Color::BLACK}}}),
|
||||
)
|
||||
.unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#336699"})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 20, "y": 120, "width": 80, "height": 60})).unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
app.ui.task_bar = false;
|
||||
app.ui.view.rulers = false;
|
||||
app.canvas.worker_started = true;
|
||||
let ctx = egui::Context::default();
|
||||
ctx.enable_accesskit();
|
||||
for _ in 0..8 {
|
||||
frame(&mut app, &ctx, vec![]).textures_delta.clear();
|
||||
}
|
||||
let view = app.view_mut().unwrap();
|
||||
view.zoom = 3.0;
|
||||
view.center = Point::new(200.0, 150.0);
|
||||
view.rotation = 0.0;
|
||||
settle(&mut app, &ctx);
|
||||
let point = Point::new(60.0, 150.0);
|
||||
let at = canvas::Xf::at(app.canvas_rect.unwrap(), app.view().unwrap(), ctx.zoom_factor()).to_screen(point);
|
||||
assert!(app.canvas_rect.unwrap().contains(at));
|
||||
|
||||
// Positive control: this exact coordinate is colored art and the ordinary real UI route hits it.
|
||||
let control_document = app.session.active().unwrap().doc.clone();
|
||||
app.run("paint.setFill", json!({"color": "#e020c0"})).unwrap();
|
||||
app.select_tool("eyedropper");
|
||||
click_at(&mut app, &ctx, at, Modifiers::SHIFT);
|
||||
let expected_key = match &app.session.paint.fill {
|
||||
Paint::Solid { color, .. } => *color,
|
||||
_ => panic!("ordinary Eye sampled a solid color"),
|
||||
};
|
||||
assert_eq!(expected_key.to_hex(), "#336699", "ordinary real UI Eyedropper hits the sample point");
|
||||
assert_eq!(app.session.active().unwrap().doc, control_document);
|
||||
assert!(app.session.active().unwrap().selection.objects.is_empty());
|
||||
app.run("paint.setFill", json!({"color": "#e020c0"})).unwrap();
|
||||
app.select_tool("paintbrush");
|
||||
let state = app.session.active().unwrap();
|
||||
let (document, selection, revision) = (state.doc.clone(), state.selection.clone(), state.revision);
|
||||
let history = (state.history.undo.len(), state.history.redo.len());
|
||||
let paint = app.session.paint.clone();
|
||||
let unchanged = |app: &VectorcraftApp| {
|
||||
let state = app.session.active().unwrap();
|
||||
assert_eq!(state.doc, document);
|
||||
assert_eq!(state.selection, selection);
|
||||
assert_eq!(state.revision, revision);
|
||||
assert_eq!((state.history.undo.len(), state.history.redo.len()), history);
|
||||
assert_eq!(app.session.paint, paint);
|
||||
};
|
||||
|
||||
// Separate callback control, not the failure witness: the existing tool-to-dialog route works.
|
||||
open_options(&mut app, &ctx);
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
assert_eq!(app.session.tool_id(), "eyedropper");
|
||||
assert_eq!(app.session.tool_options()["brushKeyColor"], true);
|
||||
let view = app.view_info();
|
||||
canvas::dispatch(&mut app, &PointerEvent::new(PointerKind::Down, point.x, point.y), view);
|
||||
settle(&mut app, &ctx);
|
||||
assert_eq!(key_color(&app), expected_key, "the callback can update this hue-shift dialog");
|
||||
assert_eq!(app.session.tool_id(), "paintbrush");
|
||||
unchanged(&app);
|
||||
click_control(&mut app, &ctx, "Cancel");
|
||||
assert!(app.ui.dialog.is_none());
|
||||
unchanged(&app);
|
||||
|
||||
// Reopen from the unchanged brush so the real canvas witness starts with the original black key.
|
||||
open_options(&mut app, &ctx);
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
assert_eq!(app.session.tool_id(), "eyedropper");
|
||||
assert_eq!(app.session.tool_options()["brushKeyColor"], true);
|
||||
assert_eq!(app.session.tool_options()["stop"], "paintbrush");
|
||||
let fields = app.ui.dialog.as_ref().unwrap().fields.clone();
|
||||
let modal = ctx.memory(|memory| memory.area_rect(egui::Id::unique(("dialog", "brushOptions")))).expect("the real Brush Options window bounds");
|
||||
let now = canvas::Xf::at(app.canvas_rect.unwrap(), app.view().unwrap(), ctx.zoom_factor()).to_screen(point);
|
||||
assert!(now.distance(at) < 0.1, "the control and witness use the same canvas coordinate");
|
||||
assert!(!modal.contains(at), "sample visible art outside the dialog body, not a covered control");
|
||||
unchanged(&app);
|
||||
click_at(&mut app, &ctx, at, Modifiers::NONE);
|
||||
settle(&mut app, &ctx);
|
||||
unchanged(&app);
|
||||
let actual_key = key_color(&app);
|
||||
assert_eq!(actual_key, expected_key, "the armed Key Color eyedropper must receive the real canvas click through the retained dialog");
|
||||
let mut expected_fields = fields;
|
||||
expected_fields.insert("keyColor".into(), serde_json::to_value(expected_key).unwrap());
|
||||
assert_eq!(app.ui.dialog.as_ref().unwrap().fields, expected_fields, "only the dialog Key Color changes");
|
||||
assert_eq!(app.session.tool_id(), "paintbrush");
|
||||
assert_eq!(app.session.tool_options_of("eyedropper")["brushKeyColor"], false);
|
||||
}
|
||||
|
||||
// Additional controls are appended; the independently reproduced witness above is unchanged.
|
||||
fn modal_fixture() -> (VectorcraftApp, egui::Context, Pos2) {
|
||||
vectorcraft_ui_egui::i18n::set_current(vectorcraft_ui_egui::i18n::Lang::EN);
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#000000"})).unwrap();
|
||||
let art = app.run("shape.rectangle", json!({"x": 300, "y": 30, "width": 20, "height": 12})).unwrap()["id"].clone();
|
||||
app.run(
|
||||
"brush.new",
|
||||
json!({"type": "art", "name": BRUSH, "ids": [art], "params": {"colorization": {"method": "hueShift", "key": Color::BLACK}}}),
|
||||
)
|
||||
.unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#336699"})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 20, "y": 120, "width": 80, "height": 60})).unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
app.ui.task_bar = false;
|
||||
app.ui.view.rulers = false;
|
||||
app.canvas.worker_started = true;
|
||||
let ctx = egui::Context::default();
|
||||
ctx.enable_accesskit();
|
||||
for _ in 0..8 {
|
||||
frame(&mut app, &ctx, vec![]).textures_delta.clear();
|
||||
}
|
||||
let view = app.view_mut().unwrap();
|
||||
view.zoom = 3.0;
|
||||
view.center = Point::new(200.0, 150.0);
|
||||
view.rotation = 0.0;
|
||||
settle(&mut app, &ctx);
|
||||
let at = canvas::Xf::at(app.canvas_rect.unwrap(), app.view().unwrap(), ctx.zoom_factor()).to_screen(Point::new(60.0, 150.0));
|
||||
app.run("paint.setFill", json!({"color": "#e020c0"})).unwrap();
|
||||
app.select_tool("paintbrush");
|
||||
open_options(&mut app, &ctx);
|
||||
let modal = ctx.memory(|memory| memory.area_rect(egui::Id::unique(("dialog", "brushOptions")))).unwrap();
|
||||
assert!(app.canvas_rect.unwrap().contains(at) && !modal.contains(at));
|
||||
(app, ctx, at)
|
||||
}
|
||||
|
||||
fn document_defaults(app: &VectorcraftApp) -> (serde_json::Value, vectorcraft_tools::PaintDefaults) {
|
||||
let state = app.session.active().unwrap();
|
||||
(
|
||||
json!({"document": state.doc, "selection": state.selection, "revision": state.revision,
|
||||
"undo": state.history.undo.len(), "redo": state.history.redo.len()}),
|
||||
app.session.paint.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
fn escape(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
for pressed in [true, false] {
|
||||
frame(
|
||||
app,
|
||||
ctx,
|
||||
vec![
|
||||
Event::ModifiersChanged(Modifiers::NONE),
|
||||
Event::Key { key: egui::Key::Escape, physical_key: Some(egui::Key::Escape), pressed, repeat: false, modifiers: Modifiers::NONE },
|
||||
],
|
||||
)
|
||||
.textures_delta
|
||||
.clear();
|
||||
}
|
||||
settle(app, ctx);
|
||||
}
|
||||
|
||||
fn sample_press(app: &mut VectorcraftApp, ctx: &egui::Context, at: Pos2, modifiers: Modifiers) {
|
||||
frame(app, ctx, vec![Event::ModifiersChanged(modifiers), Event::PointerMoved(at)]).textures_delta.clear();
|
||||
frame(app, ctx, vec![Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: true, modifiers }]).textures_delta.clear();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unarmed_brush_and_other_modal_keep_blocking_canvas_input() {
|
||||
for other_modal in [false, true] {
|
||||
let (mut app, ctx, at) = modal_fixture();
|
||||
if other_modal {
|
||||
click_control(&mut app, &ctx, "Cancel");
|
||||
app.run("ui.newBrush", json!({})).unwrap();
|
||||
settle(&mut app, &ctx);
|
||||
}
|
||||
app.select_tool("eyedropper");
|
||||
let before = document_defaults(&app);
|
||||
click_at(&mut app, &ctx, at, Modifiers::SHIFT);
|
||||
settle(&mut app, &ctx);
|
||||
assert_eq!(document_defaults(&app), before, "an unarmed modal must still block the same canvas point");
|
||||
if !other_modal {
|
||||
assert_eq!(key_color(&app), Color::BLACK);
|
||||
}
|
||||
click_control(&mut app, &ctx, "Cancel");
|
||||
assert!(app.ui.dialog.is_none());
|
||||
click_at(&mut app, &ctx, at, Modifiers::SHIFT);
|
||||
match &app.session.paint.fill {
|
||||
Paint::Solid { color, .. } => assert_eq!(color.to_hex(), "#336699", "the same point works after the modal closes"),
|
||||
_ => panic!("ordinary Eye returns a solid color"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_color_reentry_escape_cancel_and_tool_choice_restore_only_the_owned_pick() {
|
||||
let (mut app, ctx, _) = modal_fixture();
|
||||
let before = document_defaults(&app);
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
assert_eq!(app.session.tool_options()["stop"], "paintbrush");
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
assert_eq!(app.session.tool_id(), "paintbrush", "reentry must not capture Eye as its own return tool");
|
||||
assert_eq!(key_color(&app), Color::BLACK);
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
escape(&mut app, &ctx);
|
||||
assert_eq!(app.session.tool_id(), "paintbrush");
|
||||
assert_eq!(key_color(&app), Color::BLACK, "the first Escape ends sampling and keeps the draft");
|
||||
escape(&mut app, &ctx);
|
||||
assert!(app.ui.dialog.is_none(), "the second Escape closes Brush Options");
|
||||
open_options(&mut app, &ctx);
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
click_control(&mut app, &ctx, "Cancel");
|
||||
assert_eq!(app.session.tool_id(), "paintbrush");
|
||||
assert!(app.ui.dialog.is_none());
|
||||
open_options(&mut app, &ctx);
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
app.select_tool("rectangle");
|
||||
settle(&mut app, &ctx);
|
||||
assert_eq!(app.session.tool_id(), "rectangle", "an explicit choice wins over automatic restoration");
|
||||
assert_eq!(key_color(&app), Color::BLACK);
|
||||
assert_eq!(document_defaults(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_color_release_samples_once_without_lending_or_sending_up_to_paintbrush() {
|
||||
let (mut app, ctx, at) = modal_fixture();
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
let before = document_defaults(&app);
|
||||
let inputs = app.session.input_count();
|
||||
let modifiers = Modifiers { ctrl: true, command: true, ..Modifiers::NONE };
|
||||
sample_press(&mut app, &ctx, at, modifiers);
|
||||
assert_eq!(app.session.tool_id(), "eyedropper", "Cmd/Ctrl must not lend Selection in this foreground pick");
|
||||
assert_eq!(app.session.input_count(), inputs, "the physical Down is retained until its release");
|
||||
assert_eq!(key_color(&app), Color::BLACK);
|
||||
frame(&mut app, &ctx, vec![Event::PointerMoved(at + vec2(2.0, 0.0))]).textures_delta.clear();
|
||||
assert_eq!(app.session.input_count(), inputs, "holding/moving the pick must not start a stroke");
|
||||
frame(&mut app, &ctx, vec![Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers }]).textures_delta.clear();
|
||||
assert_eq!(app.session.input_count(), inputs + 2, "only the existing Eye Down and Eye Up reach Session");
|
||||
assert_eq!(app.session.tool_id(), "paintbrush");
|
||||
assert!(!app.session.pointer_held());
|
||||
assert!(!app.session.in_interaction());
|
||||
assert_eq!(key_color(&app).to_hex(), "#336699");
|
||||
assert_eq!(document_defaults(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_color_lost_press_or_replaced_target_cannot_commit_on_a_later_up() {
|
||||
for exit in ["focus", "pointerGone", "dialog", "document"] {
|
||||
let (mut app, ctx, at) = modal_fixture();
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
sample_press(&mut app, &ctx, at, Modifiers::NONE);
|
||||
assert_eq!(key_color(&app), Color::BLACK);
|
||||
match exit {
|
||||
"focus" => {
|
||||
let mut raw =
|
||||
RawInput { focused: false, screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 1100.0))), ..Default::default() };
|
||||
app.raw_input_hook(&ctx, &mut raw);
|
||||
ctx.run_ui(raw, |ui| {
|
||||
app.tick(ui.ctx());
|
||||
app.ui(ui);
|
||||
})
|
||||
.textures_delta
|
||||
.clear();
|
||||
}
|
||||
"pointerGone" => {
|
||||
frame(&mut app, &ctx, vec![Event::PointerGone]).textures_delta.clear();
|
||||
}
|
||||
"dialog" => {
|
||||
app.run("ui.brushOptions", json!({"name": BRUSH})).unwrap();
|
||||
}
|
||||
"document" => {
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
}
|
||||
_ => panic!("unexpected test exit: {exit}"),
|
||||
}
|
||||
settle(&mut app, &ctx);
|
||||
assert_eq!(app.session.tool_id(), "paintbrush", "{exit}: invalidated picks restore the original tool");
|
||||
let before = document_defaults(&app);
|
||||
let fields = app.ui.dialog.as_ref().map(|dialog| dialog.fields.clone());
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![
|
||||
Event::PointerMoved(at),
|
||||
Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE },
|
||||
],
|
||||
)
|
||||
.textures_delta
|
||||
.clear();
|
||||
settle(&mut app, &ctx);
|
||||
assert_eq!(document_defaults(&app), before, "{exit}: an unrelated Up cannot commit a ghost sample or stroke");
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|dialog| dialog.fields.clone()), fields, "{exit}: no late callback changes the draft");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_color_ok_saves_the_sampled_brush_key_and_reopened_cancel_preserves_it() {
|
||||
let (mut app, ctx, at) = modal_fixture();
|
||||
let before = document_defaults(&app);
|
||||
let selection = app.session.active().unwrap().selection.clone();
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
click_control(&mut app, &ctx, PICK_KEY);
|
||||
click_at(&mut app, &ctx, at, Modifiers::NONE);
|
||||
settle(&mut app, &ctx);
|
||||
assert_eq!(key_color(&app).to_hex(), "#336699");
|
||||
assert_eq!(app.session.tool_id(), "paintbrush");
|
||||
assert_eq!(document_defaults(&app), before, "sampling changes only the dialog draft before OK");
|
||||
|
||||
click_control(&mut app, &ctx, "OK");
|
||||
assert!(app.ui.dialog.is_none(), "the actual OK button commits and closes Brush Options");
|
||||
let state = app.session.active().unwrap();
|
||||
assert_eq!(state.selection, selection);
|
||||
assert_eq!(state.history.undo.len(), undo + 1, "saving the changed brush definition is one Brush Options edit");
|
||||
assert!(state.history.redo.is_empty());
|
||||
assert_eq!(app.session.paint, before.1, "OK does not change the default paints");
|
||||
|
||||
// Open from the saved brush, rather than the black-key fixture helper.
|
||||
app.run("ui.brushOptions", json!({"name": BRUSH})).unwrap();
|
||||
settle(&mut app, &ctx);
|
||||
assert_eq!(key_color(&app).to_hex(), "#336699", "reopening reads the sampled key saved by OK");
|
||||
let saved = document_defaults(&app);
|
||||
click_control(&mut app, &ctx, "Cancel");
|
||||
assert!(app.ui.dialog.is_none());
|
||||
assert_eq!(document_defaults(&app), saved, "Cancel leaves the stored definition, history and default paints intact");
|
||||
app.run("ui.brushOptions", json!({"name": BRUSH})).unwrap();
|
||||
settle(&mut app, &ctx);
|
||||
assert_eq!(key_color(&app).to_hex(), "#336699", "Cancel preserves the stored sampled key");
|
||||
assert_eq!(document_defaults(&app), saved);
|
||||
}
|
||||
+2
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user