mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 03:49:11 +00:00
Merge red3/g3 (root_env takes ctx; theme_preference shown by Debug)
This commit is contained in:
@@ -487,11 +487,13 @@ impl PdfCraftApp {
|
||||
|
||||
/// The app's root values for this frame: appearance mode, motion, interface scale and the
|
||||
/// interface language's direction. The one place the app's `RootEnv` is built.
|
||||
// PLAN: `ui_scale: None` gives scale 1; following the desktop's text scale (`env::system_text_scale`) needs a ctx, and hub-w3 calls this as `root_env()`.
|
||||
pub(crate) fn root_env(&self) -> RootEnv {
|
||||
pub(crate) fn root_env(&self, ctx: &egui::Context) -> RootEnv {
|
||||
let lang = i18n::Lang::from_pref(&self.language);
|
||||
let direction = if lang.rtl() { craft_i18n::Direction::Rtl } else { craft_i18n::Direction::Ltr };
|
||||
let mut root = RootEnv::new().mode(self.theme_preference).direction(direction).scale(Scale::new(self.ui_scale.unwrap_or(1.0)));
|
||||
let system = craft::ui::runtime::env::system_text_scale(ctx).unwrap_or(1.0);
|
||||
let native = ctx.native_pixels_per_point().unwrap_or(1.0);
|
||||
let mut root =
|
||||
RootEnv::new().mode(self.theme_preference).direction(direction).scale(Scale::new(crate::ui_scale::zoom(self.ui_scale, system, native)));
|
||||
root.motion = self.animation_effects;
|
||||
root
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ impl PdfCraftApp {
|
||||
self.run_declined(declined);
|
||||
}
|
||||
let commands = crate::commands::catalog::command_input(self, ctx);
|
||||
FrameInput::new(self.root_env()).commands(commands).host(self.host.clone())
|
||||
FrameInput::new(self.root_env(ctx)).commands(commands).host(self.host.clone())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,8 +212,7 @@ impl PdfCraftApp {
|
||||
|
||||
/// Switches between light and dark from the mode the interface shows now.
|
||||
fn toggle_theme(&mut self, ctx: &egui::Context) {
|
||||
// PLAN: assumed `PdfCraftApp::root_env(&self) -> RootEnv`, hub-w1's one builder (pdf-hub-w1).
|
||||
let next = if self.root_env().resolved(ctx).mode == craft::theme::Mode::Light { ModeChoice::Dark } else { ModeChoice::Light };
|
||||
let next = if self.root_env(ctx).resolved(ctx).mode == craft::theme::Mode::Light { ModeChoice::Dark } else { ModeChoice::Light };
|
||||
self.set_theme_preference(next);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ impl crate::PdfCraftApp {
|
||||
.or_else(|| self.preferences.is_some().then(|| "preferences".to_string()))
|
||||
.or_else(|| self.shortcuts.is_some().then(|| "shortcuts".to_string())),
|
||||
"palette_open": self.palette_open,
|
||||
"theme": format!("{:?}", self.root_env().resolved(ctx).mode),
|
||||
"theme": format!("{:?}", self.root_env(ctx).resolved(ctx).mode),
|
||||
"theme_preference": format!("{:?}", self.theme_preference),
|
||||
"show_page_edge_shadows": self.show_page_edge_shadows,
|
||||
"language": self.language,
|
||||
|
||||
@@ -346,6 +346,12 @@ impl Panels<'_> {
|
||||
/// the page area.
|
||||
fn document_view(app: &mut PdfCraftApp, ui: &mut Ui, rect: egui::Rect) {
|
||||
app.settle_document_view();
|
||||
eprintln!(
|
||||
"DIAG continuous_layout_stacks_pages_vertically: document_view rect={rect:?} avail={:?} max={:?} screen={:?}",
|
||||
ui.available_rect_before_wrap(),
|
||||
ui.max_rect(),
|
||||
ui.ctx().content_rect()
|
||||
);
|
||||
if app.full_screen_document() {
|
||||
ui.painter().rect_filled(rect, 0.0, egui::Color32::BLACK);
|
||||
if let Some(i) = app.active {
|
||||
|
||||
@@ -116,6 +116,12 @@ impl Rig {
|
||||
}
|
||||
});
|
||||
h.run_steps(3);
|
||||
// The host's queue also carries the page text layers the window asks for; they finish first, so that the
|
||||
// oldest waiting job in a test is the open it holds.
|
||||
for _ in 0..2 {
|
||||
jobs.run_all();
|
||||
h.run_steps(2);
|
||||
}
|
||||
Self { h, jobs, files, intake: sender, control }
|
||||
}
|
||||
|
||||
|
||||
@@ -50,10 +50,12 @@ impl ItemSource<usize> for PageRows<'_> {}
|
||||
pub(super) fn pages(app: &PdfCraftApp, ui: &mut egui::Ui, n: &mut Intents) {
|
||||
let v = &app.ocr_verify;
|
||||
let rows = PageRows(&v.pages);
|
||||
let out = List::<usize>::new(tl!("Pages")).select(SelectMode::Single).selection(Bind::given(Selection::single(v.current))).show_items(
|
||||
ui,
|
||||
&rows,
|
||||
&mut |key, _| {
|
||||
// The pane's panel scrolls its body, so the list takes its natural height and the panel carries the scroll.
|
||||
let out = List::<usize>::new(tl!("Pages"))
|
||||
.select(SelectMode::Single)
|
||||
.selection(Bind::given(Selection::single(v.current)))
|
||||
.natural_height(true)
|
||||
.show_items(ui, &rows, &mut |key, _| {
|
||||
let Some(pg) = v.pages.iter().find(|pg| pg.page == *key) else { return ListRow::spacer() };
|
||||
let live = pg.words.iter().filter(|w| !w.text.trim().is_empty()).count();
|
||||
let suspects = pg.words.iter().filter(|w| !w.text.trim().is_empty() && is_suspect(w.confidence)).count();
|
||||
@@ -66,8 +68,7 @@ pub(super) fn pages(app: &PdfCraftApp, ui: &mut egui::Ui, n: &mut Intents) {
|
||||
};
|
||||
let row = ListRow::new(format!("{} {}{} · {live}", tl!("Page"), pg.page + 1, marked));
|
||||
if suspects > 0 { row.detail(crate::i18n::fmt(tl!("{n} word(s) to review"), &[("n", &suspects.to_string())])) } else { row }
|
||||
},
|
||||
);
|
||||
});
|
||||
for event in out.events {
|
||||
if let CollectionEvent::Selection(change) = event {
|
||||
match change {
|
||||
|
||||
@@ -134,7 +134,7 @@ fn search_finds_collapsed_bookmarks_and_keeps_original_paths() {
|
||||
h.state_mut().apply_edit(&ctx_h, Edit::AddBookmark { parent, index, title: title.into(), page, left: None, top: None });
|
||||
}
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Bookmark options").click();
|
||||
h.get_by_label("Panel Menu").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Collapse all bookmarks").click();
|
||||
h.run_steps(3);
|
||||
@@ -210,7 +210,7 @@ trailer << /Root 1 0 R >>
|
||||
let ctx_h = h.ctx.clone();
|
||||
h.state_mut().open_bytes(&ctx_h, "tagged.pdf", None, TAGGED.to_vec()).unwrap();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Bookmark options").click();
|
||||
h.get_by_label("Panel Menu").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("New bookmarks from structure").click();
|
||||
h.run_steps(3);
|
||||
@@ -267,7 +267,7 @@ fn new_bookmarks_from_text_styles_from_the_bookmark_options() {
|
||||
h.run_steps(3);
|
||||
let id = h.state().active.and_then(|i| h.state().views.get(i)).unwrap().id;
|
||||
let open = |h: &mut Harness<'static, PdfCraftApp>| {
|
||||
h.get_by_label("Bookmark options").click();
|
||||
h.get_by_label("Panel Menu").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("New bookmarks from text styles…").click();
|
||||
h.run_steps(3);
|
||||
@@ -330,17 +330,17 @@ fn expanding_and_collapsing_all_bookmarks() {
|
||||
}
|
||||
h.run_steps(3);
|
||||
let shown = |h: &Harness<'static, PdfCraftApp>, t: &str| h.query_by_label(t).is_some();
|
||||
h.get_by_label("Bookmark options").click();
|
||||
h.get_by_label("Panel Menu").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Expand all bookmarks").click();
|
||||
h.run_steps(3);
|
||||
assert!(shown(&h, "Chapter") && shown(&h, "Section"));
|
||||
h.get_by_label("Bookmark options").click();
|
||||
h.get_by_label("Panel Menu").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Collapse all bookmarks").click();
|
||||
h.run_steps(3);
|
||||
assert!(shown(&h, "Part") && !shown(&h, "Chapter"));
|
||||
h.get_by_label("Bookmark options").click();
|
||||
h.get_by_label("Panel Menu").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Expand top-level bookmarks").click();
|
||||
h.run_steps(3);
|
||||
@@ -501,7 +501,7 @@ fn cut_copy_and_paste_a_bookmark_subtree_within_and_between_documents() {
|
||||
let ctx_h = h.ctx.clone();
|
||||
h.state_mut().open_bytes(&ctx_h, "one.pdf", None, ONE_PAGE.to_vec()).unwrap();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Bookmark options").click();
|
||||
h.get_by_label("Panel Menu").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Paste bookmarks").click();
|
||||
h.run_steps(3);
|
||||
|
||||
@@ -16,7 +16,7 @@ use std::ops::{Deref, DerefMut};
|
||||
use std::sync::Arc;
|
||||
|
||||
const BOX_LABELS: [&str; 6] =
|
||||
["Header left text", "Header center text", "Header right text", "Footer left text", "Footer center text", "Footer right text"];
|
||||
["Left Header Text", "Center Header Text", "Right Header Text", "Left Footer Text", "Center Footer Text", "Right Footer Text"];
|
||||
const WATERMARK_TEXT: &str = "Watermark text";
|
||||
const REPLACE: &str = "Page 1 paints its own white backdrop, which would hide the background. Replace it";
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ fn a_watched_label_replacement_keeps_the_display_mode_and_focused_page() {
|
||||
assert_eq!((doc.can_undo(), doc.can_redo()), (None, None));
|
||||
assert!(h.execute("view.focus_page_input"));
|
||||
h.run_steps(3);
|
||||
h.get(By::new().role(egui::accesskit::Role::TextInput).value("2"));
|
||||
assert!(h.get_all(By::new().role(egui::accesskit::Role::TextInput).value("2")).next().is_some());
|
||||
let editor = h.ctx.memory(|m| m.focused()).expect("the page editor is focused");
|
||||
|
||||
// A build atomically publishes a whole, clean PDF. The real watcher detects it.
|
||||
@@ -350,11 +350,11 @@ fn saving_over_a_file_changed_by_something_else_asks_first() {
|
||||
let ctx_h = h.ctx.clone();
|
||||
assert!(!h.state_mut().save_active(&ctx_h, SaveTarget::InPlace), "not written yet");
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Save over the changed file?");
|
||||
h.get_by_label("File changed");
|
||||
h.get_by_label("Cancel").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(std::fs::read(&file.path).unwrap(), fixture(4), "Cancel keeps the newer file");
|
||||
assert!(dirty(&h) && h.query_by_label("Save over the changed file?").is_none());
|
||||
assert!(dirty(&h) && h.query_by_label("File changed").is_none());
|
||||
let ctx_h = h.ctx.clone();
|
||||
assert!(!h.state_mut().save_active(&ctx_h, SaveTarget::InPlace));
|
||||
h.run_steps(2);
|
||||
@@ -381,7 +381,7 @@ fn saving_checks_the_file_with_the_watcher_off_too() {
|
||||
let ctx_h = h.ctx.clone();
|
||||
assert!(!h.state_mut().save_active(&ctx_h, SaveTarget::InPlace));
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Save over the changed file?");
|
||||
h.get_by_label("File changed");
|
||||
}
|
||||
|
||||
/// One file, one tab (#2166): opening a file that is open already brings its tab forward,
|
||||
@@ -467,7 +467,8 @@ fn a_file_rebuilt_under_the_full_screen_prompt_reloads_once_it_is_answered() {
|
||||
let file = TempPdf::new("under-full-screen", &fixture_catalog(2, false, "/PageMode /FullScreen "));
|
||||
let mut h = harness(&file.path);
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Open in Full Screen mode?");
|
||||
// The prompt's window and its title both carry the name.
|
||||
assert!(h.get_all_by_label("Open in Full Screen mode?").next().is_some());
|
||||
file.rebuild(&fixture(4));
|
||||
h.run_steps(4);
|
||||
assert_eq!(pages(&h), 2, "not replaced under the prompt");
|
||||
|
||||
@@ -55,6 +55,18 @@ fn rect(h: &Harness<'static, PdfCraftApp>, page: usize) -> Option<egui::Rect> {
|
||||
h.state().views[0].page_screen_rect(page)
|
||||
}
|
||||
|
||||
/// Turns on the Preferences row `label` on the Documents and view page and applies it with OK, as a user does.
|
||||
fn choose_in_documents_preferences(h: &mut Harness<'static, PdfCraftApp>, label: &str) {
|
||||
h.get_by_label("Documents and view").click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label(label).scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by_label(label).click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn sidebar_key(h: &mut Harness<'static, PdfCraftApp>, key: Key, modifiers: Modifiers) {
|
||||
h.event(egui::Event::ModifiersChanged(modifiers));
|
||||
for pressed in [true, false] {
|
||||
@@ -552,9 +564,9 @@ fn the_rail_zoom_field_sets_a_typed_zoom() {
|
||||
use pdfcraft_ui_egui::canvas::Fit;
|
||||
let mut h = harness(&[]);
|
||||
let type_zoom = |h: &mut Harness<'static, PdfCraftApp>, typed: &str, key: Key| {
|
||||
h.get_by_role_and_label(Role::TextInput, "Zoom").click();
|
||||
h.get_by_role_and_label(Role::SpinButton, "Zoom").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_role_and_label(Role::TextInput, "Zoom").type_text(typed);
|
||||
h.get_by_role_and_label(Role::SpinButton, "Zoom").type_text(typed);
|
||||
h.run_steps(1);
|
||||
h.key_press(key);
|
||||
h.run_steps(3);
|
||||
@@ -571,7 +583,7 @@ fn the_rail_zoom_field_sets_a_typed_zoom() {
|
||||
assert_eq!(h.state().views[0].zoom(), 64.0);
|
||||
h.state_mut().views[0].view.zoom = 2.0;
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.get_by_role_and_label(Role::TextInput, "Zoom").value().as_deref(), Some("200%"));
|
||||
assert_eq!(h.get_by_role_and_label(Role::SpinButton, "Zoom").value().as_deref(), Some("200%"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -620,10 +632,7 @@ fn preferences_turn_on_always_use_my_default_zoom_and_page_layout() {
|
||||
let mut h = harness(&[]);
|
||||
assert!(h.execute("app.preferences"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Always use my default zoom and page layout").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Always use my default zoom and page layout").click();
|
||||
h.run_steps(2);
|
||||
choose_in_documents_preferences(&mut h, "Always use my default zoom and page layout");
|
||||
assert!(h.state().always_default_view);
|
||||
}
|
||||
|
||||
@@ -642,10 +651,7 @@ fn preferences_turn_on_always_use_my_default_zoom_and_page_layout_updates_open_d
|
||||
assert_ne!(h.state().views[1].fit(), pdfcraft_ui_egui::canvas::Fit::Width);
|
||||
assert!(h.execute("app.preferences"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Always use my default zoom and page layout").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Always use my default zoom and page layout").click();
|
||||
h.run_steps(2);
|
||||
choose_in_documents_preferences(&mut h, "Always use my default zoom and page layout");
|
||||
assert!(h.state().always_default_view);
|
||||
for (i, view) in h.state().views.iter().enumerate() {
|
||||
assert!(view.continuous(), "continuous scrolling is applied to view {i}");
|
||||
@@ -661,10 +667,7 @@ fn preferences_toggle_continuous_scrolling_updates_active_document() {
|
||||
assert!(!h.state().views[0].continuous());
|
||||
assert!(h.execute("app.preferences"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Continuous scrolling").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Continuous scrolling").click();
|
||||
h.run_steps(2);
|
||||
choose_in_documents_preferences(&mut h, "Continuous scrolling");
|
||||
assert!(h.state().view_defaults.continuous, "defaults are updated");
|
||||
assert!(h.state().views[0].continuous(), "active document view is updated");
|
||||
}
|
||||
@@ -687,10 +690,7 @@ fn preferences_during_full_screen_updates_saved_normal_display_and_restores_on_e
|
||||
|
||||
assert!(h.execute("app.preferences"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Always use my default zoom and page layout").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Always use my default zoom and page layout").click();
|
||||
h.run_steps(2);
|
||||
choose_in_documents_preferences(&mut h, "Always use my default zoom and page layout");
|
||||
assert!(h.state().always_default_view);
|
||||
|
||||
{
|
||||
@@ -726,10 +726,7 @@ fn preferences_toggle_continuous_during_full_screen_updates_saved_normal_display
|
||||
|
||||
assert!(h.execute("app.preferences"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Continuous scrolling").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Continuous scrolling").click();
|
||||
h.run_steps(2);
|
||||
choose_in_documents_preferences(&mut h, "Continuous scrolling");
|
||||
|
||||
assert!(h.state().view_defaults.continuous);
|
||||
{
|
||||
@@ -760,10 +757,7 @@ fn preferences_with_always_default_view_on_toggling_continuous_preserves_custom_
|
||||
|
||||
assert!(h.execute("app.preferences"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Continuous scrolling").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Continuous scrolling").click();
|
||||
h.run_steps(2);
|
||||
choose_in_documents_preferences(&mut h, "Continuous scrolling");
|
||||
|
||||
assert!(h.state().view_defaults.continuous);
|
||||
let v = &h.state().views[0];
|
||||
@@ -777,10 +771,7 @@ fn preferences_set_the_default_zoom() {
|
||||
let mut h = harness(&[]);
|
||||
assert!(h.execute("app.preferences"));
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Zoom to page level").scroll_to_me();
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Zoom to page level").click();
|
||||
h.run_steps(2);
|
||||
choose_in_documents_preferences(&mut h, "Zoom to page level");
|
||||
assert!(h.execute("create.blank"));
|
||||
assert_eq!(h.state().views[1].fit(), pdfcraft_ui_egui::canvas::Fit::Page);
|
||||
}
|
||||
@@ -792,7 +783,7 @@ fn rail_page_display_menu_offers_acrobats_view_choices() {
|
||||
let mut h = harness(&[]);
|
||||
h.run_steps(4);
|
||||
let pick = |h: &mut Harness<'static, PdfCraftApp>, item: &str| {
|
||||
h.get_by_label_contains("Page display:").click();
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Button, "Page display").click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label(item).click();
|
||||
h.run_steps(4);
|
||||
@@ -2190,7 +2181,7 @@ fn the_pages_panel_tools_act_on_the_selected_pages() {
|
||||
let rotations = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(id).unwrap().info.pages.iter().map(|p| p.rotation).collect::<Vec<_>>();
|
||||
// The panel's Page tools menu, on the right-hand side of the window.
|
||||
let tool = |h: &mut Harness<'static, PdfCraftApp>, label: &str| {
|
||||
h.get_all_by_label("Page tools").find(|n| n.rect().left() > 1000.0).expect("Page tools in the Pages panel").click();
|
||||
h.get_all_by_label("Panel Menu").find(|n| n.rect().left() > 1000.0).expect("Panel Menu in the Pages panel").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label(label).click();
|
||||
h.run_steps(3);
|
||||
@@ -2244,7 +2235,7 @@ fn the_pages_panel_tools_insert_from_a_file_and_extract() {
|
||||
let id = h.state().views[0].id;
|
||||
let count = |h: &Harness<'static, PdfCraftApp>| h.state().session.get(id).unwrap().info.pages.len();
|
||||
let tool = |h: &mut Harness<'static, PdfCraftApp>, label: &str| {
|
||||
h.get_all_by_label("Page tools").find(|n| n.rect().left() > 1000.0).expect("Page tools in the Pages panel").click();
|
||||
h.get_all_by_label("Panel Menu").find(|n| n.rect().left() > 1000.0).expect("Panel Menu in the Pages panel").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label(label).click();
|
||||
h.run_steps(3);
|
||||
@@ -2287,7 +2278,7 @@ fn the_pages_panel_tools_are_off_without_page_editing_permission() {
|
||||
let i = h.state().active.unwrap();
|
||||
let id = h.state().views[i].id;
|
||||
assert!(!h.state().session.get(id).unwrap().allows_assembly());
|
||||
let tools = h.get_all_by_label("Page tools").find(|n| n.rect().left() > 1000.0).expect("Page tools");
|
||||
let tools = h.get_all_by_label("Panel Menu").find(|n| n.rect().left() > 1000.0).expect("Page tools");
|
||||
assert!(tools.accesskit_node().is_disabled(), "Page tools is greyed out");
|
||||
tools.click();
|
||||
h.run_steps(3);
|
||||
|
||||
Reference in New Issue
Block a user