mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 10:13:09 -06:00
Merge branch 'port/deckcraft/red/app-r6-3' into port/deckcraft/area/app
This commit is contained in:
@@ -288,13 +288,14 @@ fn host_close_prompt_keeps_the_presentation_when_the_save_fails() {
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::W);
|
||||
h.run_steps(3);
|
||||
assert!(close_prompt_open(&h));
|
||||
h.get_by_role_and_label(Role::Button, "Save").click();
|
||||
// The window's own Save stays in the tree behind the prompt, hidden and disabled.
|
||||
h.get_by_role(Role::AlertDialog).get_by_role_and_label(Role::Button, "Save").click();
|
||||
h.run_steps(4);
|
||||
if fail {
|
||||
assert_eq!(h.state().session.documents().len(), 1);
|
||||
assert!(h.state().session.active().unwrap().is_dirty());
|
||||
assert!(close_prompt_open(&h));
|
||||
assert!(h.query_by_label_contains(reason).is_some());
|
||||
assert!(h.get_by_role(Role::AlertDialog).query_all_by_label_contains(reason).next().is_some(), "the prompt says why");
|
||||
} else {
|
||||
assert!(h.state().session.documents().is_empty());
|
||||
assert!(crate::dialogs::open_keys(&h.ctx).is_empty());
|
||||
@@ -495,8 +496,9 @@ fn a_file_that_cant_be_opened_says_why() {
|
||||
page_choice(&h, "Browse").click();
|
||||
wait_for_open(&mut h);
|
||||
assert!(h.state().session.documents().is_empty());
|
||||
let view = h.get_by_role_and_label(Role::Group, "File view");
|
||||
assert!(view.query_all_by_label_contains(&reason).any(|node| !in_navigation(&node)), "the read failure is visible on the page");
|
||||
// The page stays, with the reason in the window's notice over it.
|
||||
assert!(h.query_by_role_and_label(Role::Group, "File view").is_some(), "the File view stays");
|
||||
assert!(h.query_all_by_label_contains(&reason).any(|node| !in_navigation(&node)), "the read failure is visible over the page");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -63,6 +63,7 @@ pub(crate) fn show(app: &mut SlideApp, ui: &mut Ui) {
|
||||
};
|
||||
let strips = (app.ui.ruler && !app.anim_preview_active()).then(|| rulers::rulers(app)).flatten();
|
||||
let canvas_id = ui.scope_id().with("slide_canvas");
|
||||
let strips_clip = ui.clip_rect().intersect(room);
|
||||
let mut canvas = Canvas::new(Word::plain("Slide canvas"))
|
||||
.id(canvas_id)
|
||||
.document(ViewTarget::new(size).fit_ceiling(scheme.max_device()))
|
||||
@@ -96,7 +97,7 @@ pub(crate) fn show(app: &mut SlideApp, ui: &mut Ui) {
|
||||
guides::show_guides(app, ui, &space, canvas_id);
|
||||
handles::show(app, ui, &space);
|
||||
ask = text_host::show_editor(app, ui, &space).and_then(|output| output.context);
|
||||
rulers::show_text_ruler(app, ui, &space, room);
|
||||
rulers::show_text_ruler(app, ui, &space, room, strips_clip);
|
||||
squiggles::show_marks(app, ui, &space);
|
||||
media::show_controls(app, ui, &space);
|
||||
// PLAN: assumed pub(super) fn slide_gifs(app: &mut SlideApp, now: f64) -> Vec<crate::media::Gif> (canvas-w7)
|
||||
|
||||
@@ -27,8 +27,9 @@ pub(crate) fn rulers(app: &SlideApp) -> Option<Rulers<'static>> {
|
||||
app.ui.ruler.then(|| Rulers::new("Rulers", Bind::given(Point::ZERO)).origin_locked(true).interactive(false))
|
||||
}
|
||||
|
||||
/// Hosts the paragraph ruler over the full canvas's top strip, outside the clipped picture body.
|
||||
pub(crate) fn show_text_ruler(app: &mut SlideApp, ui: &mut egui::Ui, space: &CanvasSpace, full: egui::Rect) {
|
||||
/// Hosts the paragraph ruler over the full canvas's top strip. The body is clipped to the view inside the strips, so
|
||||
/// the ruler shows with the clip opened over the canvas again (`strips_clip`), where it takes its own presses.
|
||||
pub(crate) fn show_text_ruler(app: &mut SlideApp, ui: &mut egui::Ui, space: &CanvasSpace, full: egui::Rect, strips_clip: egui::Rect) {
|
||||
if !app.ui.ruler || app.session.active().is_none_or(|st| st.selection.text.is_none()) {
|
||||
return;
|
||||
}
|
||||
@@ -51,6 +52,8 @@ pub(crate) fn show_text_ruler(app: &mut SlideApp, ui: &mut egui::Ui, space: &Can
|
||||
.collect();
|
||||
let (top, _, corner) = Rulers::strips(ui, full);
|
||||
let unit = app.session.prefs.units;
|
||||
let body_clip = ui.clip_rect();
|
||||
ui.set_clip_rect(strips_clip);
|
||||
let output = TextRuler::new("Text ruler", Bind::given(values.clone()), number("width") as f32)
|
||||
.model(ParagraphModel::TextBox)
|
||||
.corner(corner)
|
||||
@@ -59,6 +62,7 @@ pub(crate) fn show_text_ruler(app: &mut SlideApp, ui: &mut egui::Ui, space: &Can
|
||||
.unit(DocUnit::new(ruler_text(unit).kind, UnitKind::POINTS_PER_INCH / Unit::Pixels.points_per_unit()))
|
||||
.kind(app.ruler_tab_kind)
|
||||
.show_at(ui, top.union(corner));
|
||||
ui.set_clip_rect(body_clip);
|
||||
if let Some(kind) = output.kind {
|
||||
app.ruler_tab_kind = kind;
|
||||
}
|
||||
|
||||
@@ -375,17 +375,19 @@ fn document_bounds(points: [deckcraft_geom::Point; 4], transform: Affine) -> Rec
|
||||
}
|
||||
|
||||
/// Hosts the edited shape or cell while no dialog, palette, File view, opening overlay or other text field owns input.
|
||||
/// The editor takes keyboard focus in the first pass it is shown, and again after a pass without it.
|
||||
/// The editor takes keyboard focus in the first pass it is shown, and again after a pass without it, including
|
||||
/// frames in which the canvas was not laid out at all (the File view replaces it).
|
||||
pub(crate) fn show_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &CanvasSpace) -> Option<TextEditorOutput> {
|
||||
let shown = egui::Id::new("slide-text-editor-shown");
|
||||
let hosted = ui.data(|data| data.get_temp::<egui::Id>(shown));
|
||||
let frame = ui.ctx().cumulative_frame_nr();
|
||||
let hosted = ui.data(|data| data.get_temp::<(egui::Id, u64)>(shown)).filter(|(_, at)| at + 1 >= frame).map(|(id, _)| id);
|
||||
let blocked = crate::dialogs::modal_open(ui.ctx()) || app.palette_open || app.backstage_open() || app.opening.is_some();
|
||||
let target = app.session.active().and_then(|state| {
|
||||
let target = state.selection.text.as_ref().filter(|target| !target.notes)?;
|
||||
Some((state.uid, target.clone()))
|
||||
});
|
||||
let (Some((uid, target)), false) = (target, blocked) else {
|
||||
ui.data_mut(|data| data.remove::<egui::Id>(shown));
|
||||
ui.data_mut(|data| data.remove::<(egui::Id, u64)>(shown));
|
||||
return None;
|
||||
};
|
||||
let id = ui.make_persistent_id(("slide-text-editor", uid, target.shape, target.cell));
|
||||
@@ -403,7 +405,7 @@ pub(crate) fn show_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &Canvas
|
||||
if hosted != Some(id) {
|
||||
editor = editor.request_focus(FocusRequest::Take);
|
||||
}
|
||||
ui.data_mut(|data| data.insert_temp(shown, id));
|
||||
ui.data_mut(|data| data.insert_temp(shown, (id, frame)));
|
||||
let output = if app.caret_blink == Some(false) {
|
||||
with_env(ui, |env| env.motion = Some(MotionMode::Off), |ui| editor.show_at(ui, bounds))
|
||||
} else {
|
||||
|
||||
@@ -7,7 +7,7 @@ use egui::accesskit::Role;
|
||||
use egui::epaint::Shape;
|
||||
use egui::{Color32, Rect, Stroke};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use egui_kittest::kittest::{NodeT as _, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{Services, SlideApp};
|
||||
@@ -29,27 +29,58 @@ fn distance(a: Color32, b: Color32) -> u8 {
|
||||
a.r().abs_diff(b.r()).max(a.g().abs_diff(b.g())).max(a.b().abs_diff(b.b()))
|
||||
}
|
||||
|
||||
/// The frame painted for the text field at `field` (its fill and outline): of the rectangles laid
|
||||
/// exactly over it (a field's layers may include an unpainted one) the one that stands apart from
|
||||
/// `surface`, else the first.
|
||||
/// Every rectangle painted, with those nested in shape lists (a field paints its fill and outline as one list).
|
||||
fn painted_rects(shapes: &[Shape], out: &mut Vec<egui::epaint::RectShape>) {
|
||||
for shape in shapes {
|
||||
match shape {
|
||||
Shape::Rect(r) => out.push(r.clone()),
|
||||
Shape::Vec(nested) => painted_rects(nested, out),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The frame painted for the text field at `field` (its fill and outline): of the rectangles round
|
||||
/// it, no more than twice its size (a combo box's frame also holds its drop-down button; a field's
|
||||
/// layers may include an unpainted one), the one that stands apart from `surface`, else the smallest.
|
||||
fn frame_at(h: &Harness<'_, SlideApp>, field: Rect, surface: Color32) -> (Color32, Stroke) {
|
||||
let frames: Vec<(Color32, Stroke)> = h
|
||||
.output()
|
||||
.shapes
|
||||
.iter()
|
||||
.filter_map(|c| match &c.shape {
|
||||
Shape::Rect(r) if r.rect.min.distance(field.min) < 2.0 && r.rect.max.distance(field.max) < 2.0 => Some((r.fill, r.stroke)),
|
||||
_ => None,
|
||||
})
|
||||
let shapes: Vec<Shape> = h.output().shapes.iter().map(|c| c.shape.clone()).collect();
|
||||
let mut rects = Vec::new();
|
||||
painted_rects(&shapes, &mut rects);
|
||||
let mut frames: Vec<(Rect, Color32, Stroke)> = rects
|
||||
.into_iter()
|
||||
.filter(|r| r.rect.expand(2.0).contains_rect(field) && r.rect.width() <= field.width() * 2.0 && r.rect.height() <= field.height() * 2.0)
|
||||
.map(|r| (r.rect, r.fill, r.stroke))
|
||||
.collect();
|
||||
frames.sort_by(|a, b| a.0.area().total_cmp(&b.0.area()));
|
||||
frames
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|(_, fill, stroke)| (*fill, *stroke))
|
||||
.find(|(fill, stroke)| stands_apart(*fill, *stroke, surface))
|
||||
.or_else(|| frames.first().copied())
|
||||
.or_else(|| frames.first().map(|(_, fill, stroke)| (*fill, *stroke)))
|
||||
.unwrap_or_else(|| panic!("no frame painted for the field at {field:?}"))
|
||||
}
|
||||
|
||||
/// Whether `node` lies inside the group or dialog named `label`.
|
||||
fn within(node: &egui_kittest::Node<'_>, label: &str) -> bool {
|
||||
let mut parent = node.parent();
|
||||
while let Some(node) = parent {
|
||||
if node.accesskit_node().label().as_deref() == Some(label) {
|
||||
return true;
|
||||
}
|
||||
parent = node.parent();
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// The text fields on one surface: those inside `inside` when given, and none inside `outside`.
|
||||
fn fields_on(h: &Harness<'_, SlideApp>, inside: Option<&str>, outside: &[&str]) -> Vec<Rect> {
|
||||
h.query_all_by_role(Role::TextInput)
|
||||
.filter(|node| inside.is_none_or(|label| within(node, label)) && !outside.iter().any(|label| within(node, label)))
|
||||
.map(|node| node.rect())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// What `c` shows when painted over the opaque `surface`. `Color32` is premultiplied, so each
|
||||
/// channel is `c + surface * (255 - alpha) / 255`.
|
||||
fn over(c: Color32, surface: Color32) -> Color32 {
|
||||
@@ -64,9 +95,8 @@ fn stands_apart(fill: Color32, stroke: Stroke, surface: Color32) -> bool {
|
||||
outlined || distance(over(fill, surface), surface) >= 16
|
||||
}
|
||||
|
||||
/// The field stands apart from `surface` by its fill or by its outline.
|
||||
fn assert_visible(h: &Harness<'_, SlideApp>, what: &str, surface: Color32) {
|
||||
let fields: Vec<Rect> = h.query_all_by_role(Role::TextInput).map(|n| n.rect()).collect();
|
||||
/// Each of `fields` stands apart from `surface` by its fill or by its outline.
|
||||
fn assert_visible(h: &Harness<'_, SlideApp>, what: &str, fields: Vec<Rect>, surface: Color32) {
|
||||
assert!(!fields.is_empty(), "{what}: no text field");
|
||||
for field in fields {
|
||||
let (fill, stroke) = frame_at(h, field, surface);
|
||||
@@ -100,7 +130,7 @@ fn light_text_fields_show_in_dialogs_panes_and_the_ribbon() {
|
||||
h.run_steps(3);
|
||||
let tokens = craft::ui::runtime::env::Env::of_root(&h.ctx).tokens.clone();
|
||||
let raised = color(tokens.color.surface.raised);
|
||||
assert_visible(&h, "Find and Replace", raised);
|
||||
assert_visible(&h, "Find and Replace", fields_on(&h, Some("Find and Replace"), &[]), raised);
|
||||
let field = h.get_by_role_and_label(Role::TextInput, "Find what:").rect();
|
||||
h.get_by_role_and_label(Role::TextInput, "Find what:").click();
|
||||
h.run_steps(2);
|
||||
@@ -112,11 +142,12 @@ fn light_text_fields_show_in_dialogs_panes_and_the_ribbon() {
|
||||
h.state_mut().ui.pane = Some("thesaurus".into());
|
||||
h.run_steps(3);
|
||||
let tokens = craft::ui::runtime::env::Env::of_root(&h.ctx).tokens.clone();
|
||||
assert_visible(&h, "Thesaurus pane", color(tokens.color.surface.panel));
|
||||
// The ribbon's and the status bar's fields sit on the window chrome, not on the pane.
|
||||
assert_visible(&h, "Thesaurus pane", fields_on(&h, None, &["Ribbon", "Status Bar"]), color(tokens.color.surface.panel));
|
||||
|
||||
let mut h = harness();
|
||||
h.state_mut().ui.tab = "Transitions".into();
|
||||
h.run_steps(3);
|
||||
let tokens = craft::ui::runtime::env::Env::of_root(&h.ctx).tokens.clone();
|
||||
assert_visible(&h, "Transitions ribbon", color(tokens.color.surface.chrome));
|
||||
assert_visible(&h, "Transitions ribbon", fields_on(&h, Some("Ribbon"), &[]), color(tokens.color.surface.chrome));
|
||||
}
|
||||
|
||||
@@ -181,7 +181,15 @@ fn opening_backstage_palette_and_modal_routes_are_explicitly_ineligible() {
|
||||
assert!(WindowDialogs::of(&h.ctx, &WindowKey::main()).with(|host| host.cancel_by_id(&h.ctx, id)));
|
||||
}
|
||||
}
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.output().platform_output.ime.as_ref().map(|ime| ime.owner), Some(owner), "closing route {route} restores the canvas editor");
|
||||
// The old owner's interrupt goes out first, so the editor may publish a frame later.
|
||||
let mut published = None;
|
||||
for _ in 0..4 {
|
||||
h.run_steps(1);
|
||||
published = h.output().platform_output.ime.as_ref().map(|ime| ime.owner);
|
||||
if published == Some(owner) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert_eq!(published, Some(owner), "closing route {route} restores the canvas editor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1363,6 +1363,10 @@ fn synthetic_click_is_consumed_on_its_old_target_before_logic_changes_the_docume
|
||||
/// Every target-changing app state withdraws a click captured for the earlier state.
|
||||
#[test]
|
||||
fn input_target_changes_retract_a_queued_click() {
|
||||
// The ribbon row's own arrow, not the canvas scroll bars' of the same name.
|
||||
let ribbon_arrow = |h: &egui_kittest::Harness<'_, SlideApp>| {
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Group, "Ribbon").get_by_label("Scroll right").rect().center()
|
||||
};
|
||||
for case in [
|
||||
"show",
|
||||
"show step",
|
||||
@@ -1385,7 +1389,7 @@ fn input_target_changes_retract_a_queued_click() {
|
||||
let mut h = crate::test_harness::harness_with(
|
||||
Session::with_new(),
|
||||
Services::default(),
|
||||
egui_kittest::Harness::builder().with_size(egui::vec2(if case == "scroll" { 700.0 } else { 1440.0 }, 900.0)),
|
||||
egui_kittest::Harness::builder().with_size(egui::vec2(if case == "scroll" { 600.0 } else { 1440.0 }, 900.0)),
|
||||
|_| {},
|
||||
);
|
||||
h.state_mut().run("shape.insert", json!({"preset": "rect", "rect": [100, 100, 200, 100]})).unwrap();
|
||||
@@ -1407,7 +1411,7 @@ fn input_target_changes_retract_a_queued_click() {
|
||||
let slide = h.state().slide_rect().unwrap();
|
||||
let point = slide.min + slide.size() * 0.8;
|
||||
if case == "scroll" {
|
||||
let arrow = h.get_by_label("Scroll right").rect().center();
|
||||
let arrow = ribbon_arrow(&h);
|
||||
WindowHost::of(&ctx).inject_move(egui::ViewportId::ROOT, arrow, craft::keymap::Mods::default(), 0.0);
|
||||
}
|
||||
WindowHost::of(&ctx).inject_click(
|
||||
@@ -1440,7 +1444,7 @@ fn input_target_changes_retract_a_queued_click() {
|
||||
"collapse" => h.state_mut().ui.ribbon_collapsed = true,
|
||||
"scroll" => {
|
||||
let before = crate::ribbon::scroll_position(h.state(), &ctx);
|
||||
let at = h.get_by_label("Scroll right").rect().center();
|
||||
let at = ribbon_arrow(&h);
|
||||
h.input_mut().events.push(egui::Event::PointerMoved(at));
|
||||
for pressed in [true, false] {
|
||||
h.input_mut().events.push(egui::Event::PointerButton {
|
||||
@@ -1450,7 +1454,13 @@ fn input_target_changes_retract_a_queued_click() {
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
}
|
||||
h.run_steps(1);
|
||||
// The press waits behind the injected batch, so the row may move a frame later.
|
||||
for _ in 0..4 {
|
||||
h.run_steps(1);
|
||||
if crate::ribbon::scroll_position(h.state(), &ctx) != before {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert_ne!(crate::ribbon::scroll_position(h.state(), &ctx), before, "the real ribbon arrow scrolls its row");
|
||||
}
|
||||
"document" | "document return" => {
|
||||
|
||||
Reference in New Issue
Block a user