From 00893772d3b3ec2d5885e7e5825c913d5f9ef0ef Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 02:28:25 -0500 Subject: [PATCH] pdf-print-ocr-w1: net change of 4 commits - pdf-print-ocr-w1: finished by an agent - pdf-print-ocr-w1: finished by an agent - pdf-print-ocr-w1: finished by an agent - pdf-print-ocr-w1: review fixes (review-1) --- Cargo.lock | 1 + crates/print/Cargo.toml | 4 +- crates/print/src/ui/dialog.rs | 598 +++++++++++++----- crates/print/src/ui/mod.rs | 36 +- crates/print/src/ui/panel.rs | 116 ++-- crates/print/src/ui/stories.rs | 247 +++++++- crates/print/tests/it/dialog.rs | 181 +++++- crates/print/tests/it/main.rs | 1 + crates/print/tests/it/panel.rs | 55 ++ crates/print/tests/it/print.rs | 28 +- crates/ui-panels/src/dialog/held.rs | 5 +- .../api-map/theme-store-print-host-ui.toml | 29 +- 12 files changed, 1054 insertions(+), 247 deletions(-) create mode 100644 crates/print/tests/it/panel.rs diff --git a/Cargo.lock b/Cargo.lock index c644d01bc..869923850 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3446,6 +3446,7 @@ name = "craft-print" version = "0.1.0" dependencies = [ "craft-behavior", + "craft-theme", "craft-ui", "craft-winprint-gdi", "egui", diff --git a/crates/print/Cargo.toml b/crates/print/Cargo.toml index a3a14b1b8..3021b292b 100644 --- a/crates/print/Cargo.toml +++ b/crates/print/Cargo.toml @@ -16,12 +16,14 @@ harness = false [features] default = [] # The printer and job settings widgets (`craft_print::ui`). -ui = ["dep:craft-behavior", "dep:craft-ui", "dep:egui", "dep:serde_json"] +ui = ["dep:craft-behavior", "dep:craft-theme", "dep:craft-ui", "dep:egui", "dep:serde_json"] # The stories and the integration binary of the print panel. screen-testing = ["ui", "craft-ui/testing"] [dependencies] craft-behavior = { workspace = true, optional = true } +# `Tone` for the dialog's refusal notice; craft-ui does not re-export it. +craft-theme = { workspace = true, optional = true } craft-ui = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } egui = { workspace = true, optional = true } diff --git a/crates/print/src/ui/dialog.rs b/crates/print/src/ui/dialog.rs index 19f584250..2588bc504 100644 --- a/crates/print/src/ui/dialog.rs +++ b/crates/print/src/ui/dialog.rs @@ -4,32 +4,38 @@ use std::sync::mpsc::Receiver; use craft_behavior::{CursorIcon, EditEvent, EditEvents, Metrics, Mixed, PartKey, PointerButton, PressPhase, Sense}; +use craft_theme::variant::Tone; +use craft_ui::buttons::Button; use craft_ui::contract::{ Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Input, MeasureCx, Name, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, - Props as _, Role, Show as _, ShowContainer as _, WordSetCx as _, + Props as _, Role, Scroll, Show as _, ShowContainer as _, WordSetCx as _, clicked, }; -use craft_ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id}; -use craft_ui::display::Text; +use craft_ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, HeldAnswer, HeldOk, StackDialog, dialog_id}; +use craft_ui::display::{Shade, Text}; +use craft_ui::layout::RowAlign; use craft_ui::layout_components::{Row, Stack}; +use craft_ui::notices::{Notice, NoticeLayout}; use craft_ui::patterns::form_dialogs::{ DialogFields, FieldValue, FormDialog, HostRequests, PagerStep, PanePager, Param, ParamRows, set_color_field, set_param_field, }; +use craft_ui::primitives::{ContentPainterCx, TextRun, fill_polygon}; use craft_ui::runtime::env::{Env, Label}; use craft_ui::runtime::focus::{ActivateKeys, KeepKeys, KeyUse}; use craft_ui::runtime::overlay::CloseReason; use craft_ui::runtime::requests::HostAnswer; use craft_ui::sections::{DialogRole, FooterButton, Section}; -use craft_ui::style::{ComponentStyle, Corners, RuleKind, StyleCx, SurfaceKind}; +use craft_ui::style::{ComponentStyle, Corners, RuleKind, StyleColor, StyleCx, SurfaceKind, TypeRole}; use egui::load::SizedTexture; -use egui::{Pos2, Rect, Response, TextureId, Ui, Vec2, pos2, vec2}; +use egui::{Color32, Mesh, Pos2, Rect, Response, Shape, TextureId, Ui, Vec2, pos2, vec2}; -use super::panel::{DriverControls, MOST_COPIES, PrintPanel}; -use super::{Duplex, Printer, Settings, State}; +use super::panel::{Destinations, DriverControls, MOST_COPIES, PrintPanel, PrintWords}; +use super::{Destination, Duplex, Printer, Settings, State}; craft_ui::words! { /// The words of the print dialog. pub struct PrintDialogWords { title: "printDialog.title" = "Print Settings"; + title_document: "printDialog.titleDocument" = "Print"; print: "printDialog.print" = "Print"; done: "printDialog.done" = "Done"; preview: "printDialog.preview" = "Print preview image"; @@ -38,7 +44,10 @@ craft_ui::words! { } } -/// The index `FormOutput::picked` gives the Done button: Print is 0, Cancel 1, and the extra buttons start at 2. +/// The index `FormOutput::picked` gives the Print button: Print is 0, Cancel 1, and the extra buttons start at 2. +const PRINT_BUTTON: usize = 0; + +/// The index `FormOutput::picked` gives the Done button of the `Image` layout, its one extra button. const DONE_BUTTON: usize = 2; /// The image box of the preview. @@ -115,10 +124,10 @@ impl SheetPage { /// The page's picture `id` and the part `uv` of it to draw. #[must_use] - #[allow(dead_code)] // P3(pdf-print-ocr-w1): PO-P6 - pub fn picture(self, id: TextureId, uv: egui::Rect) -> Self { - let _ = (id, uv); - todo!("PO-P6") + pub fn picture(mut self, id: TextureId, uv: egui::Rect) -> Self { + self.picture = Some(id); + self.uv = uv; + self } } @@ -130,11 +139,7 @@ pub struct PrintSheet { pub paper: egui::Vec2, /// The printable area of the paper, when the printer says. pub printable: Option, - /// The image box on the paper. - pub image: egui::Rect, - /// The picture of the document. - pub picture: SizedTexture, - /// The marks to draw. + /// The marks to draw, around the image box or the pages. pub marks: PrintMarks, /// The readout under the preview. pub readout: Label, @@ -152,12 +157,25 @@ impl PrintSheet { /// A sheet of `paper` with the image box `image` holding `picture`, `readout` under the preview, no printable area /// and no marks. pub fn new(paper: egui::Vec2, image: egui::Rect, picture: SizedTexture, readout: Label) -> Self { - let content = SheetContent::Image { image, picture }; + Self::of(paper, SheetContent::Image { image, picture }, readout) + } + + /// A sheet of `paper` holding `pages`, with `readout` under the preview. + pub fn pages(paper: Vec2, pages: Vec, readout: Label) -> Self { + Self::of(paper, SheetContent::Pages(pages), readout) + } + + /// A preview showing `message` instead of a sheet, with `readout` under it. `paper` keeps the preview the size the + /// sheets around it take. + pub fn message(paper: Vec2, message: Label, readout: Label) -> Self { + Self::of(paper, SheetContent::Message(message), readout) + } + + /// A sheet of `paper` showing `content`, with no printable area, no marks, borders, cuts or notes. + fn of(paper: Vec2, content: SheetContent, readout: Label) -> Self { PrintSheet { paper, printable: None, - image, - picture, marks: PrintMarks::default(), readout, content, @@ -167,42 +185,33 @@ impl PrintSheet { } } - /// A sheet of `paper` holding `pages`, with `readout` under the preview. - #[allow(dead_code)] // P3(pdf-print-ocr-w1): PO-P6 - pub fn pages(paper: Vec2, pages: Vec, readout: Label) -> Self { - let _ = (paper, pages, readout); - todo!("PO-P6") - } - - /// A preview showing `message` instead of a sheet, with `readout` under it. - #[allow(dead_code)] // P3(pdf-print-ocr-w1): PO-P6 - pub fn message(paper: Vec2, message: Label, readout: Label) -> Self { - let _ = (paper, message, readout); - todo!("PO-P6") + /// The image box of an `Image` sheet; none for pages or a message. + pub(super) fn image_box(&self) -> Option { + match &self.content { + SheetContent::Image { image, .. } => Some(*image), + SheetContent::Pages(_) | SheetContent::Message(_) => None, + } } /// The borders drawn around the pages. #[must_use] - #[allow(dead_code)] // P3(pdf-print-ocr-w1): PO-P6 - pub fn borders(self, borders: Vec) -> Self { - let _ = borders; - todo!("PO-P6") + pub fn borders(mut self, borders: Vec) -> Self { + self.borders = borders; + self } /// The cut lines. #[must_use] - #[allow(dead_code)] // P3(pdf-print-ocr-w1): PO-P6 - pub fn cuts(self, cuts: Vec<[Pos2; 2]>) -> Self { - let _ = cuts; - todo!("PO-P6") + pub fn cuts(mut self, cuts: Vec<[Pos2; 2]>) -> Self { + self.cuts = cuts; + self } /// The notes under the readout. #[must_use] - #[allow(dead_code)] // P3(pdf-print-ocr-w1): PO-P6 - pub fn notes(self, notes: Vec