From c6250e81b9fd04def10464ee427807e0a8864515 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 23:01:15 -0500 Subject: [PATCH] fw sync, fw-widgets: merge origin/next into the port's ui-widgets Union of both sides in buttons, swatches, picture, lists and rows, menus, notices, date picker, popup list, tabs, text fields and the tile grid, and their stories and trials. Picture keeps upstream's Rendered source and the port's Svg source on the shared packed store. Swatches take upstream's hexagon shape with the port's WellFill and icon cells. Tab strips take upstream's Fitting (ghosts, kept tabs, end items) with the port's document tab gap; tabs take upstream's place() with the port's marker dot. Menu rows keep the port's RowInput with upstream's pointer-driven activation. Test module lists are the union, pub(crate). --- crates/ui-widgets/src/buttons/button.rs | 12 -- crates/ui-widgets/src/buttons/mod.rs | 6 +- crates/ui-widgets/src/buttons/stories.rs | 14 +- crates/ui-widgets/src/choice/swatch.rs | 53 +++--- crates/ui-widgets/src/choice/swatch_table.rs | 44 +---- .../src/choice/swatch_table/stories.rs | 6 +- crates/ui-widgets/src/controls/disclosure.rs | 7 +- crates/ui-widgets/src/display/picture.rs | 70 +++----- .../ui-widgets/src/display/picture/stories.rs | 23 ++- crates/ui-widgets/src/display/text.rs | 21 +-- crates/ui-widgets/src/list/mod.rs | 7 +- crates/ui-widgets/src/list/row.rs | 4 - crates/ui-widgets/src/list/row/paint.rs | 9 +- crates/ui-widgets/src/list/row/show.rs | 6 +- crates/ui-widgets/src/list/row/style.rs | 6 +- crates/ui-widgets/src/list/stories.rs | 7 +- crates/ui-widgets/src/list/view.rs | 6 +- crates/ui-widgets/src/list/view_stories.rs | 24 +-- crates/ui-widgets/src/menu/item.rs | 26 +-- crates/ui-widgets/src/menu/mod.rs | 10 +- crates/ui-widgets/src/menu/stories.rs | 8 +- crates/ui-widgets/src/notices/notice.rs | 11 +- crates/ui-widgets/src/pickers/date.rs | 69 -------- crates/ui-widgets/src/pickers/date/stories.rs | 5 - crates/ui-widgets/src/popover/popup_list.rs | 5 +- .../src/popover/popup_list/stories.rs | 6 +- crates/ui-widgets/src/tabs/rules.rs | 14 +- crates/ui-widgets/src/tabs/strip.rs | 80 +++------ crates/ui-widgets/src/tabs/tab.rs | 111 ++---------- crates/ui-widgets/src/text/mod.rs | 10 +- crates/ui-widgets/src/text/number.rs | 11 +- crates/ui-widgets/src/text/text_field.rs | 6 +- .../ui-widgets/src/text/text_field/stories.rs | 6 +- crates/ui-widgets/src/text/zoom_field.rs | 21 +-- crates/ui-widgets/src/tile_grid/grid.rs | 41 +---- crates/ui-widgets/src/tile_grid/tile.rs | 70 +++----- crates/ui-widgets/tests/it/access/mod.rs | 9 +- crates/ui-widgets/tests/it/bars/bar.rs | 5 +- crates/ui-widgets/tests/it/commands/mod.rs | 6 +- crates/ui-widgets/tests/it/label/hit.rs | 5 +- crates/ui-widgets/tests/it/label/tooltip.rs | 5 +- crates/ui-widgets/tests/it/list.rs | 5 +- crates/ui-widgets/tests/it/main.rs | 23 +-- crates/ui-widgets/tests/it/menu/mod.rs | 8 +- crates/ui-widgets/tests/it/menu/rows.rs | 5 +- crates/ui-widgets/tests/it/pickers/mod.rs | 11 +- crates/ui-widgets/tests/it/picture.rs | 23 +-- crates/ui-widgets/tests/it/tabs.rs | 163 +++++++++--------- crates/ui-widgets/tests/it/text/mod.rs | 17 +- crates/ui-widgets/tests/it/text/text_field.rs | 5 +- crates/ui-widgets/tests/it/tile_grid/tile.rs | 5 +- 51 files changed, 299 insertions(+), 831 deletions(-) diff --git a/crates/ui-widgets/src/buttons/button.rs b/crates/ui-widgets/src/buttons/button.rs index 816b642597..c24f7ecdef 100644 --- a/crates/ui-widgets/src/buttons/button.rs +++ b/crates/ui-widgets/src/buttons/button.rs @@ -298,17 +298,6 @@ impl Component for Button<'_> { if self.loading { Sense::FOCUS } else { Sense::CLICK | Sense::FOCUS } } -<<<<<<< HEAD - /// A loading button declares the slot of its spinner, which paints as the face of its part. - fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) { - if !self.loading { - return; - } - let (content, rtl) = (cx.content_rect, cx.flow.is_rtl()); - let spinner = face::spinner_rect(cx, &self.spec(cx.resolved.label), &cx.style.face, cx.style.icon.side, content, rtl); - if let Some(rect) = spinner { - cx.part(SPINNER, rect); -======= /// A loading button declares the slot of its spinner, which paints as the face of that part; any other button with /// a picture declares the picture's box, where `paint` shows it. fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) { @@ -322,7 +311,6 @@ impl Component for Button<'_> { && let Some(rect) = face::lead_rect(cx, &self.spec(cx.resolved.label, cx.style), &cx.style.face, cx.style.icon.side, area, rtl) { cx.part(PICTURE, rect); ->>>>>>> origin/next } } diff --git a/crates/ui-widgets/src/buttons/mod.rs b/crates/ui-widgets/src/buttons/mod.rs index 40a060efae..63ba54f2a2 100644 --- a/crates/ui-widgets/src/buttons/mod.rs +++ b/crates/ui-widgets/src/buttons/mod.rs @@ -15,13 +15,9 @@ use crate::contract::MemoProps; use crate::runtime::env::EnvValue; pub use button::{Button, ButtonOutput, ButtonStyle}; -<<<<<<< HEAD pub use command_search::{CommandSearch, CommandSearchStyle}; -pub use icon_button::{IconButton, IconButtonStyle, PopupMark, PressFocus}; -======= pub use face::Arrangement; -pub use icon_button::{IconButton, IconButtonStyle, PopupMark}; ->>>>>>> origin/next +pub use icon_button::{IconButton, IconButtonStyle, PopupMark, PressFocus}; pub use link::{Link, LinkStyle}; pub use split_button::{SplitButton, SplitButtonStyle, SplitMenu, SplitOutput}; pub use toggle_button::{ToggleButton, ToggleButtonStyle}; diff --git a/crates/ui-widgets/src/buttons/stories.rs b/crates/ui-widgets/src/buttons/stories.rs index 313e25f890..9b9ce90a36 100644 --- a/crates/ui-widgets/src/buttons/stories.rs +++ b/crates/ui-widgets/src/buttons/stories.rs @@ -1,16 +1,7 @@ //! Stories of the buttons. -<<<<<<< HEAD -use super::{Button, CommandSearch, IconButton, Link, PressFocus, SplitButton, ToggleButton}; -use crate::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Validity}; -use crate::display::{Shade, Text}; -use crate::layout_components::{Grid, Row}; -use crate::primitives::IconSpec; -use crate::runtime::env::Message; -use crate::style::DataColor; -======= -use super::{Arrangement, Button, ControlPlace, GroupLevel, IconButton, Link, SplitButton, SplitMenu, ToggleButton}; -use crate::contract::{BodyCx, Entry, LeastWidth, Props as _, Show as _, ShowContainer as _, Sizing, Validity}; +use super::{Arrangement, Button, CommandSearch, ControlPlace, GroupLevel, IconButton, Link, PressFocus, SplitButton, SplitMenu, ToggleButton}; +use crate::contract::{Bind, BodyCx, Entry, LeastWidth, Props as _, Show as _, ShowContainer as _, Sizing, Validity}; use crate::display::{Picture, Shade, Text}; use crate::layout_components::{Grid, Row, Stack}; use crate::list::ThumbAspect; @@ -20,7 +11,6 @@ use crate::runtime::commands::EditCommands; use crate::runtime::env::{Message, with_env}; use crate::style::{DataColor, SurfaceKind}; use crate::testing::pictures::sample_picture; ->>>>>>> origin/next use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story}; use craft_behavior::{ColumnWidth, IconId, Mixed, Proposal}; use craft_theme::{ControlSize, Variant}; diff --git a/crates/ui-widgets/src/choice/swatch.rs b/crates/ui-widgets/src/choice/swatch.rs index 6bbfa24b30..c46c18cb1b 100644 --- a/crates/ui-widgets/src/choice/swatch.rs +++ b/crates/ui-widgets/src/choice/swatch.rs @@ -312,12 +312,9 @@ impl Component for Swatch { } fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { -<<<<<<< HEAD let fill = if self.icon.is_some() { WellFill::Empty } else { well_fill(self.color) }; - paint_face(&ui.draw(), cx.rect, cx.style, cx.state(), fill, self.icon.as_ref(), self.marked); -======= - paint_face(&ui.draw(), cx.rect, cx.style, cx.state(), self.color, self.marked, self.shape); ->>>>>>> origin/next + let face = WellFace { fill, glyph: self.icon.as_ref(), shape: self.shape }; + paint_face(&ui.draw(), cx.rect, cx.style, cx.state(), face, self.marked); } fn finish(self, cx: Cx<'_, Self>) -> SwatchOutput { @@ -329,7 +326,6 @@ impl Component for Swatch { } } -<<<<<<< HEAD /// What the well of a swatch of `color` shows: the colour, the "no colour" diagonal, or the mixed dash. fn well_fill(color: Mixed>) -> WellFill { match color { @@ -339,32 +335,32 @@ fn well_fill(color: Mixed>) -> WellFill { } } -/// The one swatch face painter: the well `fill` in `well` (a checkerboard behind a translucent colour, the dash of a -/// mixed one, the diagonal of none), the `glyph` of an icon cell in the text colour, then the outline ring, the mark +/// What a swatch's well shows, and its shape. +struct WellFace<'a> { + fill: WellFill, + /// The glyph of an icon cell, over the empty well. + glyph: Option<&'a IconId>, + shape: SwatchShape, +} + +/// The one swatch face painter: the well `face.fill` in `well` (a checkerboard behind a translucent colour, the dash of +/// a mixed one, the diagonal of none), the glyph of an icon cell in the text colour, then the outline ring, the mark /// when `marked`, and the selection ring, in `state`. -fn paint_face(draw: &Draw<'_>, well: Rect, style: &SwatchStyle, state: &StateSet, fill: WellFill, glyph: Option<&IconId>, marked: bool) { - let shape = PaintShape::Rect(well, style.radius); - draw.swatch_well(well, style.radius, fill); - if let Some(glyph) = glyph { - let side = style.glyph.min(well.width()).min(well.height()); - draw.icon(Rect::from_center_size(well.center(), Vec2::splat(side)), &IconSpec::svg(glyph.clone()).color(style.mark)); - } - draw.stroke(&shape, StrokeWidth::Thin, state.resolve(&style.edge)); -======= -/// The one swatch face painter: the well of `color` in `well` (a checkerboard behind a translucent colour, the dash -/// of a mixed one), then the outline ring, the mark when `marked`, and the selection ring, in `state`. -fn paint_face(draw: &Draw<'_>, well: Rect, style: &SwatchStyle, state: &StateSet, color: Mixed, marked: bool, shape: SwatchShape) { - let outline = |rect: Rect| match shape { +fn paint_face(draw: &Draw<'_>, well: Rect, style: &SwatchStyle, state: &StateSet, face: WellFace<'_>, marked: bool) { + let outline = |rect: Rect| match face.shape { SwatchShape::Square => PaintShape::Rect(rect, style.radius), SwatchShape::Hexagon => PaintShape::Polygon(hexagon(rect)), }; let edge = outline(well); - match shape { - SwatchShape::Square => draw.swatch_well(well, style.radius, color.same().copied()), - SwatchShape::Hexagon => draw.swatch_polygon_well(&hexagon(well), color.same().copied()), + match face.shape { + SwatchShape::Square => draw.swatch_well(well, style.radius, face.fill), + SwatchShape::Hexagon => draw.swatch_polygon_well(&hexagon(well), face.fill), + } + if let Some(glyph) = face.glyph { + let side = style.glyph.min(well.width()).min(well.height()); + draw.icon(Rect::from_center_size(well.center(), Vec2::splat(side)), &IconSpec::svg(glyph.clone()).color(style.mark)); } draw.stroke(&edge, StrokeWidth::Thin, state.resolve(&style.edge)); ->>>>>>> origin/next if marked { let inside = outline(well.shrink(draw.width(StrokeWidth::Thin))); draw.stroke(&inside, StrokeWidth::Thin, style.mark); @@ -421,10 +417,7 @@ impl SwatchFace { let style = resolve_style(&scope, key, cx.painter.ctx(), Swatch::<()>::style); let (flags, on) = if self.selected { (Flags::SELECTED, 1.0) } else { (Flags::empty(), 0.0) }; let state = StateSet::new(State::Rest, flags, StateMix::new(0.0, 0.0, on)); -<<<<<<< HEAD - cx.with_draw(|draw| paint_face(draw, rect, &style, &state, well_fill(self.color), None, false)); -======= - cx.with_draw(|draw| paint_face(draw, rect, &style, &state, self.color, false, SwatchShape::Square)); ->>>>>>> origin/next + let face = WellFace { fill: well_fill(self.color), glyph: None, shape: SwatchShape::Square }; + cx.with_draw(|draw| paint_face(draw, rect, &style, &state, face, false)); } } diff --git a/crates/ui-widgets/src/choice/swatch_table.rs b/crates/ui-widgets/src/choice/swatch_table.rs index 97b0bf6b41..0a6162ce69 100644 --- a/crates/ui-widgets/src/choice/swatch_table.rs +++ b/crates/ui-widgets/src/choice/swatch_table.rs @@ -3,22 +3,13 @@ use super::swatch::hexagon; use super::{Swatch, SwatchMetrics, SwatchShape}; use crate::contract::{ -<<<<<<< HEAD ActivateOn, Bind, BindMut, Collection, CollectionEvent, CollectionProps, Common, Component, ContainerProps, Cx, LeadOnOpen, NoValue, Outcome, - Props, Role, SelectMode, ShowCollection as _, Sizing, -======= - ActivateOn, Bind, BindMut, Collection, CollectionEvent, CollectionProps, Common, Component, ContainerProps, Cx, NoValue, Outcome, Props, - Remember as _, Role, SelectMode, ShowCollection as _, Sizing, ->>>>>>> origin/next + Props, Remember as _, Role, SelectMode, ShowCollection as _, Sizing, }; use crate::list::RowTest; use crate::runtime::env::Label; use crate::style::{ComponentStyle, StyleCx}; -<<<<<<< HEAD -use craft_behavior::{DisplayOrder, IconId, ItemSource, Metrics, Selection, TileLayout}; -======= -use craft_behavior::{DisplayOrder, ItemLayout, ItemSource, Metrics, NavShape, Preview, ScrollPos, Selection, TileLayout}; ->>>>>>> origin/next +use craft_behavior::{DisplayOrder, IconId, ItemLayout, ItemSource, Metrics, NavShape, Preview, ScrollPos, Selection, TileLayout}; use craft_theme::Srgba; use egui::{Pos2, Rect, Response, Ui, Vec2}; @@ -381,15 +372,12 @@ pub struct SwatchTable<'a> { /// Whether the cells are wells at the control height, as a palette's swatches are, instead of small touching cells. #[prop] wells: bool, -<<<<<<< HEAD - /// The icon cell after the entries: its name and glyph. - trailing: Option<(Label, IconId)>, -======= /// How the cells lie: a square grid, or touching hexagons. A honeycomb ignores `per_row`, `span` and `wells`: its /// rows follow the count of entries and its cells are `size.icon.md` wide. #[prop] arrangement: SwatchArrangement, ->>>>>>> origin/next + /// The icon cell after the entries: its name and glyph. + trailing: Option<(Label, IconId)>, } impl<'a> SwatchTable<'a> { @@ -417,11 +405,8 @@ impl<'a> SwatchTable<'a> { marked: None, tips: false, wells: false, -<<<<<<< HEAD - trailing: None, -======= arrangement: SwatchArrangement::default(), ->>>>>>> origin/next + trailing: None, } .label(label) } @@ -451,7 +436,6 @@ impl<'a> SwatchTable<'a> { let (swatches, tips, wells) = (self.swatches, self.tips, self.wells); let shape = if self.arrangement == SwatchArrangement::Honeycomb { SwatchShape::Hexagon } else { SwatchShape::Square }; let marked = self.marked.take(); -<<<<<<< HEAD // A clone, not a take: `ideal_width` reads the trailing cell while the table shows. let trailing = self.trailing.clone(); let rows = match &trailing { @@ -465,12 +449,7 @@ impl<'a> SwatchTable<'a> { // The rows name no key past the trailing cell; a mixed well keeps the closure total without a panic. (None, None) => (Label::Empty, Swatch::new(Label::Empty, craft_behavior::Mixed::::Mixed)), }; - let cell = cell.cell(); -======= - self.show_items(ui, &SwatchRows::new(swatches), &mut |key, _| { - let (name, color) = &swatches[*key]; - let cell = Swatch::new(name.clone(), *color).cell().shape(shape); ->>>>>>> origin/next + let cell = cell.cell().shape(shape); let cell = if wells { cell.well() } else { cell }; let cell = if marked.as_ref().is_some_and(|test| test.passes(key)) { cell.marked() } else { cell }; if tips { cell.tooltip(name) } else { cell } @@ -529,17 +508,12 @@ impl Collection for SwatchTable<'_> { /// Where the table takes its width from its content it asks for every cell in one row, or its count per row: the /// room it is offered then wraps the cells, as it does where it is given the width. -<<<<<<< HEAD - fn ideal_width(&self, _item: Option, cx: &StyleCx<'_>) -> f32 { - let cells = self.cells(); - let columns = self.per_row.map_or(cells, |columns| columns.max(1).min(cells)); -======= fn ideal_width(&self, _item: Option, _rows: usize, cx: &StyleCx<'_>) -> f32 { + let cells = self.cells(); if self.arrangement == SwatchArrangement::Honeycomb { - return HoneycombLayout::new(self.swatches.len(), self.cell(cx)).columns() as f32 * self.cell(cx) + 0.5; + return HoneycombLayout::new(cells, self.cell(cx)).columns() as f32 * self.cell(cx) + 0.5; } - let columns = self.per_row.map_or(self.swatches.len(), |columns| columns.max(1).min(self.swatches.len())); ->>>>>>> origin/next + let columns = self.per_row.map_or(cells, |columns| columns.max(1).min(cells)); // Half a point over, so the division that counts the columns back never rounds below `columns`. columns as f32 * self.cell(cx) + 0.5 } diff --git a/crates/ui-widgets/src/choice/swatch_table/stories.rs b/crates/ui-widgets/src/choice/swatch_table/stories.rs index b3f685ec32..48143e4961 100644 --- a/crates/ui-widgets/src/choice/swatch_table/stories.rs +++ b/crates/ui-widgets/src/choice/swatch_table/stories.rs @@ -3,11 +3,7 @@ use super::{SwatchArrangement, SwatchTable, SwatchTableOutput}; use crate::runtime::env::Label; use crate::testing::{Drive, StoryData, StoryOutput, story}; -<<<<<<< HEAD -use craft_behavior::{IconId, Selection}; -======= -use craft_behavior::{Preview, Selection}; ->>>>>>> origin/next +use craft_behavior::{IconId, Preview, Selection}; use craft_theme::Srgba; use egui::Ui; diff --git a/crates/ui-widgets/src/controls/disclosure.rs b/crates/ui-widgets/src/controls/disclosure.rs index da4a094e33..89863f9eb1 100644 --- a/crates/ui-widgets/src/controls/disclosure.rs +++ b/crates/ui-widgets/src/controls/disclosure.rs @@ -52,13 +52,8 @@ pub struct DisclosureGlyph { pub stroke: StrokeWidth, } -<<<<<<< HEAD /// The arrow of a field or picker: the small filled triangle pointing down. -static DROPDOWN: DisclosureGlyph = DisclosureGlyph::new(1.0); -======= -/// The arrow of a field or picker. -const DROPDOWN: DisclosureGlyph = DisclosureGlyph::dropdown_form(); ->>>>>>> origin/next +const DROPDOWN: DisclosureGlyph = DisclosureGlyph::new(1.0); /// The arrow of a button that opens a menu. const MENU_BUTTON: DisclosureGlyph = DisclosureGlyph { open: 1.0, form: ArrowForm::Dropdown, stroke: StrokeWidth::Medium }; /// The submenu arrow. diff --git a/crates/ui-widgets/src/display/picture.rs b/crates/ui-widgets/src/display/picture.rs index bebd8dc69d..8740ec5ec8 100644 --- a/crates/ui-widgets/src/display/picture.rs +++ b/crates/ui-widgets/src/display/picture.rs @@ -4,23 +4,16 @@ use super::display_sense; use crate::contract::{Access, Common, Component, Cx, DisabledLook, MeasureCx, PaintUi, Props as _, Role}; use crate::list::{ThumbAspect, ThumbSize}; -<<<<<<< HEAD -use crate::primitives::{ContentPainterCx, Revision, TextureState, TextureStore, TextureStoreOptions, fit_rect, svg_tree}; -use crate::runtime::env::Label; -use crate::style::{ComponentStyle, StyleCx}; -use craft_behavior::{Metrics, Sense}; -use egui::{Color32, ColorImage, Id, Pos2, Rect, Response, Vec2}; -use std::collections::hash_map::DefaultHasher; -use std::hash::{Hash, Hasher}; -======= use crate::primitives::{ - ContentPainterCx, Priority, Revision, TextureStore, TextureStoreOptions, ThumbPaint, ThumbRequest, ThumbSource, Thumbnails, fit_rect, + ContentPainterCx, Priority, Revision, TextureState, TextureStore, TextureStoreOptions, ThumbPaint, ThumbRequest, ThumbSource, Thumbnails, + fit_rect, svg_tree, }; use crate::runtime::env::Label; use crate::style::{ComponentStyle, StyleCx}; use craft_behavior::{Metrics, Sense}; -use egui::{ColorImage, Id, Rect, Response, Vec2}; ->>>>>>> origin/next +use egui::{Color32, ColorImage, Id, Rect, Response, Vec2}; +use std::collections::hash_map::DefaultHasher; +use std::hash::{Hash, Hasher}; #[cfg(feature = "suite")] pub(crate) mod stories; @@ -61,13 +54,10 @@ enum Source<'a> { Image { key: u64, image: &'a dyn Fn() -> ColorImage }, /// A content painter that paints into the picture's rect. Painter(Paint<'a>), -<<<<<<< HEAD - /// An SVG asset, rasterised at the picture's drawn size. - Svg(&'static [u8]), -======= /// A picture rendered off the frame by a thumbnail source, shown pending until it arrives. Rendered { key: u64, thumbnails: &'a Thumbnails, source: &'a dyn ThumbSource }, ->>>>>>> origin/next + /// An SVG asset, rasterised at the picture's drawn size. + Svg(&'static [u8]), } /// A picture of an image the caller makes (`new`), of what a content painter paints (`painter`) or of an SVG asset @@ -108,12 +98,6 @@ impl<'a> Picture<'a> { Picture::from_source(label, Source::Painter(Box::new(paint))).aspect(aspect) } -<<<<<<< HEAD - /// A picture of the SVG asset `svg`, rasterised through `craft-svg` at the picture's drawn size; a malformed or - /// oversized SVG draws nothing. `label` names it for a screen reader; an empty one leaves it decorative. - pub fn svg(label: impl Into