Merge look-fix2-backstage app work

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-29 22:48:50 +00:00
co-authored by Claude Opus 5.5
4 changed files with 99 additions and 48 deletions
+38 -17
View File
@@ -6,16 +6,16 @@ use craft::ui::contract::{
ActivateOn, Bind, BodyCx, CollectionEvent, LeastWidth, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing,
clicked,
};
use craft::ui::display::{Divider, Picture, Shade, Text};
use craft::ui::display::{Divider, Picture, PictureSize, Shade, Text};
use craft::ui::layout_components::{Row, Stack};
use craft::ui::list::{List, ListRow, ThumbAspect};
use craft::ui::list::{List, ListRow, ThumbAspect, ThumbSize};
use craft::ui::runtime::env::with_env;
use craft::ui::sections::Section;
use craft::ui::sections::{HeaderStrength, Section};
use craft::ui::shell::{RecentFile, RecentList, RecentRemove, StartAction};
use craft::ui::style::TypeRole;
use craft::ui::text::TextField;
use craft::ui::tile_grid::{CaptionPlace, GridZoom, Tile, TileGrid};
use craft::ui::tile_grid::{CaptionPlace, CaptionType, 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()
}
/// 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;
/// Production's New and Home pages show a theme's picture 160 wide, against the card thumbnail's 128.
const THEME_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.
/// The blank presentation's picture against the card thumbnail: production's New page shows it 200 wide.
const BLANK_ZOOM: f64 = 1.5625;
/// Shows `tiles` as pictures with their names under them in body text, 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)
.caption(CaptionPlace::BelowWrapped)
.caption_type(CaptionType::Body)
.zoom(GridZoom::Fixed(zoom))
.aspect(16.0 / 9.0)
.sizing(Sizing::FillWidth)
@@ -184,23 +188,27 @@ fn recent_actions(app: &mut SlideApp, actions: Vec<StartAction>) {
pub(super) fn home(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &mut Backstage, out: &mut Outcome) {
Row::new().show(ui, |ui, _| {
// PLAN: assumed assets/app-icon/deckcraft-mark.svg (dialogs-w18)
let _ = Picture::svg("DeckCraft", include_bytes!("../../../../assets/app-icon/deckcraft-mark.svg")).show(ui);
let _ = Picture::svg("DeckCraft", include_bytes!("../../../../assets/app-icon/deckcraft-mark.svg"))
.extent(PictureSize::Thumb(ThumbSize::Medium))
.show(ui);
let _ = Text::new("DeckCraft").role(TypeRole::Display).show(ui);
});
Section::new("New")
// Plain page headings, as the New page's, with the link to the rest at their end.
let heading = |title: &'static str| Section::fixed(title).strength(HeaderStrength::Heading).quiet_header();
heading("New")
.controls(|ui, _| {
if clicked(&Link::new("More themes").show(ui)) {
out.page = Some(Page::New);
}
})
.show(ui, |ui, _| show_tiles(app, ui, "New presentations", &theme_tiles("", 5, true), 1.0));
Section::new("Templates")
.show(ui, |ui, _| show_tiles(app, ui, "New presentations", &theme_tiles("", 5, true), THEME_ZOOM));
heading("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), 1.0));
.show(ui, |ui, _| show_tiles(app, ui, "Starter templates", &template_tiles("", 3), THEME_ZOOM));
let files = recent_files(app, &bs.query);
let empty = recent_empty(&bs.query);
let shown = RecentList::new(&files)
@@ -225,10 +233,10 @@ pub(super) fn new_page(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs
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, 1.0);
show_tiles(app, ui, "Themes", &themes, THEME_ZOOM);
if bs.query.trim().is_empty() || !templates.is_empty() {
let _ = Text::new("Templates").role(TypeRole::Heading).show(ui);
show_tiles(app, ui, "Starter templates", &templates, 1.0);
show_tiles(app, ui, "Starter templates", &templates, THEME_ZOOM);
}
if themes.is_empty() && templates.is_empty() {
let _ = Text::new(format!("No themes or templates match “{}”.", bs.query.trim())).shade(Shade::Muted).show(ui);
@@ -287,9 +295,22 @@ pub(super) fn open_page(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, b
});
let _ = Divider::vertical().show(ui);
Stack::new().fill_width().show(ui, |ui, _| {
let _ = TextField::search("Search for a file", Bind::bound(&mut bs.query)).placeholder("Search for a file").show(ui);
// A search box keeps one width while its query changes, as production's does, not its text's.
Row::new().show(ui, |ui, _| {
Stack::new().least_width(LeastWidth::Palette).show(ui, |ui, _| {
let _ = TextField::search("Search for a file", Bind::bound(&mut bs.query))
.placeholder("Search for a file")
.sizing(Sizing::FillWidth)
.show(ui);
});
});
let files = recent_files(app, &bs.query);
let shown = RecentList::new(&files).remove(RecentRemove::Always).heading("Presentations").empty(recent_empty(&bs.query)).show(ui);
let shown = RecentList::new(&files)
.remove(RecentRemove::Always)
.heading("Presentations")
.heading_sections()
.empty(recent_empty(&bs.query))
.show(ui);
recent_actions(app, shown.actions);
});
});
+42 -31
View File
@@ -1,8 +1,11 @@
use super::{Backstage, Icon, Outcome, Page, SlideApp, Ui, Value, json};
use crate::app::files::SaveOutcome;
use craft::behavior::ColumnWidth;
use craft::theme::variant::Tone;
use craft::ui::buttons::{Arrangement, Button, Link};
use craft::ui::contract::{Bind, BodyCx, Entry, FieldLayout, LabelScheme, Props as _, Show as _, ShowContainer as _, Sizing, WrapWidth};
use craft::ui::contract::{
Bind, BodyCx, Entry, FieldLayout, Gap, LabelGap, LabelScheme, Props as _, Show as _, ShowContainer as _, Sizing, WrapWidth,
};
use craft::ui::display::{Picture, Shade, Text};
use craft::ui::form::{Field, FieldGroup};
use craft::ui::layout::CellAlign;
@@ -10,6 +13,7 @@ use craft::ui::layout_components::{Grid, Row, Stack};
use craft::ui::pickers::Select;
use craft::ui::primitives::Span;
use craft::ui::runtime::commands::{ClipItem, ClipboardHandle};
use craft::ui::runtime::env::{Overrides, with_env};
use craft::ui::runtime::focus;
use craft::ui::style::{TypeRole, Variant};
use craft::ui::text::TextField;
@@ -41,6 +45,7 @@ pub(super) const PROPERTIES: [(&str, &str, &str); 7] = [
/// A task's action beside its heading and explanation, sized by the controls and content.
pub(super) fn task_row(ui: &mut Ui, icon: Icon, label: &'static str, title: &'static str, detail: &'static str, enabled: bool) -> bool {
Row::new()
.gap(Gap::Section)
.show(ui, |ui, _| {
let pressed = Button::new(label).icon(icon.id()).arrangement(Arrangement::Stacked).enabled(enabled).show(ui).clicked();
Stack::new().wrap_width(WrapWidth::Column).show(ui, |ui, _| {
@@ -62,7 +67,7 @@ pub(super) fn info(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &m
let path = v.get("path").and_then(Value::as_str).map(str::to_string);
let title = v.get("title").and_then(Value::as_str).unwrap_or("");
let dirty = v.get("dirty").and_then(Value::as_bool).unwrap_or(false);
Text::new(title.to_string()).role(TypeRole::Heading).show(ui);
Text::new(title.to_string()).role(TypeRole::Display).tone(Tone::Accent).show(ui);
Text::new(path.as_deref().unwrap_or("Not saved yet").to_string()).shade(Shade::Muted).show(ui);
if let Some(path) = &path {
Row::new().wrap(true).show(ui, |ui, _| {
@@ -79,7 +84,7 @@ pub(super) fn info(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &m
});
}
Grid::new(&[ColumnWidth::Content, ColumnWidth::Content]).cells(CellAlign::Top).show(ui, |ui, _| {
Stack::new().wrap_width(WrapWidth::Column).show(ui, |ui, _| {
Stack::new().wrap_width(WrapWidth::Column).gap(Gap::Section).show(ui, |ui, _| {
if task_row(
ui,
Icon::Accessibility,
@@ -102,34 +107,40 @@ pub(super) fn info(app: &mut SlideApp, ui: &mut Ui, _cx: &mut BodyCx<'_>, bs: &m
Stack::new().show(ui, |ui, _| {
Text::new("Properties").role(TypeRole::Heading).show(ui);
let props = v.get("properties").cloned().unwrap_or_default();
FieldGroup::new("Properties").labels(LabelScheme::Inspector).show(ui, |ui, _| {
let readout = |ui: &mut Ui, label: &'static str, value: String| {
Field::new(label).layout(FieldLayout::Beside).value(value.clone()).show(ui, |ui, _| {
Text::new(value.clone()).show(ui);
});
};
if let Some(size) = v.get("bytes").and_then(Value::as_u64).map(format_bytes) {
readout(ui, "Size", size);
}
readout(ui, "Slides", v.get("slides").and_then(Value::as_u64).unwrap_or(0).to_string());
readout(ui, "Hidden slides", v.get("hiddenSlides").and_then(Value::as_u64).unwrap_or(0).to_string());
for (i, (key, label, hint)) in PROPERTIES.iter().enumerate() {
let saved = props.get(*key).and_then(Value::as_str).unwrap_or("").to_string();
let Some(draft) = bs.props.get_mut(i) else { continue };
Field::new(*label).id_salt(*key).layout(FieldLayout::Beside).show(ui, |ui, _| {
let response = TextField::new(*label, Bind::bound(draft)).placeholder(*hint).show(ui);
if (response.text_lost_focus || response.submitted) && *draft != saved {
// Losing focus can precede this field's body, so its draft must commit before it is refreshed.
let mut params = serde_json::Map::new();
params.insert((*key).to_string(), json!(draft.clone()));
let _ = app.run("file.properties", Value::Object(params));
} else if !focus::is_focused(ui.ctx(), response.response.id) && *draft != saved {
draft.clone_from(&saved);
ui.ctx().request_repaint();
}
});
}
readout(ui, "Location", path.clone().unwrap_or_else(|| "Not saved yet".into()));
// The values stand in their own column, apart from the longest name ("Hidden slides").
let wide = |overrides: &mut Overrides| {
overrides.values.set(LabelGap::Section);
};
with_env(ui, wide, |ui| {
FieldGroup::new("Properties").labels(LabelScheme::Inspector).show(ui, |ui, _| {
let readout = |ui: &mut Ui, label: &'static str, value: String| {
Field::new(label).layout(FieldLayout::Beside).value(value.clone()).show(ui, |ui, _| {
Text::new(value.clone()).show(ui);
});
};
if let Some(size) = v.get("bytes").and_then(Value::as_u64).map(format_bytes) {
readout(ui, "Size", size);
}
readout(ui, "Slides", v.get("slides").and_then(Value::as_u64).unwrap_or(0).to_string());
readout(ui, "Hidden slides", v.get("hiddenSlides").and_then(Value::as_u64).unwrap_or(0).to_string());
for (i, (key, label, hint)) in PROPERTIES.iter().enumerate() {
let saved = props.get(*key).and_then(Value::as_str).unwrap_or("").to_string();
let Some(draft) = bs.props.get_mut(i) else { continue };
Field::new(*label).id_salt(*key).layout(FieldLayout::Beside).show(ui, |ui, _| {
let response = TextField::new(*label, Bind::bound(draft)).placeholder(*hint).show(ui);
if (response.text_lost_focus || response.submitted) && *draft != saved {
// Losing focus can precede this field's body, so its draft must commit before it is refreshed.
let mut params = serde_json::Map::new();
params.insert((*key).to_string(), json!(draft.clone()));
let _ = app.run("file.properties", Value::Object(params));
} else if !focus::is_focused(ui.ctx(), response.response.id) && *draft != saved {
draft.clone_from(&saved);
ui.ctx().request_repaint();
}
});
}
readout(ui, "Location", path.clone().unwrap_or_else(|| "Not saved yet".into()));
})
});
});
});
+17
View File
@@ -143,6 +143,23 @@ fn the_new_pages_templates_have_no_fold() {
page_choice(&h, "Briefing");
}
/// Home heads its new presentations and starter templates with plain page headings, as the New page does: neither
/// folds away, and each keeps its link to the New page.
#[test]
fn the_home_pages_headings_have_no_fold() {
let mut h = new_app();
h.state_mut().run("app.backstage", json!({"page": Page::Home.id()})).unwrap();
h.run_steps(3);
let view = h.get_by_role_and_label(Role::Group, "File view");
for heading in ["New", "Templates"] {
let mut nodes = view.query_all_by_label(heading).filter(|node| !in_navigation(node)).peekable();
assert!(nodes.peek().is_some(), "Home has its {heading} heading");
assert!(nodes.all(|node| node.accesskit_node().data().is_expanded().is_none()), "the {heading} heading opens and closes nothing");
}
page_choice(&h, "More themes");
page_choice(&h, "More templates");
}
#[test]
fn open_lists_recent_files_and_opens_one() {
let dir = temp_dir("open");
+2
View File
@@ -9,6 +9,8 @@
"typography.body.size": 13,
"typography.body_strong.size": 13,
"typography.caption.size": 11,
"typography.display.line_height": 36,
"typography.display.size": 28,
"typography.heading.line_height": 24,
"typography.heading.size": 18,
"typography.label.size": 13,