Merge look-fix4-popups framework work

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-30 03:18:51 +00:00
commit 2d97cb92b8
7 files changed
+99 -7

No files matched your search

+3 -1
View File
@@ -360,7 +360,7 @@ fn show_row<T: Clone + Eq + Hash + Send + Sync + Debug + 'static>(
// The groups start a regular pad in from the row's start edge, as the old ribbon's did.
craft_ui::layout::place_in_flow(ui, Vec2::new(start, 0.0));
let mut row =
RibbonRow { ui, base, groups: Vec::new(), title_line, launcher_side, icons, launcher: launcher.clone(), chevron };
RibbonRow { ui, base, groups: Vec::new(), title_line, launcher_side, icons, launcher: launcher.clone(), chevron, owner };
body(&mut row, key);
row.groups
});
@@ -458,6 +458,8 @@ pub struct RibbonRow<'a> {
launcher: IconId,
/// The width of an edge chevron's slot, which no group shown in a scrolling row reaches into.
chevron: f32,
/// The scrolling body the groups stand in: its content's extent says whether groups run past an edge.
owner: Id,
}
/// What the ribbon reports for a pass.
+10 -3
View File
@@ -6,7 +6,7 @@ use craft_behavior::IconId;
use craft_keymap::CommandRef;
use craft_ui::buttons::{Arrangement, Button, ControlPlace, IconButton};
use craft_ui::contract::MemoProps;
use craft_ui::contract::{Bind, Gap, Props as _, Show as _, ShowContainer as _, Sizing, Trigger};
use craft_ui::contract::{Bind, Gap, Props as _, Show as _, ShowContainer as _, Sizing, Trigger, scroll_extent};
use craft_ui::display::{Divider, Shade, Text};
use craft_ui::layout::{RowAlign, levelled_unit};
use craft_ui::layout_components::{Row, Stack};
@@ -208,11 +208,18 @@ impl RibbonRow<'_> {
_ => LEVELS.len(),
};
// A scrolling row shows whole groups only: a group that does not lie wholly inside the view, short of the edge
// chevrons' slots when the row overflows on that side, is not drawn and takes no pointer.
// chevrons' slots when groups run past that edge (as the chevrons show), is not drawn and takes no pointer. The
// body's room is unbounded along the row, so the groups' run is the first group's start edge to the end the
// content's extent reaches.
let (body, view, chevron) = (self.ui.max_rect(), self.ui.clip_rect(), self.chevron);
let slots = (if body.min.x < view.min.x - 0.5 { chevron } else { 0.0 }, if body.max.x > view.max.x + 0.5 { chevron } else { 0.0 });
let rtl = Env::of(self.ui).direction.is_rtl();
let extent = scroll_extent(self.ui.ctx(), self.owner).x;
let first = self.groups.first().copied();
levelled_unit(self.ui, id, levels, |ui, at| {
let unit = ui.max_rect();
let first = first.unwrap_or(unit);
let (start, end) = if rtl { (body.max.x - extent, first.max.x) } else { (first.min.x, body.min.x + extent) };
let slots = (if start < view.min.x - 0.5 { chevron } else { 0.0 }, if end > view.max.x + 0.5 { chevron } else { 0.0 });
if unit.min.x < view.min.x + slots.0 - 0.5 || unit.max.x > view.max.x - slots.1 + 0.5 {
ui.set_clip_rect(Rect::NOTHING);
}
+45
View File
@@ -189,6 +189,51 @@ fn an_overflowing_scrolling_row_ends_on_a_whole_group_clear_of_the_chevron() {
}
}
/// Five three-button groups in a scrolling row.
const FIVE: [(&str, [&str; 3]); 5] = [
("one", ["One1", "One2", "One3"]),
("two", ["Two1", "Two2", "Two3"]),
("three", ["Three1", "Three2", "Three3"]),
("four", ["Four1", "Four2", "Four3"]),
("five", ["Five1", "Five2", "Five3"]),
];
fn five_groups() -> Fixture {
Fixture::new(move |ui| {
let tabs = [RibbonTab::new(0_usize, "Home")];
let look = RibbonLook::default().fit(RibbonFit::Scroll);
let _ = Ribbon::new("Ribbon", &tabs, Bind::given(0_usize)).look(look).show(ui, |row, _| {
for (key, labels) in &FIVE {
group(row, key, key, labels);
}
});
})
}
/// Whether the label `text` paints inside its clip.
fn painted(fixture: &Fixture, text: &str) -> bool {
fixture.texts().iter().any(|run| run.text == text && run.rect.intersect(run.clip).width() > 0.0)
}
/// Steps the row with its end chevron until the chevron goes, at most ten steps.
fn scroll_to_end(fixture: &mut Fixture) {
for _ in 0..10 {
let Some(chevron) = fixture.by_label("Scroll ribbon right") else { return };
fixture.click(&chevron).settle();
}
}
/// Scrolled to its end, the row shows its last group: no end chevron is left, so none keeps its slot.
#[trial]
fn a_scrolling_row_scrolled_to_its_end_shows_its_last_group() {
let mut fixture = five_groups();
fixture.room(vec2(420.0, 300.0));
fixture.settle();
scroll_to_end(&mut fixture);
assert!(fixture.by_label("Scroll ribbon right").is_none(), "the end chevron goes at the row's end");
assert!(painted(&fixture, "Five3"), "the last group shows at the row's end");
}
/// A gallery's More list hangs from its More button, below the ribbon row, clear of a taller control beside the
/// gallery, not from the gallery's own shorter rect.
#[trial]
@@ -96,6 +96,12 @@ pub fn scroll_position(ctx: &Context, owner: Id) -> ScrollPos {
})
}
/// The extent of the scrolling body `owner`'s content as its measuring run took it, which its real run scrolls over:
/// read from inside the body, it is the content of this pass. A body that has not measured reads zero.
pub fn scroll_extent(ctx: &Context, owner: Id) -> Vec2 {
crate::runtime::layout_memory::measured(ctx, crate::runtime::memory::sub(owner, "extent")).map_or(Vec2::ZERO, |measured| measured.took)
}
/// Queues `offset` for step 4 of the body `id`'s next pass, in place of one queued before, and repeats the pass to show
/// it.
pub(super) fn queue_jump(ctx: &Context, id: Id, offset: ScrollPos) {
+1 -1
View File
@@ -57,7 +57,7 @@ pub use body::grip_band;
pub use body::keep_inside;
pub use body::pad_of;
// PLAN: assumed body::scroll::scroll_position(ctx: &Context, owner: Id) -> ScrollPos (widgets-w2)
pub use body::scroll::scroll_position;
pub use body::scroll::{scroll_extent, scroll_position};
#[doc(hidden)]
pub use body::{STRIP_BACK, STRIP_FORWARD};
pub use collection::{
+6 -1
View File
@@ -1310,7 +1310,12 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for TileGrid<'_, K
}
/// The width of the requested card columns, their gaps and the content inset.
fn ideal_width(&self, item: Option<Vec2>, _rows: usize, cx: &StyleCx<'_>) -> f32 {
fn ideal_width(&self, item: Option<Vec2>, rows: usize, cx: &StyleCx<'_>) -> f32 {
// Content cells take their side from their tiles: with no tiles there is no card to ask room for, and the empty
// text decides the width.
if self.content_cells && rows == 0 {
return 0.0;
}
let style =
GridSizes::of(cx, self.card, self.card_text, self.caption_type, self.items.row_height, self.regular_card_padding, self.action_place);
let around = style.around.get(self.caption, self.detail_line);
+28 -1
View File
@@ -2,7 +2,7 @@
//! changes, and packs tiles without a caption closer than captioned ones.
use craft_behavior::{IconId, keyed};
use craft_ui::contract::ShowCollection as _;
use craft_ui::contract::{Props as _, ShowCollection as _, Sizing};
use craft_ui::primitives::IconSpec;
use craft_ui::testing::{Fixture, pointer, trial, widest_runs};
use craft_ui::tile_grid::{CaptionPlace, Tile, TileActionPlace, TileGrid};
@@ -58,6 +58,33 @@ fn content_cells_fit_the_icons_and_keep_their_measure() {
assert!(widest_runs(cells.ctx()).is_empty(), "a pointer move measured the tiles again: {:?}", widest_runs(cells.ctx()));
}
/// A content-sized grid of `count` icon cells that asks for nine columns, with an empty text.
fn nine_columns(count: usize) -> Fixture {
let mut fixture = Fixture::new(move |ui| {
let source = keyed(&KEYS[..count], |key: &usize| *key);
let grid = TileGrid::new("Icons")
.caption(CaptionPlace::None)
.content_cells()
.card_columns(9)
.sizing(Sizing::Content)
.empty("No icons match.")
.rows_stamp(1);
let _ = grid.show_items(ui, &source, &mut |key, _| Tile::new(format!("Icon {key}")).icon(IconSpec::svg(IconId::new("settings"))));
});
fixture.room(Vec2::new(1600.0, 400.0));
fixture.settle();
fixture
}
/// With no tiles there is no cell to size the asked columns from: an empty content-cell grid is no wider than the same
/// grid with its columns full, not as wide as the columns of thumbnail cards.
#[trial]
fn an_empty_content_cell_grid_asks_no_wider_than_its_full_columns() {
let width = |fixture: &Fixture| fixture.by_label("Icons").expect("the grid has a node").rect.width();
let (full, empty) = (nine_columns(9), nine_columns(0));
assert!(width(&empty) <= width(&full), "the empty grid ({}) is wider than its full columns ({})", width(&empty), width(&full));
}
fn photo_grid(caption: CaptionPlace) -> Fixture {
let mut fixture = Fixture::new(move |ui| {
let source = keyed(&KEYS, |key: &usize| *key);