From 329ceb85fba3e76b1ba7ea291c386b94ed3c7bd5 Mon Sep 17 00:00:00 2001 From: haranishi <223786623+haranishi@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:18:52 +0900 Subject: [PATCH] Give desktop Home recent cards more room --- crates/ui-shell/src/shell/start.rs | 9 ++++-- crates/ui-shell/tests/it/shell/start.rs | 42 +++++++++++++++++++++++++ crates/ui-widgets/src/tile_grid/grid.rs | 16 ++++++---- crates/ui-widgets/src/tile_grid/tile.rs | 24 +++++++++----- 4 files changed, 76 insertions(+), 15 deletions(-) diff --git a/crates/ui-shell/src/shell/start.rs b/crates/ui-shell/src/shell/start.rs index cc712c9c0..e92ee18e7 100644 --- a/crates/ui-shell/src/shell/start.rs +++ b/crates/ui-shell/src/shell/start.rs @@ -43,6 +43,7 @@ const CARD_ZOOM: f32 = 2.0; /// The width and height parts of a card's picture. const PICTURE_WIDE: u16 = 16; const PICTURE_HIGH: u16 = 9; +const HOME_RECENT_PICTURE_ASPECT: f32 = 3.0 / 2.0; /// The number of recent files shown until `max_recent` says otherwise. const RECENT_SHOWN: usize = 12; @@ -409,7 +410,8 @@ impl StartScreen<'_> { if let (true, Some(hint), Some((center, wide))) = (files.is_empty(), page.drop_hint, drop_area) { home_drop(&page, ui, hint, center, wide); } else { - recent_section(&page, ui, &view, &sort, current_view, &files); + let desktop_home = drop_area.is_some_and(|(_, wide)| wide); + recent_section(&page, ui, &view, &sort, current_view, &files, desktop_home); } if let Some(pinned) = pinned { pinned_section(&page, ui, pinned); @@ -646,6 +648,7 @@ fn recent_section( sort: &RefCell>, current: RecentView, files: &[RecentFile], + desktop_home: bool, ) { let words = page.words; let modes = [ @@ -698,7 +701,9 @@ fn recent_section( let file_of = |path: &PathBuf| files.iter().find(|file| &file.path == path); let source = keyed(files, |file: &RecentFile| file.path.clone()).with_text(|file| Cow::Borrowed(file.name.as_str())); let (response, (opened, removed)) = if current == RecentView::Grid { - let out = page.grid::(words.recent.clone(), true).show_items(ui, &source, &mut |path, _| { + let grid = page.grid::(words.recent.clone(), true); + let grid = if desktop_home { grid.aspect(HOME_RECENT_PICTURE_ASPECT).regular_card_padding() } else { grid }; + let out = grid.show_items(ui, &source, &mut |path, _| { let Some(file) = file_of(path) else { return Tile::new(Label::Empty) }; page.tile(&file.name, page.age(file.opened), ThumbKey::Recent(file.path.clone())) .corner_action(IconId::new("close"), StartRecentCommands::Remove) diff --git a/crates/ui-shell/tests/it/shell/start.rs b/crates/ui-shell/tests/it/shell/start.rs index 32e616de2..a8a8d35a5 100644 --- a/crates/ui-shell/tests/it/shell/start.rs +++ b/crates/ui-shell/tests/it/shell/start.rs @@ -138,6 +138,48 @@ fn the_home_screen_places_navigation_to_the_left_of_recent_files() { assert!(rect("GitHub").top() - rect("Discord").bottom() >= 6.0); } +/// A desktop Recent tile gives its picture and filename room while keeping the whole card clickable. +#[trial] +fn desktop_home_recent_cards_give_the_picture_and_caption_room() { + use egui::{Shape, pos2, vec2}; + + let (mut fixture, log) = home_screen(true); + fixture.room(vec2(1100.0, 700.0)).settle(); + let card = fixture.by_label("Poster.psd").expect("the recent file shows").rect; + let shapes = fixture.frame_shapes(); + let picture = shapes + .iter() + .find_map(|shape| match shape { + Shape::Rect(shape) + if card.contains_rect(shape.rect) + && shape.rect.width() > card.width() * 0.8 + && shape.rect.width() < card.width() - 1.0 + && shape.rect.height() > 100.0 => + { + Some(shape.rect) + } + _ => None, + }) + .expect("the tile paints an inset picture well"); + let caption = shapes + .iter() + .find_map(|shape| match shape { + Shape::Text(text) if text.galley.text() == "Poster.psd" => Some(text.pos), + _ => None, + }) + .expect("the tile paints its filename"); + + assert!((390.0..400.0).contains(&card.width()), "{card:?}"); + assert!(card.height() >= 285.0, "there is more vertical room: {card:?}"); + assert!(picture.left() - card.left() >= 8.0, "the picture has horizontal padding: {picture:?}"); + assert!(picture.top() - card.top() >= 8.0, "the picture has top padding: {picture:?}"); + assert!(caption.x - card.left() >= 8.0 && caption.y - picture.bottom() >= 8.0, "the filename has space: {caption:?}"); + + log.borrow_mut().clear(); + fixture.click_at(pos2(card.left() + 3.0, card.top() + 3.0)).settle(); + assert_eq!(*log.borrow(), vec![StartAction::OpenRecent(PathBuf::from("/tmp/work/Poster.psd"))]); +} + /// The Home surround can have the same colour as ordinary separators. The title and drop card still need visible ink. #[trial] fn the_home_title_and_drop_card_keep_their_outlines_visible() { diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index f02ea9d77..ebfd9c7dc 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -149,13 +149,13 @@ struct GridSizes { } impl GridSizes { - fn of(cx: &StyleCx<'_>, card: bool, rows: RowHeight) -> GridSizes { + fn of(cx: &StyleCx<'_>, card: bool, rows: RowHeight, regular_card_padding: bool) -> GridSizes { let spacing = ArrangeSpacing::new(if card { cx.tokens.space.gap.section } else { cx.tokens.space.gap.stack }, cx.tokens.space.gap.inline, rows.of(cx)); GridSizes { card: cx.tokens.size.thumb.card, thumbs: [cx.tokens.size.thumb.sm, cx.tokens.size.thumb.md, cx.tokens.size.thumb.lg], - around: Tile::around(cx, card), + around: Tile::around(cx, card, regular_card_padding), spacing, // Bare tiles sit with no gap between them: the room around each picture keeps them apart. bare_spacing: if card { spacing } else { ArrangeSpacing { gap: 0.0, ..spacing } }, @@ -239,6 +239,9 @@ pub struct TileGrid<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { /// Tiles are framed cards: the picture inset in a raised surface with the name and detail at the reading start. #[prop(flag)] card: bool, + /// Framed cards use the theme's regular padding around their picture and caption. + #[prop(flag)] + regular_card_padding: bool, /// The headers over runs of tiles, in display order. #[prop] groups: &'a [TileGroup], @@ -311,6 +314,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> { caption: CaptionPlace::Below, detail_line: false, card: false, + regular_card_padding: false, groups: &[], collapsible: false, tail: &[], @@ -391,7 +395,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> { /// The layout of this pass: `previous` when it was made from the same recipe, else a new arrangement. A card is /// the picture plus what the tile adds around it in every tiling. fn laid_out(&self, previous: Option, source: &dyn ItemSource, width: f32, item: Option, cx: &StyleCx<'_>) -> GridLayout { - let style = GridSizes::of(cx, self.card, self.items.row_height); + let style = GridSizes::of(cx, self.card, self.items.row_height, self.regular_card_padding); let spacing = style.spacing(self.caption); let around = style.around.get(self.caption, self.detail_line); // A card never outgrows the grid: in a column narrower than a card the card takes the column. @@ -793,7 +797,7 @@ impl Collection for TileGrid<'_, K fn dress_inputs(&self) -> u64 { use std::hash::{Hash as _, Hasher as _}; let mut hasher = std::collections::hash_map::DefaultHasher::new(); - (self.caption, self.detail_line, self.card).hash(&mut hasher); + (self.caption, self.detail_line, self.card, self.regular_card_padding).hash(&mut hasher); hasher.finish() } @@ -802,7 +806,7 @@ impl Collection for TileGrid<'_, K if self.card_columns == 0 { return 0.0; } - let style = GridSizes::of(cx, self.card, self.items.row_height); + let style = GridSizes::of(cx, self.card, self.items.row_height, self.regular_card_padding); let aspect = if self.aspect.is_finite() && self.aspect > 0.0 { self.aspect } else { 1.0 }; let around = style.around.get(self.caption, self.detail_line); let card = style.card(self.picture_side(&style, item, around), aspect, around).x; @@ -826,7 +830,7 @@ impl Collection for TileGrid<'_, K /// Every tile gets the grid's caption place and detail line, the card look, and its row's rename state. fn dress<'r>(&self, tile: Self::Item<'r>, row: &RowState) -> Self::Item<'r> { let tile = tile.caption(self.caption).detail_line(self.detail_line).renaming(row.renaming); - if self.card { tile.card() } else { tile } + if self.card { tile.card().with_regular_card_padding(self.regular_card_padding) } else { tile } } fn can_rename(&self, key: &K) -> bool { diff --git a/crates/ui-widgets/src/tile_grid/tile.rs b/crates/ui-widgets/src/tile_grid/tile.rs index 08f56aac8..a86e97354 100644 --- a/crates/ui-widgets/src/tile_grid/tile.rs +++ b/crates/ui-widgets/src/tile_grid/tile.rs @@ -121,8 +121,8 @@ pub(super) struct AroundPicture { } impl AroundPicture { - fn of(cx: &StyleCx<'_>, card: bool) -> AroundPicture { - let around = |place: CaptionPlace, detail: bool| Sizes::of(cx, card, place).around(place, detail); + fn of(cx: &StyleCx<'_>, card: bool, regular_card_padding: bool) -> AroundPicture { + let around = |place: CaptionPlace, detail: bool| Sizes::of(cx, card, place, regular_card_padding).around(place, detail); AroundPicture { below: around(CaptionPlace::Below, false), below_detail: around(CaptionPlace::Below, true), @@ -145,11 +145,12 @@ impl AroundPicture { impl Sizes { /// The sizes of a tile with its caption in `place`. A bare tile keeps only the room its selection ring draws in, so /// a grid packs bare tiles close. - fn of(cx: &StyleCx<'_>, card: bool, place: CaptionPlace) -> Sizes { + fn of(cx: &StyleCx<'_>, card: bool, place: CaptionPlace, regular_card_padding: bool) -> Sizes { let (tokens, control) = (cx.tokens, cx.control()); let line = tokens.typography.get(TypeRole::Caption).line_height; let name_line = if card { tokens.typography.get(TypeRole::BodyStrong).line_height } else { line }; let inset = match (card, place) { + (true, _) if regular_card_padding => tokens.space.pad.regular, (true, _) => tokens.space.pad.control, (false, CaptionPlace::None) => tokens.space.gap.tight, (false, _) => tokens.space.gap.inline, @@ -297,6 +298,9 @@ pub struct Tile<'a> { #[style_key] #[prop] caption: CaptionPlace, + /// The grid asked for the theme's regular padding around a framed card. + #[style_key] + regular_card_padding: bool, /// The card has a line for the detail, whether this tile has one or not: the grid's, applied to its tiles. #[prop] detail_line: bool, @@ -375,6 +379,7 @@ impl<'a> Tile<'a> { Tile { common: Common::new(), caption: CaptionPlace::Below, + regular_card_padding: false, detail_line: false, card: false, detail: None, @@ -454,12 +459,17 @@ impl<'a> Tile<'a> { /// What a tile adds around its picture: its padding, the caption band under the picture or the column at its /// reading start. A tile grid sizes a tile as the picture plus this. pub fn around_picture(cx: &StyleCx<'_>, place: CaptionPlace, detail: bool) -> Around { - Sizes::of(cx, false, place).around(place, detail) + Sizes::of(cx, false, place, false).around(place, detail) } /// What a tile adds around its picture for every caption arrangement. - pub(super) fn around(cx: &StyleCx<'_>, card: bool) -> AroundPicture { - AroundPicture::of(cx, card) + pub(super) fn around(cx: &StyleCx<'_>, card: bool, regular_card_padding: bool) -> AroundPicture { + AroundPicture::of(cx, card, regular_card_padding) + } + + pub(super) fn with_regular_card_padding(mut self, enabled: bool) -> Self { + self.regular_card_padding = enabled; + self } /// Whether the caption band holds a detail line. @@ -627,7 +637,7 @@ impl Component for Tile<'_> { let (state, text) = (&colors.state, &colors.text); let clear = Rgba::TRANSPARENT; let c = |rgba: Rgba| cx.color(rgba); - let sizes = Sizes::of(cx, key.card, key.caption); + let sizes = Sizes::of(cx, key.card, key.caption, key.regular_card_padding); // Selection and hover are rings around the picture; only a card has a fill of its own. let fill = if key.card { let raised = colors.surface.raised;