diff --git a/crates/print/src/ui/stories.rs b/crates/print/src/ui/stories.rs index bbc19e868..7e1c62fa5 100644 --- a/crates/print/src/ui/stories.rs +++ b/crates/print/src/ui/stories.rs @@ -92,15 +92,17 @@ fn print_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { PrintDialog::new(data.bind("settings", start), &printers, Bind::given(DialogFields::default())).sheet(&sheet).ready(true).show(ui).into() } +/// The artwork outlines of the sections story's document, in document points: the page inset half an inch and the +/// image box of [`sheet`]. +const SECTIONS_OUTLINES: [Rect; 2] = + [Rect::from_min_max(pos2(36.0, 36.0), pos2(576.0, 756.0)), Rect::from_min_max(pos2(72.0, 72.0), pos2(540.0, 384.0))]; + /// The sections beside the shown one, with a preset row, a one-line header and a document on three sheets. #[story(PrintDialog<'static>, covers = [], drive = Drive::Never)] fn print_dialog_sections(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let start = Settings { printer: "Office_1".to_owned(), ..Settings::default() }; let printers = printers(); - // design: allow[literal-size/vec2](page and paper sizes are document points, story data) - let outlines = - vec![Rect::from_min_size(pos2(36.0, 36.0), Vec2::new(540.0, 720.0)), Rect::from_min_size(pos2(72.0, 72.0), Vec2::new(468.0, 312.0))]; - let sheet = sheet(ui, true).count(3).outlines(outlines); + let sheet = sheet(ui, true).count(3).outlines(SECTIONS_OUTLINES.to_vec()); let rows = [PresetRow::item("Default".to_owned(), "Default", 0), PresetRow::item("Proof".to_owned(), "Proof", 0)]; let built_in = ["Default".to_owned()]; let header = [Param::number("pagesPerSheet", "Pages per sheet", 1.0, 1.0, 0)]; diff --git a/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs b/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs index 19a4d128c..292d23f80 100644 --- a/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs +++ b/crates/ui-canvas/src/canvas_controls/task_bar/stories.rs @@ -128,11 +128,14 @@ fn host_rows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { configured(ui, data, &turned_frame(), None, |bar| bar.more_rows(rows.clone())) } +/// How far the beside-a-point story moves the frame to the right, in document points: near the canvas's right edge. +const NEAR_RIGHT_EDGE: Vec2 = Vec2::new(300.0, 0.0); + /// A bar beside the frame's right end, near the canvas's right edge so it flips to the other side, keeping clear of a /// point. #[story(TaskBar<'static>, covers = [], drive = Drive::Never)] fn beside_a_point(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - let corners = turned_frame().map(|corner| corner + Vec2::new(300.0, 0.0)); + let corners = turned_frame().map(|corner| corner + NEAR_RIGHT_EDGE); let point = corners[0]; configured(ui, data, &corners, None, |bar| bar.side(Side::End, Align::Start).keep_clear(point)) } diff --git a/crates/ui-panels/src/dialog/trials.rs b/crates/ui-panels/src/dialog/trials.rs index 643a079dd..83d776e41 100644 --- a/crates/ui-panels/src/dialog/trials.rs +++ b/crates/ui-panels/src/dialog/trials.rs @@ -16,7 +16,7 @@ use crate::testing::relations::{aligned_left, apart_above, grows_with, inside, o use crate::testing::{Fixture, Frames, trial}; use crate::text::TextField; use craft_behavior::ColumnWidth; -use egui::{Key, Modifiers, Rect, Ui}; +use egui::{Key, Modifiers, Rect, Ui, Vec2}; use std::cell::Cell; #[trial] @@ -370,6 +370,21 @@ fn a_reopened_dialog_focuses_its_first_enabled_field_again() { assert!(on_second(&fixture), "and takes it again after a reopen"); } +/// The window of the title-band trial: room around the dialog to move it in. +const BAND_ROOM: Vec2 = Vec2::new(900.0, 700.0); +/// Where a drag in the body starts, from the middle of the dialog's bottom edge: inside the body, far from the title. +const IN_BODY: Vec2 = Vec2::new(0.0, -6.0); +/// The drag that starts in the body. +const BODY_DRAG: Vec2 = Vec2::new(60.0, 40.0); +/// The drag of the title band. +const BAND_DRAG: Vec2 = Vec2::new(80.0, 50.0); +/// A drag of the title band far past every edge of the window. +const PAST_THE_EDGE: Vec2 = Vec2::new(5000.0, 5000.0); +/// The window of the tall-body trial: lower than the body. +const SHORT_ROOM: Vec2 = Vec2::new(600.0, 320.0); +/// One wheel turn down the body. +const WHEEL_DOWN: Vec2 = Vec2::new(0.0, -400.0); + #[trial] fn a_dialog_moves_by_its_title_band_stays_on_screen_and_reopens_where_left() { let open = std::rc::Rc::new(Cell::new(true)); @@ -380,7 +395,7 @@ fn a_dialog_moves_by_its_title_band_stays_on_screen_and_reopens_where_left() { Text::new("Body text").show(ui); }, ); - fixture.room(egui::vec2(900.0, 700.0)); + fixture.room(BAND_ROOM); fixture.settle(); let dialog = |fixture: &Fixture| fixture.by_role(Role::DIALOG).into_iter().next().expect("the dialog is shown").rect; let band = |fixture: &Fixture| { @@ -388,17 +403,17 @@ fn a_dialog_moves_by_its_title_band_stays_on_screen_and_reopens_where_left() { }; let start = dialog(&fixture); - let from = start.center_bottom() - egui::vec2(0.0, 6.0); - fixture.drag_at(from, egui::vec2(60.0, 40.0)).settle(); + let from = start.center_bottom() + IN_BODY; + fixture.drag_at(from, BODY_DRAG).settle(); assert_eq!(dialog(&fixture), start, "a drag that starts in the body moves nothing"); let title = band(&fixture); - fixture.drag(&title, egui::vec2(80.0, 50.0)).settle(); + fixture.drag(&title, BAND_DRAG).settle(); let moved = dialog(&fixture); - assert_eq!(moved.min - start.min, egui::vec2(80.0, 50.0), "a drag of the band moves the dialog by it"); + assert_eq!(moved.min - start.min, BAND_DRAG, "a drag of the band moves the dialog by it"); let title = band(&fixture); - fixture.drag(&title, egui::vec2(5000.0, 5000.0)).settle(); + fixture.drag(&title, PAST_THE_EDGE).settle(); let screen = fixture.ctx().content_rect(); assert!(screen.contains_rect(dialog(&fixture)), "a drag past the edge stops at it: {:?} in {screen:?}", dialog(&fixture)); @@ -425,7 +440,7 @@ fn a_tall_body_scrolls_under_a_footer_that_stays_in_view() { } }, ); - fixture.room(egui::vec2(600.0, 320.0)); + fixture.room(SHORT_ROOM); fixture.settle(); let first = |fixture: &Fixture| fixture.by_label("Line 0").map(|target| target.rect); let at_top = first(&fixture).expect("the first line is shown"); @@ -437,7 +452,7 @@ fn a_tall_body_scrolls_under_a_footer_that_stays_in_view() { let over = fixture.by_role(Role::DIALOG).into_iter().next().expect("the dialog is shown").rect.center(); let wheel = egui::Event::MouseWheel { unit: egui::MouseWheelUnit::Point, - delta: egui::vec2(0.0, -400.0), + delta: WHEEL_DOWN, phase: egui::TouchPhase::Move, modifiers: Modifiers::NONE, source: egui::MouseWheelSource::Wheel, diff --git a/crates/ui-panels/src/rails/tool/stories.rs b/crates/ui-panels/src/rails/tool/stories.rs index 403fa6020..65ad66d16 100644 --- a/crates/ui-panels/src/rails/tool/stories.rs +++ b/crates/ui-panels/src/rails/tool/stories.rs @@ -71,7 +71,6 @@ fn captioned_slots() -> Vec> { fn in_columns(ui: &mut Ui, columns: u8, cells: usize, height: Option, rail: ToolRail<'_, u8>) -> ToolRailOutput { let width = DockGrid::rail(cells).resolved(&DockSizes::of_scope(ui)).width(u16::from(columns)); let room = Flow::new(ui.available_rect_before_wrap(), Env::of(ui).direction.is_rtl()).span(0.0, width); - // design: allow[contract/memory](the story gives the rail the width of its chosen columns, as a dock column does) ui.scope_builder(UiBuilder::new().max_rect(room), |ui| { if let Some(height) = height { ui.set_max_height(height); diff --git a/crates/ui-panels/src/rails/tool/trials.rs b/crates/ui-panels/src/rails/tool/trials.rs index fa7669395..3a973eccb 100644 --- a/crates/ui-panels/src/rails/tool/trials.rs +++ b/crates/ui-panels/src/rails/tool/trials.rs @@ -183,7 +183,7 @@ fn captions_take_room_only_while_the_rail_shows_them() { fixture.room(Vec2::new(width, 800.0)).settle(); let [none, off, on] = measured.get(); assert!(near(off.y, none.y), "a caption takes no room while captions are off: {off:?} against {none:?}"); - assert!(on.y >= off.y + 1.0, "a shown caption adds its row: {on:?} against {off:?}"); + assert!(on.y > off.y && !near(on.y, off.y), "a shown caption adds its row: {on:?} against {off:?}"); let (rail, caption) = (rect(&fixture, "Tools"), rect(&fixture, CAPTION)); assert!(rail.contains_rect(caption), "the caption {caption:?} is cut at the rail's width {rail:?}"); assert!(above(caption, rect(&fixture, "Move")), "the caption heads its group"); diff --git a/design/exceptions/craft-ui-panels/rails.toml b/design/exceptions/craft-ui-panels/rails.toml index 29dafe7a8..8fd2a55ab 100644 --- a/design/exceptions/craft-ui-panels/rails.toml +++ b/design/exceptions/craft-ui-panels/rails.toml @@ -1,13 +1,5 @@ config_version = 1 -[[exception]] -name = "tool-rail-story-width" -kind = "marker" -rule = "contract/memory" -path = "crates/ui-panels/src/rails/tool/stories.rs" -reason = "The story gives the rail the width of its chosen columns, as a dock column does." -count = 1 - [[exception]] name = "tool-rail-trial-rooms" kind = "exempt"