From db0fa5522594fa22dc44c5f38bd2193fcad0f546 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 21 Nov 2026 23:36:54 +0700 Subject: [PATCH] Fix late-set calls: wheel event fields, shows_outside flag, outline tokens read in style, one warning_lines, help icon button, section list row lifetime, callout Props import --- crates/ui-canvas/src/canvas/pasteboard/mod.rs | 2 +- .../src/canvas/pasteboard/stories.rs | 2 +- .../src/canvas_controls/outline/mod.rs | 35 ++++++++++++------- .../ui-canvas/tests/it/canvas/pasteboard.rs | 3 +- crates/ui-contract/src/primitives/kit.rs | 8 +++-- crates/ui-contract/src/primitives/mod.rs | 2 +- crates/ui-panels/src/dialog/trials.rs | 8 ++++- .../src/patterns/form_dialogs/pdf_export.rs | 5 --- .../form_dialogs/pdf_export/hosted.rs | 3 +- .../form_dialogs/pdf_export/summary.rs | 8 ++--- .../src/patterns/form_dialogs/rows.rs | 4 +-- .../src/patterns/form_dialogs/section_list.rs | 2 +- .../src/patterns/panels/palette/callout.rs | 2 +- 13 files changed, 49 insertions(+), 35 deletions(-) diff --git a/crates/ui-canvas/src/canvas/pasteboard/mod.rs b/crates/ui-canvas/src/canvas/pasteboard/mod.rs index 399981438..fcfbb0133 100644 --- a/crates/ui-canvas/src/canvas/pasteboard/mod.rs +++ b/crates/ui-canvas/src/canvas/pasteboard/mod.rs @@ -500,7 +500,7 @@ impl Component for Pasteboard<'_> { match page.fill { Some(PageFill::Color(color)) => draw.data_fill(&polygon(&quad), color), Some(PageFill::Checker(checker)) => { - let grid = checker.shape(edges.painter.ctx(), &cx.env.tokens, CheckerArea::Quad(quad), page_corner(&view, page)); + let grid = checker.shape(edges.painter.ctx(), &ui.env.tokens, CheckerArea::Quad(quad), page_corner(&view, page)); edges.painter.add(grid); } None => {} diff --git a/crates/ui-canvas/src/canvas/pasteboard/stories.rs b/crates/ui-canvas/src/canvas/pasteboard/stories.rs index a1b3d333c..3740fc583 100644 --- a/crates/ui-canvas/src/canvas/pasteboard/stories.rs +++ b/crates/ui-canvas/src/canvas/pasteboard/stories.rs @@ -111,7 +111,7 @@ fn artboards_show_outside(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let border = border_of(data, PageBorder::DropShadow); let pages: &[PageFrame] = data.value("pages", boards()); on_canvas_view(ui, view, Some(&StoryDocument::STANDARD), |ui, at, _| { - Pasteboard::new("Pasteboard", pages).shows_outside(true).border(border).show_at(ui, at) + Pasteboard::new("Pasteboard", pages).shows_outside().border(border).show_at(ui, at) }) } diff --git a/crates/ui-canvas/src/canvas_controls/outline/mod.rs b/crates/ui-canvas/src/canvas_controls/outline/mod.rs index d65b48a3c..efc02a9fd 100644 --- a/crates/ui-canvas/src/canvas_controls/outline/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/outline/mod.rs @@ -9,10 +9,10 @@ pub(super) mod stories; use crate::canvas::canvas_space; use crate::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role}; use crate::primitives::textures::{Revision, TextureStore, TextureStoreOptions, UNTINTED}; -use crate::primitives::{ContentPainterCx, Dashes, PaintShape, dashed, outline}; +use crate::primitives::{ContentPainterCx, Dashes, PaintShape, dashed, outline_with}; use crate::runtime::env::Label; use crate::runtime::memory::Remember as _; -use crate::style::{ComponentStyle, DataColor, StyleColor, StyleCx, UiTokens}; +use crate::style::{ComponentStyle, DataColor, StyleColor, StyleCx}; use craft_behavior::kurbo::{self, BezPath, PathEl, Point, Rect}; use craft_behavior::{CanvasView, Input, Metrics}; use egui::epaint::Vertex; @@ -67,6 +67,9 @@ pub struct OutlineStyle { metrics: Metrics, /// The line colour of a shape the host gives no colour: the accent as a bare line. line: StyleColor, + /// The colour of the halo under that line, and its width. + halo: StyleColor, + thick: f32, /// The width of a hover line and of a dashed selection line. medium: f32, /// The width of a solid selection line. @@ -81,6 +84,8 @@ fn outline_style(cx: &StyleCx<'_>) -> OutlineStyle { OutlineStyle { metrics: Metrics::new(), line: cx.color(cx.tokens.color.overlay.line), + halo: cx.color(cx.tokens.color.overlay.halo), + thick: stroke.thick, medium: stroke.medium, thin: stroke.thin, dash: stroke.dash, @@ -153,9 +158,13 @@ fn segment_hull(from: kurbo::Point, segment: PathEl) -> Vec { /// The shapes of one run: the kit's halo-and-line outline in the overlay colours, or a line of the host's `color` /// alone. -fn run_shapes(tokens: &UiTokens, run: Vec, closed: bool, color: Option, width: f32) -> Vec { +fn run_shapes(style: &OutlineStyle, run: Vec, closed: bool, color: Option, width: f32) -> Vec { match color { - None => outline(tokens, &if closed { PaintShape::Polygon(run) } else { PaintShape::Path(run) }), + None => outline_with( + Stroke::new(style.thick, style.halo.egui()), + Stroke::new(style.medium, style.line.egui()), + &[if closed { PaintShape::Polygon(run) } else { PaintShape::Path(run) }], + ), Some(color) => { let stroke = Stroke::new(width, color.0); vec![if closed { Shape::closed_line(run, stroke) } else { Shape::line(run, stroke) }] @@ -164,8 +173,8 @@ fn run_shapes(tokens: &UiTokens, run: Vec, closed: bool, color: Option, tokens: &UiTokens, run: Vec, closed: bool, color: Option, width: f32) { - painter.painter.extend(run_shapes(tokens, run, closed, color, width)); +fn stroke_run(painter: &ContentPainterCx<'_>, style: &OutlineStyle, run: Vec, closed: bool, color: Option, width: f32) { + painter.painter.extend(run_shapes(style, run, closed, color, width)); } fn tint(mask: &HoverMask, color: Color32) -> ColorImage { @@ -251,11 +260,11 @@ impl Component for HoverOutline { let (half_y, half_x) = (view.doc_len(style.medium / 2.0), f64::from(style.medium / 2.0) / view.zoom_x()); let rect = rect.abs(); let grown = Rect::new(rect.x0 - half_x, rect.y0 - half_y, rect.x1 + half_x, rect.y1 + half_y); - stroke_run(&painter, &cx.env.tokens, view.quad(grown).to_vec(), true, self.color, style.medium); + stroke_run(&painter, style, view.quad(grown).to_vec(), true, self.color, style.medium); } HoverShape::Path(path) => { for (points, closed) in path_runs(&view, path) { - stroke_run(&painter, &cx.env.tokens, points, closed, self.color, style.medium); + stroke_run(&painter, style, points, closed, self.color, style.medium); } } HoverShape::Mask(mask) => paint_mask(&painter, &view, mask, self.color.map_or(style.line.egui(), |color| color.0)), @@ -330,12 +339,12 @@ impl<'a> SelectionOutline<'a> { impl SelectionOutline<'_> { /// The shapes of the paths, then of the key path, under `view`. - fn build(&self, view: &CanvasView, tokens: &UiTokens, style: &OutlineStyle) -> Vec { + fn build(&self, view: &CanvasView, style: &OutlineStyle) -> Vec { let mut shapes = Vec::new(); for path in self.paths { for (mut points, closed) in path_runs(view, path) { match self.look { - SelectionOutlineLook::Solid => shapes.extend(run_shapes(tokens, points, closed, self.color, style.thin)), + SelectionOutlineLook::Solid => shapes.extend(run_shapes(style, points, closed, self.color, style.thin)), SelectionOutlineLook::Dashed => { if closed { points.extend(points.first().copied()); @@ -348,7 +357,7 @@ impl SelectionOutline<'_> { } if let Some(key) = self.key { for (points, closed) in path_runs(view, key) { - shapes.extend(run_shapes(tokens, points, closed, self.color, style.medium)); + shapes.extend(run_shapes(style, points, closed, self.color, style.medium)); } } shapes @@ -407,7 +416,7 @@ impl Component for SelectionOutline<'_> { return; } } - let shapes = Arc::new(self.build(&space.view, &cx.env.tokens, &key.style)); + let shapes = Arc::new(self.build(&space.view, &key.style)); *cx.memory::() = OutlineShapes { key: Some(key), centre, shapes }; } @@ -417,7 +426,7 @@ impl Component for SelectionOutline<'_> { if self.revision.is_some() { painter.painter.extend(cx.recall::().shapes.iter().cloned()); } else { - painter.painter.extend(self.build(&space.view, &cx.env.tokens, &cx.style)); + painter.painter.extend(self.build(&space.view, cx.style)); } } diff --git a/crates/ui-canvas/tests/it/canvas/pasteboard.rs b/crates/ui-canvas/tests/it/canvas/pasteboard.rs index 212572790..b97fda7e3 100644 --- a/crates/ui-canvas/tests/it/canvas/pasteboard.rs +++ b/crates/ui-canvas/tests/it/canvas/pasteboard.rs @@ -273,7 +273,8 @@ fn pasteboard_shapes(pages: Vec, shows_outside: bool) -> (CanvasView, let view = CanvasView::new(egui::Rect::from_min_size(Pos2::ZERO, room), Point::new(200.0, 150.0), 1.0); let mut fixture = Fixture::new(move |ui| { Canvas::new("Document").view(view).pasteboard(PasteboardColor::DarkGray).show(ui, |ui, body| { - let _ = Pasteboard::new("Pasteboard", &pages).shows_outside(shows_outside).show_at(ui, body.rect); + let pasteboard = Pasteboard::new("Pasteboard", &pages); + let _ = if shows_outside { pasteboard.shows_outside() } else { pasteboard }.show_at(ui, body.rect); let paint = AppPaint::new(|painter, view: CanvasView| { painter.painter.add(Shape::rect_filled(view.rect, 0.0, PICTURE)); }); diff --git a/crates/ui-contract/src/primitives/kit.rs b/crates/ui-contract/src/primitives/kit.rs index a20d020f3..a7ce5375f 100644 --- a/crates/ui-contract/src/primitives/kit.rs +++ b/crates/ui-contract/src/primitives/kit.rs @@ -571,8 +571,12 @@ pub fn outline(tokens: &UiTokens, shape: &PaintShape) -> Vec { /// The outline of [`outline`] with the line in `line`, a colour the user picked (a Navigator proxy colour), over the /// overlay halo. Every halo is drawn under every line, so the edges of one mark that meet or cross stay unbroken. pub fn outline_in(tokens: &UiTokens, shapes: &[PaintShape], line: Color32) -> Vec { - let halo = Stroke::new(tokens.stroke.thick, rgba_color(tokens.color.overlay.halo)); - let line = Stroke::new(tokens.stroke.medium, line); + outline_with(Stroke::new(tokens.stroke.thick, rgba_color(tokens.color.overlay.halo)), Stroke::new(tokens.stroke.medium, line), shapes) +} + +/// The outline of `shapes` with the strokes given: the halo under the line. For a component that keeps shapes built in +/// `update`, where only `style` has read the tokens. +pub fn outline_with(halo: Stroke, line: Stroke, shapes: &[PaintShape]) -> Vec { let halos = shapes.iter().flat_map(|shape| stroked(shape, halo)); halos.chain(shapes.iter().flat_map(|shape| stroked(shape, line))).collect() } diff --git a/crates/ui-contract/src/primitives/mod.rs b/crates/ui-contract/src/primitives/mod.rs index 9d0a6494b..b84095f51 100644 --- a/crates/ui-contract/src/primitives/mod.rs +++ b/crates/ui-contract/src/primitives/mod.rs @@ -43,7 +43,7 @@ pub use icon::{Glyph, IconSet, IconSource, IconSpec, Mirror, has_icon, icon_name pub use ime_surface::ImeSurface; pub use kit::{ Checker, CheckerArea, GridAxis, GridInk, GridLines, GridLook, GridStroke, MAX_LINES, Tick, TickEdge, TickRank, dashed, drop_mark, ellipse, - fill_polygon, grid_lines, grid_lines_with, marching_ants, outline, ramp, ticks, + fill_polygon, grid_lines, grid_lines_with, marching_ants, outline, outline_with, ramp, ticks, }; pub use marker::{Marker, MarkerSize}; pub use paint_slot::PaintSlot; diff --git a/crates/ui-panels/src/dialog/trials.rs b/crates/ui-panels/src/dialog/trials.rs index 7a7cced78..e602549f4 100644 --- a/crates/ui-panels/src/dialog/trials.rs +++ b/crates/ui-panels/src/dialog/trials.rs @@ -429,7 +429,13 @@ fn a_tall_body_scrolls_under_a_footer_that_stays_in_view() { assert!(fixture.by_label("Line 59").is_none_or(|last| !screen.contains_rect(last.rect)), "the body does not all fit: it scrolls"); 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), modifiers: Modifiers::NONE }; + let wheel = egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + delta: egui::vec2(0.0, -400.0), + phase: egui::TouchPhase::Move, + modifiers: Modifiers::NONE, + source: egui::MouseWheelSource::Wheel, + }; fixture.frame(vec![egui::Event::PointerMoved(over), wheel]).settle(); assert_ne!(first(&fixture), Some(at_top), "the wheel scrolled the body"); assert!(screen.contains_rect(fixture.by_label("OK").expect("the footer is shown").rect), "the footer stays in view while the body scrolls"); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs index c10269dda..f00fa1ec2 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs @@ -167,11 +167,6 @@ pub(crate) fn apply_standard(settings: &mut PdfSettings) { } } -/// The warnings of `settings`, worded, then the host's: what the Summary shows and Save Summary… writes. -pub(super) fn warning_lines(words: &PdfExportWords, settings: &PdfSettings, catalog: &dyn ProfileCatalog, host: &[String]) -> Vec { - settings.warnings(catalog).iter().map(|warning| words.warning_text(warning)).chain(host.iter().cloned()).collect() -} - /// The value `bind` holds, when it is bound and holds one. fn bound_value(bind: &mut Option>) -> Option { bind.as_mut().and_then(read_bind) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs index cfa8b7e28..bd8fba8cb 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/hosted.rs @@ -244,8 +244,7 @@ impl HostedPdfExport { /// The Summary's text for the dialog's settings, as Save Summary… saves it, worded by `words`. pub fn summary_text(&self, words: &PdfExportWords) -> String { - let mut warnings = warning_lines(words, &self.settings, Self::catalog_of(&self.catalog)); - warnings.extend(self.host_warnings.iter().cloned()); + let warnings = warning_lines(words, &self.settings, Self::catalog_of(&self.catalog), &self.host_warnings); summary_text(words, &self.settings, &self.base(), &warnings) } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/summary.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/summary.rs index cb494cb6a..63ccc1463 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/summary.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/summary.rs @@ -19,10 +19,10 @@ enum Shown { }, } -/// The worded warnings of `settings` against `catalog`: the Summary's warnings, and what Save Summary… appends the -/// host's to. -pub(super) fn warning_lines(words: &PdfExportWords, settings: &PdfSettings, catalog: &dyn ProfileCatalog) -> Vec { - settings.warnings(catalog).iter().map(|warning| words.warning_text(warning)).collect() +/// The warnings of `settings` against `catalog`, worded, then the host's: what the Summary shows and Save Summary… +/// writes. +pub(super) fn warning_lines(words: &PdfExportWords, settings: &PdfSettings, catalog: &dyn ProfileCatalog, host: &[String]) -> Vec { + settings.warnings(catalog).iter().map(|warning| words.warning_text(warning)).chain(host.iter().cloned()).collect() } /// The Summary's lines for `settings` against `base`, then the `warnings`, with LF line breaks (CR and CRLF in values diff --git a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs index 4850dac66..94d9ee589 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs @@ -10,7 +10,7 @@ use crate::runtime::requests::{ColorRequest, EyedropperRequest, ListingRequest, use super::param::{CustomContext, Head, Lifted, Param, ParamKind, fill_defaults, path_list, rounded}; use super::path_row::PathRow; use super::words::ParamWords; -use crate::buttons::{Button, ToggleButton}; +use crate::buttons::{Button, IconButton, ToggleButton}; use crate::choice::{Checkbox, Radio, RadioGroup, Swatch}; use crate::contract::{ Bind, BodyCx, CanvasGesture, Entry, FieldLayout, NoValue, Outcome, Props as _, Remember as _, Sampler as _, Show as _, ShowContainer as _, @@ -361,7 +361,7 @@ impl Line<'_> { /// The help button after a row's control: a press is noted for the pass, which reports the row's link. fn help_button(&self, ui: &mut Ui) { let help = Env::of(ui).words::().help.clone(); - if clicked(&Button::new(help).icon(IconId::new("help")).icon_only().id_salt("help").show(ui)) { + if clicked(&IconButton::new(IconId::new("help")).label(help).id_salt("help").show(ui)) { self.helped.set(true); } } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/section_list.rs b/crates/ui-patterns/src/patterns/form_dialogs/section_list.rs index 5649c5bc7..f5dbafab2 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/section_list.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/section_list.rs @@ -62,7 +62,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> SectionList<'a, K> { /// Shows the list with a row per section from `row` and `body` beside it; the section picked this pass. // PLAN: ty.X70 gives `body: impl FnOnce`; a container runs its body again for a measuring pass, so `body` and // `foot` are `FnMut`. - pub fn show(self, ui: &mut Ui, mut row: impl FnMut(&K) -> ListRow, mut body: impl FnMut(&mut Ui)) -> Option { + pub fn show(self, ui: &mut Ui, mut row: impl FnMut(&K) -> ListRow<'static>, mut body: impl FnMut(&mut Ui)) -> Option { let SectionList { label, source, shown, id, body_label, mut foot } = self; let mut picked = None; Row::new().fill().show(ui, |ui, _| { diff --git a/crates/ui-patterns/src/patterns/panels/palette/callout.rs b/crates/ui-patterns/src/patterns/panels/palette/callout.rs index 728ecbae3..4c4571562 100644 --- a/crates/ui-patterns/src/patterns/panels/palette/callout.rs +++ b/crates/ui-patterns/src/patterns/panels/palette/callout.rs @@ -1,7 +1,7 @@ //! The callout of the palette's active row: the mark on its shown control and the box beside it. use super::super::tour; -use crate::contract::{Bind, Show as _, ShowContainer as _}; +use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _}; use crate::display::{TargetMark, Text}; use crate::popover::Popover; use crate::runtime::commands::{self, CommandRef};