diff --git a/crates/ui-contract/src/contract/label.rs b/crates/ui-contract/src/contract/label.rs index 3becbef258..f5eb275593 100644 --- a/crates/ui-contract/src/contract/label.rs +++ b/crates/ui-contract/src/contract/label.rs @@ -14,7 +14,7 @@ pub use leaf::colon_of; pub(crate) use place::{control_after, label_gap}; pub(crate) use props::inside; pub use props::{ - CaptionColumn, CaptionInk, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, LinkLabelInk, - LinkLabelUnderline, Scrub, SideLabel, + CaptionColumn, CaptionInk, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelGap, LabelKind, LabelPress, LabelScheme, + LinkLabelInk, LinkLabelUnderline, Scrub, SideLabel, }; pub(crate) use step::{LabelIn, LeafLabel, Trailing, flow_leaf, in_column, leaf, leaf_under, report_after_reach, run, show_leaf_in_flow}; diff --git a/crates/ui-contract/src/contract/label/place.rs b/crates/ui-contract/src/contract/label/place.rs index 7b972ba76d..d61e348f5d 100644 --- a/crates/ui-contract/src/contract/label/place.rs +++ b/crates/ui-contract/src/contract/label/place.rs @@ -1,7 +1,7 @@ //! Where the label and its control sit: the beside, above and after placements and the gap. use super::leaf::{LabelLeaf, colon}; -use super::props::{CaptionColumn, FieldLayout, LabelKind, LabelScheme}; +use super::props::{CaptionColumn, FieldLayout, LabelGap, LabelKind, LabelScheme}; use super::step::LabelIn; use crate::contract::Show; use crate::runtime::access::scope::{self}; @@ -232,10 +232,16 @@ fn widened(flow: Flow, need: f32, grows: Grows) -> Flow { Flow::new(wide, flow.is_rtl()) } -/// The gap between a label and its control: `space.gap.inline`, `space.gap.item` inside a bar. +/// The gap between a label and its control: `space.gap.item` inside a bar, else the scope's [`LabelGap`]. pub(crate) fn label_gap(env: &Env) -> f32 { let gaps = &env.tokens.space.gap; - if env.values.get::().0 { gaps.item } else { gaps.inline } + if env.values.get::().0 { + return gaps.item; + } + match env.values.get::() { + LabelGap::Inline => gaps.inline, + LabelGap::Section => gaps.section, + } } /// Where the control sits once `input.control_min` is known: the decision `run` takes, without showing the label. A diff --git a/crates/ui-contract/src/contract/label/props.rs b/crates/ui-contract/src/contract/label/props.rs index 664694405b..95bb38c141 100644 --- a/crates/ui-contract/src/contract/label/props.rs +++ b/crates/ui-contract/src/contract/label/props.rs @@ -191,6 +191,25 @@ impl crate::runtime::env::EnvValue for CaptionColumn { } } +/// The gap between a beside label's column and its control, outside a bar (a bar's labels keep `space.gap.item`). A +/// container sets it for what it holds (`with_env`). +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, crate::contract::MemoProps)] +#[non_exhaustive] +pub enum LabelGap { + /// `space.gap.inline`: the label reads with its control, as in a panel or a dialog. + #[default] + Inline, + /// `space.gap.section`: a page's property list, whose values stand in their own column apart from the names + /// (DeckCraft's Info page). + Section, +} + +impl crate::runtime::env::EnvValue for LabelGap { + fn root() -> Self { + LabelGap::Inline + } +} + /// Where a side label sits relative to its control. #[derive(Clone, Copy, Debug, Default, PartialEq)] #[non_exhaustive] diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 3cb6370c90..66a98f1051 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -98,8 +98,8 @@ pub use items::{measure_item, show_item, show_item_in_flow}; #[doc(hidden)] pub use label::colon_of; pub use label::{ - CaptionColumn, CaptionInk, CellWidth, FieldLabelRole, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, - LinkLabelInk, LinkLabelUnderline, Scrub, SideLabel, + CaptionColumn, CaptionInk, CellWidth, FieldLabelRole, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelGap, LabelKind, LabelPress, + LabelScheme, LinkLabelInk, LinkLabelUnderline, Scrub, SideLabel, }; pub use lazy::Lazy; #[doc(hidden)] diff --git a/crates/ui-shell/src/shell/recent_list.rs b/crates/ui-shell/src/shell/recent_list.rs index 9fb7c58f47..ec2ad71e10 100644 --- a/crates/ui-shell/src/shell/recent_list.rs +++ b/crates/ui-shell/src/shell/recent_list.rs @@ -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>, 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::(); 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 = 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, diff --git a/crates/ui-shell/src/shell/start/stories.rs b/crates/ui-shell/src/shell/start/stories.rs index 2b91b39372..edb2889cd0 100644 --- a/crates/ui-shell/src/shell/start/stories.rs +++ b/crates/ui-shell/src/shell/start/stories.rs @@ -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 { diff --git a/crates/ui-shell/tests/it/shell/start.rs b/crates/ui-shell/tests/it/shell/start.rs index bc0d532f08..f215124268 100644 --- a/crates/ui-shell/tests/it/shell/start.rs +++ b/crates/ui-shell/tests/it/shell/start.rs @@ -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] diff --git a/crates/ui-widgets/src/form/stories.rs b/crates/ui-widgets/src/form/stories.rs index 22a0f80dd5..3d09b97d45 100644 --- a/crates/ui-widgets/src/form/stories.rs +++ b/crates/ui-widgets/src/form/stories.rs @@ -5,13 +5,14 @@ use super::{Field, FieldGroup}; use crate::buttons::Link; use crate::choice::Swatch; use crate::contract::{ - CaptionInk, FieldLayout, GlyphColon, GlyphLabel, LabelKind, LabelScheme, LinkLabelInk, Props as _, Show as _, ShowContainer as _, SideLabel, - Validity, + CaptionInk, FieldLayout, GlyphColon, GlyphLabel, LabelGap, LabelKind, LabelScheme, LinkLabelInk, Props as _, Show as _, ShowContainer as _, + SideLabel, Validity, }; +use crate::display::Text; use crate::layout_components::{Row, Stack}; use crate::runtime::env::{Message, with_env}; use crate::testing::{Drive, StoryData, StoryOutput, story}; -use crate::text::{HexField, NumberField}; +use crate::text::{HexField, NumberField, TextField}; use craft_behavior::IconId; use craft_theme::Srgba; use craft_theme::variant::Tone; @@ -191,6 +192,25 @@ fn field_glyph_captions_with_colons(ui: &mut Ui, data: &mut StoryData) -> StoryO .into() } +/// A page's property list under `LabelGap::Section`: the values stand in their own column, a section gap past the +/// widest name, so a value never reads as part of its name. +#[story(FieldGroup, covers = [], drive = Drive::Never)] +fn field_property_list_gap(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + with_env( + ui, + |overrides| { + overrides.values.set(LabelGap::Section); + }, + |ui| { + FieldGroup::new("Properties").labels(LabelScheme::Inspector).show(ui, |ui, _| { + Field::new("Hidden slides").value("0").show(ui, |ui, _| Text::new("0").show(ui)); + Field::new("Title").show(ui, |ui, _| TextField::new("Title", data.bind("title", String::new())).placeholder("Add a title").show(ui)); + }) + }, + ) + .into() +} + /// The rows of an inspector: glyph labels W and H sharing a row, word labels at the row's start without a colon, and /// controls that fill the rest of the row. #[story(FieldGroup, covers = [], drive = Drive::Never)] diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index e753a3ad35..5f2ddd38c3 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -14,7 +14,7 @@ use super::layout::{ normalize_columns, slot_at, }; use super::tile::AroundPicture; -use super::{CaptionPlace, CardText, PictureEdge, Tile, TileActionPlace, TilePartEvent, TileZoom, ZoomStep}; +use super::{CaptionPlace, CaptionType, CardText, PictureEdge, Tile, TileActionPlace, TilePartEvent, TileZoom, ZoomStep}; use crate::contract::{ Access, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, ColumnKind, ColumnSpec, Common, Component, ContainerProps, Cx, DragPayload, DragPreview, DropKind, DropMark, DropTarget, EditResponse, Focus as _, ListDrag, Meta as _, NoValue, Notch, @@ -233,13 +233,21 @@ struct GridSizes { } impl GridSizes { - fn of(cx: &StyleCx<'_>, card: bool, text: CardText, rows: RowHeight, regular_card_padding: bool, action_place: TileActionPlace) -> GridSizes { + fn of( + cx: &StyleCx<'_>, + card: bool, + text: CardText, + caption_type: CaptionType, + rows: RowHeight, + regular_card_padding: bool, + action_place: TileActionPlace, + ) -> GridSizes { let spacing = ArrangeSpacing::new(if card { cx.tokens.space.gap.section } else { cx.tokens.space.gap.stack }, cx.tokens.space.gap.inline, rows.of(cx)); GridSizes { card: cx.tokens.size.thumb.card, thumbs: [cx.tokens.size.thumb.sm, cx.tokens.size.thumb.md, cx.tokens.size.thumb.lg], - around: Tile::around(cx, card, text, regular_card_padding, action_place), + around: Tile::around(cx, card, text, caption_type, regular_card_padding, action_place), spacing, // Bare tiles sit with no gap between them: the room around each picture keeps them apart. bare_spacing: if card { spacing } else { ArrangeSpacing { gap: 0.0, ..spacing } }, @@ -349,6 +357,9 @@ pub struct TileGrid<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { /// name of a preset. #[prop] card_text: CardText, + /// The type of every tile's name when the tiles are not cards: small print by default, or body text. + #[prop] + caption_type: CaptionType, /// Framed cards use the theme's regular padding around their picture and caption. #[prop(flag)] regular_card_padding: bool, @@ -507,6 +518,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> { detail_line: false, card: false, card_text: CardText::File, + caption_type: CaptionType::Small, regular_card_padding: false, picture_edge: PictureEdge::Open, groups: &[], @@ -633,7 +645,8 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> { /// A card is the picture plus what the tile adds around it in every tiling. fn laid_out(&self, source: &dyn ItemSource, room: Vec2, item: Option, cx: &StyleCx<'_>) -> GridLayout { let width = room.x.max(1.0); - let style = GridSizes::of(cx, self.card, self.card_text, self.items.row_height, self.regular_card_padding, self.action_place); + let style = + GridSizes::of(cx, self.card, self.card_text, self.caption_type, self.items.row_height, self.regular_card_padding, self.action_place); let ruled = self.group_heads == GroupHeads::Rule; let mut spacing = style.spacing(self.caption).ruled(ruled); let around = style.around.get(self.caption, self.detail_line); @@ -1281,14 +1294,25 @@ impl Collection for TileGrid<'_, K fn dress_inputs(&self) -> u64 { use std::hash::{Hash as _, Hasher as _}; let mut hasher = std::collections::hash_map::DefaultHasher::new(); - (self.caption, self.detail_line, self.card, self.card_text, self.regular_card_padding, self.picture_edge, self.action_place, self.checks) + ( + self.caption, + self.detail_line, + self.card, + self.card_text, + self.caption_type, + self.regular_card_padding, + self.picture_edge, + self.action_place, + self.checks, + ) .hash(&mut hasher); hasher.finish() } /// The width of the requested card columns, their gaps and the content inset. fn ideal_width(&self, item: Option, _rows: usize, cx: &StyleCx<'_>) -> f32 { - let style = GridSizes::of(cx, self.card, self.card_text, self.items.row_height, self.regular_card_padding, self.action_place); + let style = + GridSizes::of(cx, self.card, self.card_text, self.caption_type, self.items.row_height, self.regular_card_padding, self.action_place); let around = style.around.get(self.caption, self.detail_line); let aspect = self.picture_aspect(item, around); let card = style.card(self.picture_side(&style, item, around), aspect, around).x; @@ -1318,6 +1342,7 @@ impl Collection for TileGrid<'_, K fn dress<'r>(&self, tile: Self::Item<'r>, row: &RowState) -> Self::Item<'r> { let tile = tile .caption(self.caption) + .caption_type(self.caption_type) .detail_line(self.detail_line) .picture_edge(self.picture_edge) .action_place(self.action_place) diff --git a/crates/ui-widgets/src/tile_grid/mod.rs b/crates/ui-widgets/src/tile_grid/mod.rs index 5bb97c455a..5ced3885a9 100644 --- a/crates/ui-widgets/src/tile_grid/mod.rs +++ b/crates/ui-widgets/src/tile_grid/mod.rs @@ -41,6 +41,28 @@ pub enum CaptionPlace { None, } +/// The type of the name under the picture of a tile that is not a card (a card's name follows its [`CardText`]). +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum CaptionType { + /// Small print in the muted ink: a grid of many pictures, where the name only labels the picture. + #[default] + Small, + /// Body text in the normal ink: a page of a few large choices, each named in reading size (DeckCraft's New and + /// Home pages). + Body, +} + +impl CaptionType { + /// The type role of the name. + pub(crate) fn role(self) -> craft_theme::TypeRole { + match self { + CaptionType::Small => craft_theme::TypeRole::Caption, + CaptionType::Body => craft_theme::TypeRole::Body, + } + } +} + /// How a framed card (`TileGrid::card`) sets its name and detail. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] diff --git a/crates/ui-widgets/src/tile_grid/stories.rs b/crates/ui-widgets/src/tile_grid/stories.rs index 686cbb7d85..f8cf547f40 100644 --- a/crates/ui-widgets/src/tile_grid/stories.rs +++ b/crates/ui-widgets/src/tile_grid/stories.rs @@ -1,8 +1,8 @@ //! Stories of `Tile` and `ThumbnailSlider`. use super::{ - BadgeKind, BadgeSlot, BadgeVisibility, CaptionPlace, CardText, GlyphLayout, StackLook, ThumbnailSlider, Tile, TileBadge, TileFlag, TileMark, - TilePartEvent, TileStatus, TileZoom, + BadgeKind, BadgeSlot, BadgeVisibility, CaptionPlace, CaptionType, CardText, GlyphLayout, StackLook, ThumbnailSlider, Tile, TileBadge, TileFlag, + TileMark, TilePartEvent, TileStatus, TileZoom, }; use crate::contract::{Props as _, Show as _, Validity}; use crate::list::{ThumbAspect, ToggleState}; @@ -200,6 +200,18 @@ fn tile_wrapped_caption(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { .into() } +/// `CaptionType::Body`: the name under the picture in body text and the normal ink, as a page of a few large choices +/// names them. +#[story(Tile<'static>, covers = [], drive = Drive::Never)] +fn tile_body_caption(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + Tile::new("Blank Presentation") + .caption(CaptionPlace::BelowWrapped) + .caption_type(CaptionType::Body) + .thumb(ThumbAspect::new(16, 9), StoryPictures::of(ui.ctx()).thumb(1)) + .show(ui) + .into() +} + /// A disabled tile: its picture, badge, stars and label colour fade with it. #[story(Tile<'static>, covers = [], drive = Drive::Never)] fn tile_disabled(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { diff --git a/crates/ui-widgets/src/tile_grid/tile.rs b/crates/ui-widgets/src/tile_grid/tile.rs index 28a79fa619..8f7de12305 100644 --- a/crates/ui-widgets/src/tile_grid/tile.rs +++ b/crates/ui-widgets/src/tile_grid/tile.rs @@ -8,7 +8,7 @@ use super::layout::Around; use super::words::TileWords; -use super::{BadgeKind, BadgeSlot, BadgeVisibility, CaptionPlace, CardText, TileBadge, TileFlag, TileMark, TileStatus}; +use super::{BadgeKind, BadgeSlot, BadgeVisibility, CaptionPlace, CaptionType, CardText, TileBadge, TileFlag, TileMark, TileStatus}; use crate::buttons::IconButton; use crate::choice::{Checkbox, ChoiceWords, Rating}; use crate::contract::{ @@ -183,9 +183,16 @@ pub(super) struct AroundPicture { } impl AroundPicture { - fn of(cx: &StyleCx<'_>, card: bool, text: CardText, regular_card_padding: bool, action_place: TileActionPlace) -> AroundPicture { + fn of( + cx: &StyleCx<'_>, + card: bool, + text: CardText, + caption_type: CaptionType, + regular_card_padding: bool, + action_place: TileActionPlace, + ) -> AroundPicture { let around = |place: CaptionPlace, detail: bool| { - let sizes = Sizes::of(cx, card, text, place, regular_card_padding); + let sizes = Sizes::of(cx, card, text, caption_type, place, regular_card_padding); let mut around = sizes.around(place, detail); if action_place == TileActionPlace::Band { around.start = sizes.glyph + sizes.column(place); @@ -221,7 +228,7 @@ impl AroundPicture { impl Sizes { /// The sizes of a tile with its caption in `place`. A bare tile keeps only the room its selection ring draws in, so /// a grid packs bare tiles close. - fn of(cx: &StyleCx<'_>, card: bool, text: CardText, place: CaptionPlace, regular_card_padding: bool) -> Sizes { + fn of(cx: &StyleCx<'_>, card: bool, text: CardText, caption_type: CaptionType, place: CaptionPlace, regular_card_padding: bool) -> Sizes { let (tokens, control) = (cx.tokens, cx.control()); let line = tokens.typography.get(TypeRole::Caption).line_height; let name_lines = match (place, card) { @@ -229,7 +236,8 @@ impl Sizes { (_, true) => text.name_lines(), (_, false) => 1, }; - let name_line = f32::from(name_lines) * if card { tokens.typography.get(text.name_role()).line_height } else { line }; + let name_role = if card { text.name_role() } else { caption_type.role() }; + let name_line = f32::from(name_lines) * tokens.typography.get(name_role).line_height; let inset = match (card, place) { (true, _) if regular_card_padding => tokens.space.pad.regular, (true, _) => tokens.space.pad.control, @@ -441,6 +449,10 @@ pub struct Tile<'a> { #[style_key] #[prop] card_text: CardText, + /// The type of the name of a tile that is not a card; the grid's, applied to its tiles. + #[style_key] + #[prop] + caption_type: CaptionType, /// Draws the preview directly on the tile so a small symbol has no separate background or selection frame. #[style_key] #[prop(flag)] @@ -563,6 +575,7 @@ impl<'a> Tile<'a> { detail_line: false, card: false, card_text: CardText::File, + caption_type: CaptionType::Small, flat_thumbnail: false, picture_edge: PictureEdge::Open, paper: None, @@ -686,12 +699,19 @@ impl<'a> Tile<'a> { /// What a tile adds around its picture: its padding, the caption band under the picture or the column at its /// reading start. A tile grid sizes a tile as the picture plus this. pub fn around_picture(cx: &StyleCx<'_>, place: CaptionPlace, detail: bool) -> Around { - Sizes::of(cx, false, CardText::File, place, false).around(place, detail) + Sizes::of(cx, false, CardText::File, CaptionType::Small, place, false).around(place, detail) } /// What a tile adds around its picture for every caption arrangement. - pub(super) fn around(cx: &StyleCx<'_>, card: bool, text: CardText, regular_card_padding: bool, action_place: TileActionPlace) -> AroundPicture { - AroundPicture::of(cx, card, text, regular_card_padding, action_place) + pub(super) fn around( + cx: &StyleCx<'_>, + card: bool, + text: CardText, + caption_type: CaptionType, + regular_card_padding: bool, + action_place: TileActionPlace, + ) -> AroundPicture { + AroundPicture::of(cx, card, text, caption_type, regular_card_padding, action_place) } /// Whether the caption band holds a detail line. @@ -909,7 +929,7 @@ impl Component for Tile<'_> { let (state, text) = (&colors.state, &colors.text); let clear = Rgba::TRANSPARENT; let c = |rgba: Rgba| cx.color(rgba); - let sizes = Sizes::of(cx, key.card, key.card_text, key.caption, key.regular_card_padding); + let sizes = Sizes::of(cx, key.card, key.card_text, key.caption_type, key.caption, key.regular_card_padding); // Band tiles use the collection's selection fill over the whole tile. Otherwise selection and hover are rings // around the picture; only a card has a fill of its own. let fill = if key.action_place == TileActionPlace::Band { @@ -990,12 +1010,12 @@ impl Component for Tile<'_> { )) .gap(sizes.tight), focus: cx.focus_look(), - name: if key.card { - TextLook::new(key.card_text.name_role(), ink(c(text.normal))) - } else { - TextLook::new(TypeRole::Caption, ink(c(text.muted))) + name: match (key.card, key.caption_type) { + (true, _) => TextLook::new(key.card_text.name_role(), ink(c(text.normal))), + (false, CaptionType::Body) => TextLook::new(CaptionType::Body.role(), ink(c(text.normal))), + (false, _) => TextLook::new(CaptionType::Small.role(), ink(c(text.muted))), }, - name_failed: TextLook::new(if key.card { key.card_text.name_role() } else { TypeRole::Caption }, ink(cx.tone(Tone::Bad))), + name_failed: TextLook::new(if key.card { key.card_text.name_role() } else { key.caption_type.role() }, ink(cx.tone(Tone::Bad))), glyph: TextLook::new(TypeRole::Title, ink(c(text.normal))), detail: TextLook::new(TypeRole::Caption, ink(c(if key.card { text.muted } else { text.faint }))), band_text: TextLook::new(TypeRole::Caption, fixed(text.on_status)).on(fixed(colors.status.bad.solid)), diff --git a/crates/ui-widgets/tests/it/label/scheme.rs b/crates/ui-widgets/tests/it/label/scheme.rs index 8bcf43cf6c..6f1b5a6e1d 100644 --- a/crates/ui-widgets/tests/it/label/scheme.rs +++ b/crates/ui-widgets/tests/it/label/scheme.rs @@ -2,8 +2,11 @@ use craft_ui::bars::{Bar, BarKind}; use craft_ui::choice::{Checkbox, Radio, RadioGroup}; -use craft_ui::contract::{Bind, FieldLayout, GlyphColon, GlyphLabel, LabelKind, LabelScheme, Props as _, Show as _, ShowContainer as _, SideLabel}; +use craft_ui::contract::{ + Bind, FieldLayout, GlyphColon, GlyphLabel, LabelGap, LabelKind, LabelScheme, Props as _, Show as _, ShowContainer as _, SideLabel, +}; use craft_ui::form::{Field, FieldGroup}; +use craft_ui::runtime::env::with_env; use craft_ui::testing::{Fixture, trial}; use craft_ui::text::{HexField, NumberField}; use egui::{Rect, Ui}; @@ -57,6 +60,36 @@ fn a_form_and_an_inspector_lay_out_the_same_rows_their_own_way() { assert!(short.width() > kept.width() + SLACK, "an inspector's control fills the row, a form's keeps its width: {short:?} {kept:?}"); } +/// Under `LabelGap::Section` an inspector's controls stand farther from the widest caption than under the default +/// gap, so a readout's value does not run into its name. +#[trial] +fn a_section_label_gap_sets_the_controls_apart_from_the_widest_caption() { + let gap = |wide: LabelGap| { + let mut fixture = Fixture::new(move |ui| { + with_env( + ui, + |overrides| { + overrides.values.set(wide); + }, + |ui| { + FieldGroup::new("Shape").labels(LabelScheme::Inspector).show(ui, |ui, _| { + for name in [SHORT, LONG] { + Field::new(name).show(ui, |ui, _| { + NumberField::new(name, Bind::given(Some(8.0))).show(ui); + }); + } + }) + }, + ); + }); + fixture.settle(); + control(&fixture, LONG).min.x - caption(&fixture, LONG).max.x + }; + let (inline, section) = (gap(LabelGap::Inline), gap(LabelGap::Section)); + assert!(inline >= 0.0, "the control follows its caption: {inline}"); + assert!(section > inline + SLACK, "the section gap sets the control farther off: {section} against {inline}"); +} + /// An inline form sets each caption at the row's start with a colon, its control right after it at its own width: the /// controls share no column. #[trial] diff --git a/crates/ui-widgets/tests/it/tile_grid/tile.rs b/crates/ui-widgets/tests/it/tile_grid/tile.rs index 05cc387c59..699903b169 100644 --- a/crates/ui-widgets/tests/it/tile_grid/tile.rs +++ b/crates/ui-widgets/tests/it/tile_grid/tile.rs @@ -6,7 +6,7 @@ use craft_ui::contract::{Props as _, Show as _}; use craft_ui::list::ThumbAspect; use craft_ui::testing::layout::in_region; use craft_ui::testing::{Frames, trial}; -use craft_ui::tile_grid::{BadgeVisibility, CaptionPlace, CardText, Tile, TileFlag}; +use craft_ui::tile_grid::{BadgeVisibility, CaptionPlace, CaptionType, CardText, Tile, TileFlag}; use egui::{Color32, Rect, Shape, pos2, vec2}; /// The tile's rect and the bounds of the glyphs (stars and flag) and colour dots it paints in a region `width` wide. @@ -559,6 +559,31 @@ fn a_wrapped_caption_sets_a_long_name_on_two_lines() { assert_eq!(short_tile.height(), tile.height(), "the band keeps both lines whatever the name"); } +/// A body caption sets the name of a tile that is not a card taller than the default small caption, and the tile +/// grows its caption band to hold it, so the name stays inside the tile. +#[trial] +fn a_body_caption_sets_the_name_larger_inside_a_taller_tile() { + let shown = |caption_type: CaptionType| { + let mut frames = Frames::new(); + let mut tile = Rect::NOTHING; + for _ in 0..3 { + frames.frame(Vec::new(), |ui| { + let region = Rect::from_min_size(pos2(0.0, 0.0), vec2(180.0, 300.0)); + tile = in_region(ui, region, |ui| { + Tile::new("Slate").caption_type(caption_type).thumb(ThumbAspect::new(16, 9), |_, _| {}).show(ui).response.rect + }); + }); + } + let name = frames.texts().iter().find(|line| line.text == "Slate").expect("the name is painted").rect; + (tile, name) + }; + let (small_tile, small) = shown(CaptionType::Small); + let (body_tile, body) = shown(CaptionType::Body); + assert!(body.height() > small.height(), "the body name is taller: {body:?} against {small:?}"); + assert!(body_tile.height() > small_tile.height(), "the tile grows with its name: {body_tile:?} against {small_tile:?}"); + assert!(body_tile.contains_rect(body), "the name is inside the tile: {body:?} in {body_tile:?}"); +} + /// Rich item content stays out of the grid until the pointer rests long enough to open its tooltip layer. #[trial] fn an_items_painted_tip_shows_after_the_pointer_rests_on_it() {