Canvas: clip the canvas Ui to its own rect so the media bar and other canvas paint stay out of the notes pane (#1922)

This commit is contained in:
Naseq committed 2026-11-08 15:18:27 +04:30
1 parent 48e2203123
commit 0a07e9eae1
2 files changed
+61

No files matched your search

+5
View File
@@ -152,6 +152,11 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
let t = Tokens::get(ui.ctx());
let avail = ui.available_rect_before_wrap();
app.canvas_rect = Some(avail);
// The notes pane and the panes beside the canvas are editor chrome over it: nothing the
// canvas paints or hit-tests (the media bar hangs 6 pt below its clip, handles stick out of a
// shape, scroll bars) may reach into them. The parent's clip still covers the whole central
// area, so clip this `Ui` to the rect the canvas was given (#1922).
ui.set_clip_rect(avail.intersect(ui.clip_rect()));
let Some(st) = app.session.active() else { return };
// The leftover fraction of a wheel line belongs to one presentation. Drop it whenever another
// one is drawn here, hovered or not, so switching away and back starts from zero.
+56
View File
@@ -70,3 +70,59 @@ fn play_on_the_editor_media_bar_plays_the_selected_clip() {
click(&mut h, bar + vec2(w - 30.0, 13.0));
assert_eq!(h.state().session.active().unwrap().selection.shapes, vec![id]);
}
/// #1922: the bar hangs 6 pt under the clip, so a clip at the bottom edge of the slide put it
/// inside the speaker-notes pane, painted over the notes text. The canvas is clipped to its own
/// rect: nothing it paints reaches the notes pane, and a click there goes to the notes field.
#[test]
fn the_media_bar_never_paints_or_clicks_into_the_notes_pane() {
use egui::accesskit::Role;
use egui_kittest::kittest::Queryable;
let mut s = Session::with_new();
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
let r = s.execute("insert.audio", &json!({"name": "tone.wav", "data": deckcraft_engine::cmd::base64_encode(&wav(2.0))})).unwrap();
let id = ShapeId(r["id"].as_u64().unwrap() as u32);
// Dragged across the bottom edge of the slide, onto the pasteboard.
let h_slide = s.doc().unwrap().doc.slide_size.height;
s.execute("shape.setBounds", &json!({"ids": [id.0], "x": 300.0, "y": h_slide - 10.0, "w": 120.0, "h": 60.0})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.notes = true;
app.ui.notes_height = 140.0;
let mut h = Harness::builder().with_size(vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
let notes = h.query_all_by_role(Role::MultilineTextInput).next().map(|n| n.rect()).expect("the notes field");
let canvas = h.state().canvas_rect.unwrap();
assert!(canvas.max.y <= notes.min.y + 1.0, "the notes pane sits under the canvas: {canvas:?} / {notes:?}");
let d = h.state().session.active().unwrap();
let x = d.doc.slides[d.selection.slide].shape(id).unwrap().xfrm.unwrap();
let (slide, k) = (h.state().slide_rect.unwrap(), h.state().canvas_scale);
let bottom = slide.min.y + (x.y + x.h) as f32 * k;
let bar_y = bottom + 6.0 + 13.0;
assert!(bar_y > notes.min.y, "the bar's row ({bar_y}) would fall inside the notes pane (top {})", notes.min.y);
// The bar's own background (the only dark rounded rect the canvas paints there) has no
// visible area below the canvas edge: whatever the canvas paints is clipped to the canvas.
let bar_fill = egui::Color32::from_rgba_unmultiplied(28, 28, 32, 230);
let bars: Vec<egui::Rect> = h
.output()
.shapes
.iter()
.filter_map(|cs| match &cs.shape {
egui::Shape::Rect(r) if r.fill == bar_fill => Some(r.rect.intersect(cs.clip_rect)),
_ => None,
})
.collect();
assert!(!bars.is_empty(), "the bar is still laid out for the selected clip");
assert!(bars.iter().all(|v| !v.is_positive() || v.max.y <= canvas.max.y + 0.5), "the bar is painted into the notes pane: {bars:?}");
// A click where the bar would be lands in the notes field, not on the bar.
click(&mut h, pos2(slide.min.x + (x.x + x.w / 2.0) as f32 * k, bar_y));
assert!(h.state().media.status(id).is_none(), "Play was not hit through the notes pane");
assert!(h.ctx.memory(|m| m.focused()).is_some(), "the notes field took the click");
}