mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 10:48:15 +01:00
RecentList: heading_sections opt-in for a page's own section heading
The list's heading takes the heading strength with no rule above it, as StartScreen::heading_sections shows its sections (one Page::section for both). Default unchanged. Story and trial. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0f7dff8d63
commit
d70ea78c9e
3 files changed
+40
-4
No files matched your search
@@ -19,7 +19,6 @@ use crate::notices::{Notice, NoticeLayout};
|
||||
use crate::primitives::{IconSpec, ThumbSource, Thumbnails};
|
||||
use crate::runtime::commands::{self, CommandSet as _, Commands as _};
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::sections::Section;
|
||||
use crate::tile_grid::{Tile, TilePartEvent};
|
||||
use craft_behavior::{IconId, keyed};
|
||||
use craft_theme::variant::Tone;
|
||||
@@ -55,6 +54,7 @@ pub struct RecentList<'a> {
|
||||
thumbnails: Option<ThumbHost<'a>>,
|
||||
picture: (u16, u16),
|
||||
remove: RecentRemove,
|
||||
heading_sections: bool,
|
||||
}
|
||||
|
||||
impl<'a> RecentList<'a> {
|
||||
@@ -70,6 +70,7 @@ impl<'a> RecentList<'a> {
|
||||
thumbnails: None,
|
||||
picture: (PICTURE_WIDE, PICTURE_HIGH),
|
||||
remove: RecentRemove::default(),
|
||||
heading_sections: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +86,14 @@ impl<'a> RecentList<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// The heading in the heading strength with no rule above it, as `StartScreen::heading_sections` shows its
|
||||
/// sections: a list that is a page's own section (DeckCraft's Open page). By default the heading is a panel
|
||||
/// section's, under a rule.
|
||||
pub fn heading_sections(mut self) -> Self {
|
||||
self.heading_sections = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// The trailing header controls of the section, which keep their own input and focus.
|
||||
/// The callback runs per pass; controls apply only the input delivered to that pass.
|
||||
pub fn controls(mut self, controls: impl FnMut(&mut Ui, &mut BodyCx<'_>) + 'a) -> Self {
|
||||
@@ -126,7 +135,7 @@ impl<'a> RecentList<'a> {
|
||||
|
||||
/// Shows the rows in their own section and reports what the user did.
|
||||
pub fn show(self, ui: &mut Ui) -> StartOutput {
|
||||
let RecentList { recent, heading, controls, max_recent, empty, now, thumbnails, picture, remove } = self;
|
||||
let RecentList { recent, heading, controls, max_recent, empty, now, thumbnails, picture, remove, heading_sections } = self;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<ShellWords>();
|
||||
let actions = RefCell::new(Vec::new());
|
||||
@@ -146,13 +155,13 @@ impl<'a> RecentList<'a> {
|
||||
templates_title: None,
|
||||
new_label: None,
|
||||
open_label: None,
|
||||
heading_sections: false,
|
||||
heading_sections,
|
||||
remove,
|
||||
};
|
||||
let files: Vec<RecentFile> = recent.iter().take(max_recent).cloned().collect();
|
||||
let empty = empty.unwrap_or_else(|| words.no_recent.clone());
|
||||
let section =
|
||||
Section::fixed(heading.unwrap_or_else(|| words.recent.clone())).header_gap(Gap::Section).command_scope(StartRecentCommands::SCOPE);
|
||||
page.section(heading.unwrap_or_else(|| words.recent.clone())).header_gap(Gap::Section).command_scope(StartRecentCommands::SCOPE);
|
||||
let section = match controls {
|
||||
Some(controls) => section.controls(controls),
|
||||
None => section,
|
||||
|
||||
@@ -277,6 +277,14 @@ fn recent_list_remove_always(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
RecentList::new(&files).now(Some(NOW)).remove(RecentRemove::Always).show(ui).into()
|
||||
}
|
||||
|
||||
/// `RecentList::heading_sections`: the list as a page's own section, its heading in the heading strength with no
|
||||
/// rule above it.
|
||||
#[story(RecentList<'static>, covers = [], drive = Drive::Never)]
|
||||
fn recent_list_heading_sections(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let files = plain_files();
|
||||
RecentList::new(&files).heading("Presentations").heading_sections().now(Some(NOW)).show(ui).into()
|
||||
}
|
||||
|
||||
/// No recent files: the muted line under the heading, at the reading start.
|
||||
#[story(RecentList<'static>, covers = [], drive = Drive::Never)]
|
||||
fn recent_list_empty(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
|
||||
@@ -235,6 +235,25 @@ fn a_list_that_always_shows_remove_offers_it_on_every_row_at_rest() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A list that is a page's own section (`heading_sections`) shows its heading taller than the panel section's
|
||||
/// heading of the default list, so a page's section reads at the page's heading size.
|
||||
#[trial]
|
||||
fn a_heading_section_list_shows_a_taller_heading_than_the_default() {
|
||||
let heading_height = |page: bool| {
|
||||
let files = vec![RecentFile::new("/tmp/work/Poster.psd", "Poster.psd")];
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let list = RecentList::new(&files).heading("Presentations");
|
||||
let _ = if page { list.heading_sections() } else { list }.show(ui);
|
||||
});
|
||||
fixture.room(egui::Vec2::new(700.0, 500.0));
|
||||
fixture.settle();
|
||||
fixture.texts().iter().find(|run| run.text == "Presentations").map_or(0.0, |run| run.rect.height())
|
||||
};
|
||||
let (panel, page) = (heading_height(false), heading_height(true));
|
||||
assert!(panel > 0.0, "the heading shows by default");
|
||||
assert!(page > panel, "the page section's heading is taller than the panel section's: {page} against {panel}");
|
||||
}
|
||||
|
||||
/// A list that always shows remove keeps every row's remove part in one end column: a row with a note ("(missing)")
|
||||
/// shows the note before its remove part, not between the part and the row's end.
|
||||
#[trial]
|
||||
|
||||
Reference in new issue
Block a user