mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
StartScreen::pinned_title: an app names the pinned folders section (trial)
This commit is contained in:
@@ -300,6 +300,9 @@ pub struct StartScreen<'a> {
|
||||
/// click on the page's empty room still asks for Open.
|
||||
#[prop]
|
||||
offers_open: bool,
|
||||
/// The heading of the pinned folders section, in place of the built-in word.
|
||||
#[prop(into)]
|
||||
pinned_title: Option<Label>,
|
||||
/// The host's sections, each at its place, in call order.
|
||||
sections: Vec<(StartPlace, HostSection<'a>)>,
|
||||
}
|
||||
@@ -358,6 +361,7 @@ impl<'a> StartScreen<'a> {
|
||||
drop_hint: None,
|
||||
offers_new: true,
|
||||
offers_open: true,
|
||||
pinned_title: None,
|
||||
sections: Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -398,6 +402,7 @@ struct Page<'p> {
|
||||
offers_new: bool,
|
||||
/// Open… shows.
|
||||
offers_open: bool,
|
||||
pinned_title: Option<&'p Label>,
|
||||
actions: &'p RefCell<Vec<StartAction>>,
|
||||
}
|
||||
|
||||
@@ -495,12 +500,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, offers_open, sections } = self;
|
||||
let StartScreen { view, sort, recent, pinned, templates, max_recent, now, thumbnails, links, drop_hint, offers_new, offers_open, pinned_title, 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, offers_open, actions: &actions };
|
||||
let page = Page { env: &env, words: &words, thumbnails, drop_hint: drop_hint.as_ref(), now, offers_new, offers_open, pinned_title: pinned_title.as_ref(), actions: &actions };
|
||||
let view = RefCell::new(view);
|
||||
let sort = RefCell::new(sort);
|
||||
|
||||
@@ -936,7 +941,7 @@ 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())
|
||||
let _ = Section::fixed(page.pinned_title.cloned().unwrap_or_else(|| words.pinned.clone()))
|
||||
.strength(HeaderStrength::Heading)
|
||||
.quiet_header()
|
||||
.header_gap(Gap::Section)
|
||||
|
||||
@@ -433,3 +433,17 @@ fn open_can_be_left_out_and_the_headings_are_page_headings() {
|
||||
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);
|
||||
}
|
||||
|
||||
/// An app may name the pinned folders section itself (`pinned_title`), in place of the built-in "Pinned Folders".
|
||||
#[trial]
|
||||
fn the_pinned_section_takes_the_apps_title() {
|
||||
let files = vec![RecentFile::new("/tmp/work/Poster.psd", "Poster.psd")];
|
||||
let folders = vec![PinnedFolder::new("/tmp/Work", "Work")];
|
||||
let (mut view, mut sort) = (RecentView::List, RecentSort::Opened);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let _ = StartScreen::new(Bind::bound(&mut view), Bind::bound(&mut sort), &files).pinned(&folders).pinned_title("Folders").show(ui);
|
||||
});
|
||||
fixture.room(egui::Vec2::new(1100.0, 700.0)).settle();
|
||||
assert!(fixture.texts().iter().any(|run| run.text == "Folders"), "the app's title heads the section");
|
||||
assert!(!fixture.texts().iter().any(|run| run.text == "Pinned Folders"), "the built-in word is replaced");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user