backstage: New tiles are pictures with their names under them, as production's

The blank presentation shows at production's larger size (the card thumbnail at 1.25), every tile frames
its picture only and sets its name under it on up to two lines (CaptionPlace::BelowWrapped), and
"Templates" is a plain heading, as Info's and Print's are, with no fold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-29 00:16:52 +00:00
co-authored by Claude Opus 5.5
parent db24e74f16
commit 378872f489
2 changed files with 31 additions and 11 deletions
+16 -11
View File
@@ -8,14 +8,14 @@ use craft::ui::contract::{
};
use craft::ui::display::{Divider, Picture, Shade, Text};
use craft::ui::layout_components::{Row, Stack};
use craft::ui::list::{List, ListRow, ThumbAspect, ThumbSize};
use craft::ui::list::{List, ListRow, ThumbAspect};
use craft::ui::runtime::env::with_env;
use craft::ui::sections::Section;
use craft::ui::shell::{RecentFile, RecentList, RecentRemove, StartAction};
use craft::ui::style::TypeRole;
use craft::ui::text::TextField;
use craft::ui::tile_grid::{CardText, Tile, TileGrid};
use craft::ui::tile_grid::{CaptionPlace, GridZoom, Tile, TileGrid};
use super::{Backstage, Icon, Outcome, Page, SlideApp, Ui, Value, json};
@@ -78,17 +78,21 @@ fn template_tiles(query: &str, limit: usize) -> Vec<NewTile> {
.collect()
}
fn show_tiles(app: &mut SlideApp, ui: &mut Ui, label: &'static str, tiles: &[NewTile], large: bool) {
/// The blank presentation's picture against a theme's: production's New page shows it larger, 200 wide to 160.
const BLANK_ZOOM: f64 = 1.25;
/// Shows `tiles` as pictures with their names under them, on two lines before a long name is cut; `zoom` scales the
/// card thumbnail.
fn show_tiles(app: &mut SlideApp, ui: &mut Ui, label: &'static str, tiles: &[NewTile], zoom: f64) {
let source = keyed(tiles, |tile: &NewTile| tile.key.clone()).with_text(|tile| Cow::Borrowed(tile.label.as_str()));
let grid = TileGrid::<NewChoice>::new(label)
.select(SelectMode::Single)
.activate(ActivateOn::Click)
.card()
.card_text(CardText::Preset)
.caption(CaptionPlace::BelowWrapped)
.zoom(GridZoom::Fixed(zoom))
.aspect(16.0 / 9.0)
.sizing(Sizing::FillWidth)
.natural_height(true);
let grid = if large { grid.thumb_size(ThumbSize::Large) } else { grid };
let out = grid.show_items(ui, &source, &mut |key, _| {
let Some(tile) = tiles.iter().find(|tile| &tile.key == key) else {
return Tile::new("");
@@ -189,14 +193,14 @@ pub(super) fn home(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &m
out.page = Some(Page::New);
}
})
.show(ui, |ui, _| show_tiles(app, ui, "New presentations", &theme_tiles("", 5, true), false));
.show(ui, |ui, _| show_tiles(app, ui, "New presentations", &theme_tiles("", 5, true), 1.0));
Section::new("Templates")
.controls(|ui, _| {
if clicked(&Link::new("More templates").show(ui)) {
out.page = Some(Page::New);
}
})
.show(ui, |ui, _| show_tiles(app, ui, "Starter templates", &template_tiles("", 3), false));
.show(ui, |ui, _| show_tiles(app, ui, "Starter templates", &template_tiles("", 3), 1.0));
let files = recent_files(app, &bs.query);
let empty = recent_empty(&bs.query);
let shown = RecentList::new(&files)
@@ -216,14 +220,15 @@ pub(super) fn home(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &m
/// A blank presentation, every matching theme and the starter templates.
pub(super) fn new_page(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &mut Backstage) {
show_tiles(app, ui, "Blank presentation", &[NewTile::blank()], true);
show_tiles(app, ui, "Blank presentation", &[NewTile::blank()], BLANK_ZOOM);
let _ = Divider::horizontal().show(ui);
let _ = TextField::search("Search for themes and templates", Bind::bound(&mut bs.query)).placeholder("Search for themes and templates").show(ui);
let themes = theme_tiles(&bs.query, usize::MAX, false);
let templates = template_tiles(&bs.query, usize::MAX);
show_tiles(app, ui, "Themes", &themes, false);
show_tiles(app, ui, "Themes", &themes, 1.0);
if bs.query.trim().is_empty() || !templates.is_empty() {
Section::new("Templates").show(ui, |ui, _| show_tiles(app, ui, "Starter templates", &templates, false));
let _ = Text::new("Templates").role(TypeRole::Heading).show(ui);
show_tiles(app, ui, "Starter templates", &templates, 1.0);
}
if themes.is_empty() && templates.is_empty() {
let _ = Text::new(format!("No themes or templates match “{}”.", bs.query.trim())).shade(Shade::Muted).show(ui);
+15
View File
@@ -128,6 +128,21 @@ fn every_page_renders() {
}
}
/// The New page heads its starter templates as production did, with a plain heading: nothing folds them away.
#[test]
fn the_new_pages_templates_have_no_fold() {
let mut h = new_app();
h.state_mut().run("app.backstage", json!({"page": Page::New.id()})).unwrap();
h.run_steps(3);
let view = h.get_by_role_and_label(Role::Group, "File view");
assert!(view.query_all_by_label("Templates").next().is_some(), "the templates have their heading");
assert!(
view.query_all_by_label("Templates").all(|node| node.accesskit_node().data().is_expanded().is_none()),
"the templates heading opens and closes nothing"
);
page_choice(&h, "Briefing");
}
#[test]
fn open_lists_recent_files_and_opens_one() {
let dir = temp_dir("open");