mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
StartScreen: offers_open(false) leaves Open out, section headings are page headings with no rule, Pin Folder is ghost, a pinned folder's Unpin is text (trial)
This commit is contained in:
@@ -167,6 +167,13 @@ impl<'a> Section<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// The header carries no rule above it: a page heading rather than a boundary between panel sections.
|
||||
#[must_use]
|
||||
pub fn quiet_header(mut self) -> Self {
|
||||
self.update_header(|header| header.rule_above(false));
|
||||
self
|
||||
}
|
||||
|
||||
/// The action parts at the end of the header, in reading order.
|
||||
#[must_use]
|
||||
pub fn actions(mut self, actions: impl IntoIterator<Item = HeaderAction>) -> Self {
|
||||
|
||||
@@ -22,7 +22,7 @@ use crate::primitives::{CheckerArea, ContentPainterCx, IconSpec, Priority, Thumb
|
||||
use crate::runtime::commands::{self, CommandRef, FireSource};
|
||||
use crate::runtime::commands::{CommandSet as _, Commands as _};
|
||||
use crate::runtime::env::{AgeStyle, Env, Label};
|
||||
use crate::sections::Section;
|
||||
use crate::sections::{HeaderStrength, Section};
|
||||
use crate::style::{Corners, SurfaceKind, SurroundLook};
|
||||
use crate::tile_grid::{CaptionPlace, GridZoom, Tile, TileGrid, TilePartEvent};
|
||||
use craft_behavior::{DisplayOrder, IconId, ItemSource, Proposal, SelectionChange, keyed};
|
||||
@@ -296,6 +296,10 @@ pub struct StartScreen<'a> {
|
||||
/// The New… button shows (true by default).
|
||||
#[prop]
|
||||
offers_new: bool,
|
||||
/// The Open… button shows (true by default); an app that opens files from its title bar leaves it out. A double
|
||||
/// click on the page's empty room still asks for Open.
|
||||
#[prop]
|
||||
offers_open: bool,
|
||||
/// The host's sections, each at its place, in call order.
|
||||
sections: Vec<(StartPlace, HostSection<'a>)>,
|
||||
}
|
||||
@@ -353,6 +357,7 @@ impl<'a> StartScreen<'a> {
|
||||
links: &[],
|
||||
drop_hint: None,
|
||||
offers_new: true,
|
||||
offers_open: true,
|
||||
sections: Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -391,6 +396,8 @@ struct Page<'p> {
|
||||
now: Option<i64>,
|
||||
/// New… shows beside Open.
|
||||
offers_new: bool,
|
||||
/// Open… shows.
|
||||
offers_open: bool,
|
||||
actions: &'p RefCell<Vec<StartAction>>,
|
||||
}
|
||||
|
||||
@@ -488,12 +495,12 @@ fn read_events<K: Clone, E>(events: Vec<CollectionEvent<K, E>>, lead: &mut Optio
|
||||
impl StartScreen<'_> {
|
||||
/// Shows the page across the available room and reports what the user did.
|
||||
pub fn show(self, ui: &mut Ui) -> StartOutput {
|
||||
let StartScreen { view, sort, recent, pinned, templates, max_recent, now, thumbnails, links, drop_hint, offers_new, sections } = self;
|
||||
let StartScreen { view, sort, recent, pinned, templates, max_recent, now, thumbnails, links, drop_hint, offers_new, offers_open, sections } = self;
|
||||
let env = Env::of(ui);
|
||||
let collator = env.collator();
|
||||
let words = env.words::<ShellWords>();
|
||||
let actions = RefCell::new(Vec::new());
|
||||
let page = Page { env: &env, words: &words, thumbnails, drop_hint: drop_hint.as_ref(), now, offers_new, actions: &actions };
|
||||
let page = Page { env: &env, words: &words, thumbnails, drop_hint: drop_hint.as_ref(), now, offers_new, offers_open, actions: &actions };
|
||||
let view = RefCell::new(view);
|
||||
let sort = RefCell::new(sort);
|
||||
|
||||
@@ -504,7 +511,9 @@ impl StartScreen<'_> {
|
||||
let rail_stack = || Stack::new().gap(Gap::Tight).pad(Pad::Regular).label(words.start_links.clone());
|
||||
let rail_body = |ui: &mut Ui| {
|
||||
new_and_open(&page, ui);
|
||||
let _ = Divider::horizontal().show(ui);
|
||||
if offers_new || offers_open {
|
||||
let _ = Divider::horizontal().show(ui);
|
||||
}
|
||||
link_items(ui, links);
|
||||
};
|
||||
let page_stack = || Stack::new().gap(Gap::Section).pad(Pad::Regular).fill_width();
|
||||
@@ -524,7 +533,7 @@ impl StartScreen<'_> {
|
||||
// `beside` is whether the rail stands beside the page; without it New and Open lead the page and the links follow
|
||||
// the sections.
|
||||
let page_body = |ui: &mut Ui, cx: &mut BodyCx<'_>, beside: bool| {
|
||||
if !beside {
|
||||
if !beside && (offers_new || offers_open) {
|
||||
let _ = Row::new().gap(Gap::Tight).show(ui, |ui, _| new_and_open(&page, ui));
|
||||
}
|
||||
host_sections(ui, StartPlace::BeforeRecent);
|
||||
@@ -581,7 +590,7 @@ fn new_and_open(page: &Page<'_>, ui: &mut Ui) {
|
||||
if page.offers_new && clicked(&Button::new(words.new.clone()).id_salt("new").variant(Variant::PRIMARY).show(ui)) {
|
||||
page.push(StartAction::New);
|
||||
}
|
||||
if clicked(&Button::new(words.open.clone()).id_salt("open").show(ui)) {
|
||||
if page.offers_open && clicked(&Button::new(words.open.clone()).id_salt("open").show(ui)) {
|
||||
page.push(StartAction::Open);
|
||||
}
|
||||
}
|
||||
@@ -631,6 +640,8 @@ fn recent_section(
|
||||
Entry::new(RecentSort::Created, words.sort_created.clone()),
|
||||
];
|
||||
let _ = Section::fixed(words.recent.clone())
|
||||
.strength(HeaderStrength::Heading)
|
||||
.quiet_header()
|
||||
.header_gap(Gap::Section)
|
||||
.command_scope(StartRecentCommands::SCOPE)
|
||||
.controls(|ui, _| {
|
||||
@@ -711,7 +722,7 @@ fn recent_section(
|
||||
};
|
||||
let row = row.trailing_part_revealed(
|
||||
REMOVE,
|
||||
TrailingFace::Icon(IconSpec::svg(IconId::new("close"))),
|
||||
TrailingFace::Strong(words.unpin.clone()),
|
||||
words.remove_recent.fill(&[("name", file.name.as_str())]),
|
||||
);
|
||||
match page.thumbnails {
|
||||
@@ -905,7 +916,7 @@ fn pinned_row<'r>(words: &ShellWords, row: PinnedRow<'_>) -> ListRow<'r> {
|
||||
}
|
||||
heading.trailing_part(
|
||||
UNPIN,
|
||||
TrailingFace::Icon(IconSpec::svg(IconId::new("close"))),
|
||||
TrailingFace::Strong(words.unpin.clone()),
|
||||
words.unpin_folder.fill(&[("name", folder.name.as_str())]),
|
||||
)
|
||||
}
|
||||
@@ -926,10 +937,12 @@ fn pinned_row<'r>(words: &ShellWords, row: PinnedRow<'_>) -> ListRow<'r> {
|
||||
fn pinned_section(page: &Page<'_>, ui: &mut Ui, folders: &[PinnedFolder]) {
|
||||
let words = page.words;
|
||||
let _ = Section::fixed(words.pinned.clone())
|
||||
.strength(HeaderStrength::Heading)
|
||||
.quiet_header()
|
||||
.header_gap(Gap::Section)
|
||||
.command_scope(StartPinnedCommands::SCOPE)
|
||||
.controls(|ui, _| {
|
||||
if clicked(&Button::new(words.pin_folder.clone()).id_salt("pin").icon(IconId::new("new_folder")).show(ui)) {
|
||||
if clicked(&Button::new(words.pin_folder.clone()).id_salt("pin").variant(Variant::GHOST).icon(IconId::new("new_folder")).show(ui)) {
|
||||
page.push(StartAction::PinFolder);
|
||||
}
|
||||
})
|
||||
@@ -994,7 +1007,7 @@ fn pinned_section(page: &Page<'_>, ui: &mut Ui, folders: &[PinnedFolder]) {
|
||||
|
||||
fn templates_section(page: &Page<'_>, ui: &mut Ui, templates: &[Template]) {
|
||||
let words = page.words;
|
||||
let _ = Section::fixed(words.templates.clone()).header_gap(Gap::Section).show(ui, |ui, _| {
|
||||
let _ = Section::fixed(words.templates.clone()).strength(HeaderStrength::Heading).quiet_header().header_gap(Gap::Section).show(ui, |ui, _| {
|
||||
let source = keyed(templates, |template: &Template| template.id.clone()).with_text(|template| Cow::Borrowed(template.name.as_str()));
|
||||
let out = page.grid::<String>(words.templates.clone(), false).show_items(ui, &source, &mut |id, _| {
|
||||
let Some(template) = templates.iter().find(|template| &template.id == id) else { return Tile::new(Label::Empty) };
|
||||
|
||||
@@ -39,6 +39,8 @@ craft_ui::words! {
|
||||
show_less: "startScreen.showLess" = "Show less";
|
||||
/// The note on a pinned folder the app kept only the newest files of.
|
||||
newest_of: template "startScreen.newestOf" = "The newest {shown} of {total}";
|
||||
/// A pinned folder's Unpin button.
|
||||
unpin: "startScreen.unpin" = "Unpin";
|
||||
/// The accessible name of a pinned folder's Unpin part.
|
||||
unpin_folder: template "startScreen.unpinFolder" = "Unpin {name}";
|
||||
|
||||
|
||||
@@ -411,3 +411,25 @@ fn folders_come_before_recent_and_recent_has_a_clear_button() {
|
||||
fixture.click(&clear).idle(2);
|
||||
assert!(log.borrow().iter().any(|action| matches!(action, StartAction::ClearRecent)), "Clear asks the app to clear the list");
|
||||
}
|
||||
|
||||
/// An app that opens files from its title bar leaves Open out of the page (`offers_open(false)`); the page's empty
|
||||
/// room still asks for Open on a double click, and the section headings are the heading role, not the panel's
|
||||
/// emphasised body text.
|
||||
#[trial]
|
||||
fn open_can_be_left_out_and_the_headings_are_page_headings() {
|
||||
let log: Log = Rc::default();
|
||||
let seen = Rc::clone(&log);
|
||||
let files = vec![RecentFile::new("/tmp/work/Poster.psd", "Poster.psd")];
|
||||
let (mut view, mut sort) = (RecentView::Grid, RecentSort::Opened);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let out = StartScreen::new(Bind::bound(&mut view), Bind::bound(&mut sort), &files).offers_new(false).offers_open(false).show(ui);
|
||||
seen.borrow_mut().extend(out.actions);
|
||||
});
|
||||
fixture.room(egui::Vec2::new(1100.0, 700.0)).settle();
|
||||
assert!(fixture.by_label("Open…").is_none(), "no Open button on the page");
|
||||
assert!(fixture.by_label("Poster.psd").is_some(), "the page still lists its recent files");
|
||||
let texts = fixture.texts();
|
||||
let recent = texts.iter().find(|run| run.text == "Recent").expect("the Recent heading");
|
||||
let file = texts.iter().find(|run| run.text == "Poster.psd").expect("a card's name");
|
||||
assert!(recent.rect.height() > file.rect.height(), "the heading is larger than card text: {:?} against {:?}", recent.rect, file.rect);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user