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

This commit is contained in:
bflatastic
2026-11-21 23:36:54 +07:00
parent 6b3c174640
commit db0fa55225
13 changed files with 49 additions and 35 deletions
@@ -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 => {}
@@ -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)
})
}
@@ -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<kurbo::Point> {
/// 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<Pos2>, closed: bool, color: Option<DataColor>, width: f32) -> Vec<Shape> {
fn run_shapes(style: &OutlineStyle, run: Vec<Pos2>, closed: bool, color: Option<DataColor>, width: f32) -> Vec<Shape> {
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<Pos2>, closed: bool, color: Option<Dat
}
/// Strokes one run; see [`run_shapes`].
fn stroke_run(painter: &ContentPainterCx<'_>, tokens: &UiTokens, run: Vec<Pos2>, closed: bool, color: Option<DataColor>, width: f32) {
painter.painter.extend(run_shapes(tokens, run, closed, color, width));
fn stroke_run(painter: &ContentPainterCx<'_>, style: &OutlineStyle, run: Vec<Pos2>, closed: bool, color: Option<DataColor>, 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<Shape> {
fn build(&self, view: &CanvasView, style: &OutlineStyle) -> Vec<Shape> {
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>() = OutlineShapes { key: Some(key), centre, shapes };
}
@@ -417,7 +426,7 @@ impl Component for SelectionOutline<'_> {
if self.revision.is_some() {
painter.painter.extend(cx.recall::<OutlineShapes>().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));
}
}
@@ -273,7 +273,8 @@ fn pasteboard_shapes(pages: Vec<PageFrame>, 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));
});
+6 -2
View File
@@ -571,8 +571,12 @@ pub fn outline(tokens: &UiTokens, shape: &PaintShape) -> Vec<Shape> {
/// 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<Shape> {
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<Shape> {
let halos = shapes.iter().flat_map(|shape| stroked(shape, halo));
halos.chain(shapes.iter().flat_map(|shape| stroked(shape, line))).collect()
}
+1 -1
View File
@@ -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;
+7 -1
View File
@@ -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");
@@ -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<String> {
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<T: Value>(bind: &mut Option<Bind<'_, T>>) -> Option<T> {
bind.as_mut().and_then(read_bind)
@@ -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)
}
@@ -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<String> {
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<String> {
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
@@ -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::<ParamWords>().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);
}
}
@@ -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<K> {
pub fn show(self, ui: &mut Ui, mut row: impl FnMut(&K) -> ListRow<'static>, mut body: impl FnMut(&mut Ui)) -> Option<K> {
let SectionList { label, source, shown, id, body_label, mut foot } = self;
let mut picked = None;
Row::new().fill().show(ui, |ui, _| {
@@ -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};