list: rows in a side menu take the place row look (large body text and icon, roomy sides, segment padding)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-28 21:51:40 +00:00
1 parent 857aba8dc4
commit c7b796ec68
5 files changed
+88 -13

No files matched your search

+3 -1
View File
@@ -63,7 +63,9 @@ pub enum LinkLook {
///
/// A page's side menu (a File page's list of pages) sets `SideMenu` for its rows: a `Button` there shows its label in
/// the large body role (`TypeRole::BodyLarge`), with `space.pad.segment` above and below it and `space.pad.roomy`
/// at its sides, so the menu reads as a list of places rather than a row of controls.
/// at its sides, so the menu reads as a list of places rather than a row of controls. A `List`'s rows there take the
/// same place look (a page's own list of places beside its content: Open's places, Export's tasks): the large body
/// role and icon, roomy sides, and `space.pad.segment` above and below the line.
///
/// A page's call to action (a start page's primary link) sets `CallToAction`: a `Button` there stands
/// `size.page.action` high, its label strong.
+16 -7
View File
@@ -4,7 +4,7 @@ use super::ListRow;
use super::style::{ListRowStyle, ThumbRows};
use super::thumb::{Thumb, ThumbAspect, ThumbSize};
use super::trailing::{TrailingFace, TrailingItem, trailing_run};
use crate::buttons::Link;
use crate::buttons::{ControlPlace, Link};
use crate::contract::{ColumnAlign, RowHeight};
use crate::layout::{ShrinkOrder, ShrinkUnit, shrink_widths};
use crate::primitives::{HAlign, TextRun, Wrap};
@@ -56,15 +56,24 @@ impl Sizes {
let (control, tokens) = (cx.control(), cx.tokens);
let thumbs = &tokens.size.thumb;
let small = cx.control_of(ControlSize::Sm);
let row = if sub_row { small.height } else { rows.of(cx) };
let tight = cx.env::<ThumbRows>() == ThumbRows::Tight;
let label_line = tokens.typography.get(role).line_height;
// A row of a page's side menu is a place, as the menu's buttons are: the large icon set off from its name by a
// section gap, roomy sides, and `space.pad.segment` above and below its line.
let place = cx.env::<ControlPlace>() == ControlPlace::SideMenu && !sub_row;
let row = match () {
_ if sub_row => small.height,
_ if place => rows.of(cx).max(label_line + 2.0 * tokens.space.pad.segment),
_ => rows.of(cx),
};
let icon = if place { control.icon.max(tokens.size.icon.lg) } else { control.icon };
Sizes {
row,
icon: control.icon,
icon,
indent: if tight { small.icon + tokens.space.gap.tight } else { control.icon },
mark: if sub_row { small.icon } else { control.icon },
pad: control.pad_x,
gap: control.gap,
mark: if sub_row { small.icon } else { icon },
pad: if place { tokens.space.pad.roomy } else { control.pad_x },
gap: if place { control.gap.max(tokens.space.gap.section) } else { control.gap },
trailing_pad: tokens.space.pad.regular,
min_label: MIN_LABEL_HEIGHTS * control.height,
thumbs: [thumbs.sm, thumbs.md, thumbs.lg],
@@ -74,7 +83,7 @@ impl Sizes {
thumb_row: if tight { row } else { tokens.size.control.md + tokens.space.pad.regular },
tight: tokens.space.gap.tight,
gap_row: tokens.space.gap.row,
label_line: tokens.typography.get(role).line_height,
label_line,
detail_line: tokens.typography.get(TypeRole::Caption).line_height,
cell_inset: control.pad_x,
// A text row's wrapped cell keeps the room a text row has around its line.
+7 -1
View File
@@ -8,6 +8,7 @@ use super::style::{FillKey, ListRowStyle, RowForm, fill_of, hued_ink, quiet_row_
use super::thumb::{RowThumb, target_at};
use super::trailing::{HostedSize, TrailingFace, TrailingItem, TrailingPart, below_key, cell_key, field_key};
use super::{HueTarget, ListRow, RowDragSpot, RowInk};
use crate::buttons::ControlPlace;
use crate::contract::{
Access, Bind, Component, Cx, DragPreview, Focus as _, MeasureCx, Name, OpenChange, PaintUi, PartsCx, Pointer as _, Props as _, Role, RowPressed,
Styled as _, WordSetCx as _,
@@ -82,7 +83,12 @@ impl Component for ListRow<'_> {
RowInk::Muted => text.muted,
RowInk::Dimmed => text.faint,
};
let role = key.role.unwrap_or(if key.strong { TypeRole::BodyStrong } else { TypeRole::Body });
// A side menu's row names its place in the large body role, as the menu's buttons do.
let role = key.role.unwrap_or(match () {
_ if key.strong => TypeRole::BodyStrong,
_ if cx.env::<ControlPlace>() == ControlPlace::SideMenu && !key.sub_row => TypeRole::BodyLarge,
_ => TypeRole::Body,
});
let sizes = Sizes::of(cx, role, key.rows, key.sub_row);
let muted = if key.ink == RowInk::Dimmed { text.faint } else { text.muted };
ListRowStyle {
+30 -4
View File
@@ -5,16 +5,16 @@ use super::{
EventLevel, EventList, EventLog, EventLogState, Finding, Findings, FindingsList, FindingsSummary, List, ListRow, LogEvent, OpenSet, RowEvent,
RowInk, Severity, ThumbSize, ThumbTarget, ToggleCell, UndoList, UndoMark, UndoRows, footer_text,
};
use crate::buttons::Button;
use crate::buttons::{Button, ControlPlace};
use crate::contract::{
Bind, CollectionEvent, ColumnSpec, DragScope, DragSelection, Entry, Props as _, ReorderRule, ScrollAnchor, Show as _, ShowCollection as _,
ShowContainer as _, ToggleColumn, ToggleEdit, WordSetCx as _, request_rename,
Bind, CollectionEvent, ColumnSpec, DragScope, DragSelection, Entry, LeastWidth, Props as _, ReorderRule, ScrollAnchor, SelectMode, Show as _,
ShowCollection as _, ShowContainer as _, Sizing, ToggleColumn, ToggleEdit, WordSetCx as _, request_rename,
};
use crate::layout_components::Stack;
use crate::menu::Menu;
use crate::popover::Popover;
use crate::primitives::{ContentPainterCx, IconSpec, Span};
use crate::runtime::env::{Env, Label};
use crate::runtime::env::{Env, Label, with_env};
use crate::style::{Corners, SurfaceKind};
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, ValueAt, story};
use crate::tile_grid::GroupHeads;
@@ -55,6 +55,32 @@ fn list(ui: &mut Ui, count: usize) -> StoryOutput {
List::<usize>::new("Layers").empty("No layers").show_items(ui, &Names(&names), &mut |key, _| ListRow::new(names[*key].clone())).into()
}
/// A page's own list of places beside its content, in the `SideMenu` place: large rows with the large icon and the
/// large body text, one of them chosen, as a File page's Open places show them.
#[story(List<'static, usize>, covers = [], drive = Drive::Never, title = "In a side menu")]
fn list_in_side_menu(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let places = [("Home", "home"), ("Browse", "open"), ("Saved", "save")];
let names: Vec<String> = places.iter().map(|(name, _)| (*name).to_owned()).collect();
let shown = Stack::new().least_width(LeastWidth::SideMenu).show(ui, |ui, _| {
with_env(
ui,
|overrides| {
overrides.values.set(ControlPlace::SideMenu);
},
|ui| {
let selection = data.bind("selection", Selection::single(0_usize));
List::<usize>::new("Open from")
.select(SelectMode::Single)
.sizing(Sizing::FillWidth)
.natural_height(true)
.selection(selection)
.show_items(ui, &Names(&names), &mut |key, _| ListRow::new(names[*key].clone()).icon(IconSpec::svg(IconId::new(places[*key].1))));
},
);
});
shown.into()
}
const EYE: ColumnKey = ColumnKey::new("eye");
const NAME: ColumnKey = ColumnKey::new("name");
+32
View File
@@ -1,8 +1,10 @@
//! List rows: the rename draft, the row menu and the trailing parts a row reveals.
use craft_behavior::{EditEvent, Mixed, keyed};
use craft_ui::buttons::ControlPlace;
use craft_ui::contract::{CollectionEvent, Props as _, RowHeight, ShowCollection as _, request_rename};
use craft_ui::list::{List, ListRow, RowEvent};
use craft_ui::runtime::env::with_env;
use craft_ui::testing::{Fixture, trial};
use egui::{Id, Vec2};
use std::cell::RefCell;
@@ -95,6 +97,36 @@ fn text_rows_are_shorter_than_control_rows() {
assert!(text[2].top() - text[0].top() < control[2].top() - control[0].top(), "text rows follow each other closer");
}
/// The rects of the three rows of a list shown in `place`.
fn placed_rects(place: ControlPlace) -> Vec<egui::Rect> {
let mut fixture = Fixture::new(move |ui| {
with_env(
ui,
|overrides| {
overrides.values.set(place);
},
|ui| {
let keys = [0_usize, 1, 2];
let source = keyed(&keys, |key: &usize| *key).with_text(|key| std::borrow::Cow::Borrowed(NAMES[*key]));
List::new("Places").natural_height(true).show_items(ui, &source, &mut |key, _| ListRow::new(NAMES[*key]));
},
);
});
fixture.room(Vec2::new(300.0, 300.0));
fixture.settle();
NAMES.iter().map(|name| fixture.by_label(name).expect("the row's node").rect).collect()
}
/// A page's own list of places in the side menu's place stands its rows taller than the same list elsewhere, as the
/// menu's buttons stand, so Open's places and Export's tasks read as places.
#[trial]
fn a_list_in_a_side_menu_has_taller_place_rows() {
let (standard, side) = (placed_rects(ControlPlace::Standard), placed_rects(ControlPlace::SideMenu));
for (standard, side) in standard.iter().zip(&side) {
assert!(side.height() > standard.height(), "a side-menu row is taller: {side:?} against {standard:?}");
}
}
/// The text the rename field of `row` opens with.
fn opened_with(draft: fn(&usize) -> Option<String>, row: usize) -> Option<String> {
let (mut fixture, seen) = rig(draft);