mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-20 19:18:41 +00:00
fix(ui): paint the active-pane line on the pane's layer, test it under an open menu
A layer no area owns is drawn after every area of its order, so at Middle the line would cross the floating bars instead. Painted on the pane's own layer after its pages, it sits over them and under every area.
This commit is contained in:
1 parent
89ec8ed9f4
commit
b549727855
2 files changed
+38
-12
No files matched your search
@@ -615,12 +615,12 @@ fn pane(app: &mut PdfCraftApp, ui: &mut egui::Ui, rect: Rect, place: Place, fron
|
||||
(Place::Second, None) => {}
|
||||
}
|
||||
app.panes.drawing = Place::Main;
|
||||
// The active pane is marked along its top edge: over the pages, under the menus (#7010). A
|
||||
// layer with no area is drawn after every area of its order, so at Foreground it crossed
|
||||
// open menus and popups.
|
||||
// The active pane is marked along its top edge, on the pane's own layer after its pages: over
|
||||
// them, and under every menu, popup and floating bar (#7010). A layer of its own, which no
|
||||
// area owns, is drawn after every area of its order, so the line crossed open menus.
|
||||
if active {
|
||||
let edge = Rect::from_min_size(rect.min, vec2(rect.width(), 2.0));
|
||||
ui.ctx().layer_painter(egui::LayerId::new(egui::Order::Middle, egui::Id::unique(("active-pane", salt)))).rect_filled(edge, 0.0, t.accent);
|
||||
child.painter().rect_filled(edge, 0.0, t.accent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -320,16 +320,42 @@ fn closing_the_second_panes_tab_from_its_strip_keeps_the_program_running() {
|
||||
/// its own at the menus' order, and egui draws such a layer after every menu and popup of that
|
||||
/// order, so the line crossed an open menu.
|
||||
#[test]
|
||||
fn the_active_panes_line_is_drawn_under_the_menus() {
|
||||
fn the_active_panes_line_is_drawn_under_an_open_menu() {
|
||||
let mut h = harness(&["right.pdf", "left.pdf"]);
|
||||
// With the tools pane closed, the main pane starts under the tabs.
|
||||
h.state_mut().set_option("left", "closed").unwrap();
|
||||
let right = index(&h, "right.pdf");
|
||||
h.state_mut().split_tab(right, false);
|
||||
h.run_steps(4);
|
||||
let painted = |h: &Harness<'static, PdfCraftApp>, order: egui::Order| {
|
||||
["main-pane", "second-pane"]
|
||||
.iter()
|
||||
.any(|salt| h.ctx.graphics(|g| g.get(egui::LayerId::new(order, egui::Id::unique(("active-pane", *salt)))).is_some()))
|
||||
};
|
||||
assert!(!painted(&h, egui::Order::Foreground), "the line is not painted at the menus' order");
|
||||
assert!(painted(&h, egui::Order::Middle), "the line is painted above the pages, below the menus");
|
||||
let left = index(&h, "left.pdf");
|
||||
let at = h.state().views[left].viewport_rect().center();
|
||||
click_at(&mut h, at);
|
||||
assert_eq!(h.state().active, Some(left), "the main pane is the active one");
|
||||
let top = h.state().views[left].viewport_rect();
|
||||
// The menu of the main strip's tab drops down across the main pane's top edge.
|
||||
h.get_by_role_and_label(Role::Tab, "left.pdf").click_secondary();
|
||||
h.run_steps(2);
|
||||
let item = h.get_by_label("Split right").rect();
|
||||
fn flat(shape: &egui::Shape, out: &mut Vec<egui::epaint::RectShape>) {
|
||||
match shape {
|
||||
egui::Shape::Vec(shapes) => shapes.iter().for_each(|s| flat(s, out)),
|
||||
egui::Shape::Rect(r) => out.push(r.clone()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut rects = Vec::new();
|
||||
for clipped in &h.output().shapes {
|
||||
flat(&clipped.shape, &mut rects);
|
||||
}
|
||||
let line = rects
|
||||
.iter()
|
||||
.position(|r| (r.rect.height() - 2.0).abs() < 0.01 && (r.rect.top() - top.top()).abs() < 1.0 && (r.rect.left() - top.left()).abs() < 1.0)
|
||||
.expect("the active pane's line is painted");
|
||||
let line_rect = rects[line].rect;
|
||||
let menu = rects
|
||||
.iter()
|
||||
.rposition(|r| r.fill.a() == 255 && r.rect.contains_rect(item) && r.rect.width() < line_rect.width())
|
||||
.expect("the tab's menu is painted");
|
||||
assert!(rects[menu].rect.intersects(line_rect), "the menu crosses the line: {:?} {line_rect:?}", rects[menu].rect);
|
||||
assert!(line < menu, "the line was painted over the open menu");
|
||||
}
|
||||
Reference in new issue
Block a user