From 2fde380ed6ee109e412ddab3d8d9e5784522d3b2 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 15 Nov 2026 04:46:07 +0000 Subject: [PATCH] dialogs-w16: net change of 8 commits - dialogs-w16: written from its sheet - dialogs-w16: repair 1 - dialogs-w16: review fixes (review-1) - dialogs-w16: review fixes (item 1, 6) - dialogs-w16: review fixes (item 6) - dialogs-w16: the print preview's style is as visible as the preview (combine) - dialogs-w16: the preview's release ends only a running drag; its output reports its edits to the suite (dialogs run round) - dialogs-w16: the print preview's value is the image box position, which a drag moves from the gesture's start and a host check can refuse (dialogs run round) --- crates/print/README.md | 12 +- crates/print/src/ui/dialog.rs | 460 +++++++++++++++++++++++++++++--- crates/print/src/ui/panel.rs | 63 ++++- crates/print/src/ui/stories.rs | 79 +++++- crates/print/tests/it/dialog.rs | 87 ++++++ crates/print/tests/it/main.rs | 1 + 6 files changed, 648 insertions(+), 54 deletions(-) create mode 100644 crates/print/tests/it/dialog.rs diff --git a/crates/print/README.md b/crates/print/README.md index bedcd0984..a5991d4a9 100644 --- a/crates/print/README.md +++ b/crates/print/README.md @@ -234,8 +234,16 @@ plus discovery and submission receivers. Hosts supply `Discover` and `Submit` wo the state nor the controls invokes an OS spooler or generates PDF content. Apps map `Settings` to ``Job`` and own the Print action, page selection, preview and export behavior. -`State::show` takes a stable `egui::Id` and app-localized `Labels`. It draws the settings only; -apps render typed `Feedback` using their own translations. `poll` requests occasional repaints +`State::run` polls the workers and draws `PrintPanel` over the settings, starting discovery on the first pass; apps +that draw their own dialog around the panel use it. `PrintDialog` is Photoshop's Print Settings: a preview of the +paper, printable area, image box and marks, the panel, and the app's `PrintSection` rows (`ParamRows`), with Print, +Cancel and Done in the footer. Dragging the image box reports its total travel from the press in paper points as +`EditEvents`. `HostedPrint` is the same dialog owned by a `DialogHost`. It holds no discovery closure: it asks with +`take_refresh` (the first pass and each Refresh) and the app answers with `listen`, passing `discover()` or its own +receiver, so a list that needs the app's session works too. `State::listen` takes the receiver and refuses while a +discovery or a job runs. + +Apps render typed `Feedback` using their own translations. `poll` requests occasional repaints while work is pending. Refresh disables submission until the new printer list arrives, preserves a still-present selection, and otherwise chooses the system default or first available printer. An empty or failed discovery cannot leave a stale printer ready to submit. diff --git a/crates/print/src/ui/dialog.rs b/crates/print/src/ui/dialog.rs index de4b7e478..91bacaeab 100644 --- a/crates/print/src/ui/dialog.rs +++ b/crates/print/src/ui/dialog.rs @@ -1,20 +1,28 @@ //! `PrintDialog`: Photoshop's Print Settings (the preview pane, the printer panel and the app's //! sections), and `HostedPrint`, the same dialog owned by a `DialogHost`. -#![allow(clippy::todo)] // P3(dialogs-w16): dl.K44 bodies. use std::sync::mpsc::Receiver; -use craft_behavior::{EditEvent, EditEvents}; -use craft_ui::contract::{Bind, NoValue, Outcome}; -use craft_ui::dialog::{DialogId, DialogResult, DialogStack, StackDialog, dialog_id}; -use craft_ui::patterns::form_dialogs::{DialogFields, HostRequests, Param}; -use craft_ui::runtime::env::Label; +use craft_behavior::{CursorIcon, EditEvent, EditEvents, Metrics, Mixed, PartKey, PointerButton, PressPhase, Sense}; +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 _, +}; +use craft_ui::dialog::{DialogId, DialogResult, DialogStack, FieldRefusal, StackDialog, dialog_id}; +use craft_ui::display::Text; +use craft_ui::layout_components::{Row, Stack}; +use craft_ui::patterns::form_dialogs::{DialogFields, FieldValue, FormDialog, HostRequests, Param, ParamRows, set_color_field, set_param_field}; +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}; +use craft_ui::style::{ComponentStyle, Corners, RuleKind, StyleCx, SurfaceKind}; use egui::load::SizedTexture; -use egui::{Response, Ui}; +use egui::{Pos2, Rect, Response, Ui, Vec2, pos2, vec2}; -use super::{Printer, Settings, State}; +use super::panel::{MOST_COPIES, PrintPanel}; +use super::{Duplex, Printer, Settings, State}; craft_ui::words! { /// The words of the print dialog. @@ -23,9 +31,20 @@ craft_ui::words! { print: "printDialog.print" = "Print"; done: "printDialog.done" = "Done"; preview: "printDialog.preview" = "Print preview"; + image_box: "printDialog.imageBox" = "Image box"; } } +/// The index `FormOutput::picked` gives the Done button: Print is 0, Cancel 1, and the extra buttons start at 2. +const DONE_BUTTON: usize = 2; + +/// The image box of the preview. +const IMAGE: PartKey = PartKey::new("image"); + +/// How far a crop or registration mark stands from the image box, and how long it is, in screen points. +const MARK_GAP: f32 = 4.0; +const MARK_LEN: f32 = 10.0; + /// Which marks the preview draws. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct PrintMarks { @@ -62,26 +81,22 @@ pub struct PrintSheet { impl PrintSheet { /// A sheet of `paper` with the image box `image` holding `picture`, `readout` under the preview, no printable area /// and no marks. - // P3(dialogs-w16): dl.K44 `PrintSheet::new` pub fn new(paper: egui::Vec2, image: egui::Rect, picture: SizedTexture, readout: Label) -> Self { - let _ = (paper, image, picture, readout); - todo!("dl.K44") + PrintSheet { paper, printable: None, image, picture, marks: PrintMarks::default(), readout } } /// The printable area of the paper. - // P3(dialogs-w16): dl.K44 builder #[must_use] - pub fn printable(self, area: egui::Rect) -> Self { - let _ = (self, area); - todo!("dl.K44") + pub fn printable(mut self, area: egui::Rect) -> Self { + self.printable = Some(area); + self } /// The marks to draw. - // P3(dialogs-w16): dl.K44 builder #[must_use] - pub fn marks(self, marks: PrintMarks) -> Self { - let _ = (self, marks); - todo!("dl.K44") + pub fn marks(mut self, marks: PrintMarks) -> Self { + self.marks = marks; + self } } @@ -103,6 +118,217 @@ pub enum PrintFinish { Done, } +/// Where the paper stands in the preview's room: the paper's top-left corner and the screen points per paper point. +#[derive(Clone, Copy)] +struct Placement { + origin: Pos2, + scale: f32, +} + +impl Placement { + /// The screen rect of `paper`, a rect in paper points. + fn rect(self, paper: Rect) -> Rect { + Rect::from_min_size(self.origin + paper.min.to_vec2() * self.scale, paper.size() * self.scale) + } +} + +/// The style of the preview: the room it asks for. +#[derive(Clone, Debug, PartialEq, ComponentStyle)] +#[non_exhaustive] +pub(super) struct PrintPreviewStyle { + #[style(metrics)] + metrics: Metrics, +} + +/// The paper, its printable area, the picture in its box and the marks. The value is where the image box's top-left +/// corner stands on the paper, in paper points; a drag of the image box reports the positions it moves the box to as +/// one gesture, and a host check can refuse a position. +#[derive(craft_ui::contract::Component, craft_ui::contract::Props)] +#[component(content_painter)] +pub(super) struct PrintPreview<'a> { + #[common] + common: Common, + sheet: &'a PrintSheet, + /// The image box's top-left corner on the paper, in paper points. + position: Bind<'a, Pos2>, +} + +impl<'a> PrintPreview<'a> { + pub(super) fn new(label: impl Into