Home layout: the rail's look from before the PhotoCraft port

The desktop Home layout (`StartScreen::home_layout`) drew its rail with the
dialog button look and inline links: pill New and Open, Home as a filled pill,
Learn and the community links underlined in the link colour, and the page
title as a Display heading. The rail is back to how PhotoCraft drew it before
it moved onto the framework (photocraft#15449):

- New and Open at the control radius.
- Every link a full-width row with its icon: muted at rest, normal under the
  pointer; a URL row opens its URL (its tooltip), a command row fires it.
- The selected row (Home) keeps normal ink and has an accent bar at its
  leading edge.
- The page title as a Heading.

Only the Home layout changes; the other start-screen layouts keep their links.

Part of photocraft#15476

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-21 11:54:42 +01:00
1 parent 2946b2041a
commit efb06e9951
2 files changed
+118 -4

No files matched your search

+84 -4
View File
@@ -59,6 +59,13 @@ const HOME_DROP_ICON: f32 = 34.0;
// design: allow[literal-size/vec2](the desktop Home page's outer margins are larger than any spacing token)
const HOME_DESKTOP_INSET: Vec2 = vec2(36.0, 54.0);
const HOME_DROP_LOOK: CustomVariant = CustomVariant::new::<ButtonStyleKey>("craft_ui.home-drop", home_drop_look);
/// New and Open on the desktop Home page: the control radius, not the pill of dialog buttons.
const HOME_NEW_LOOK: CustomVariant = CustomVariant::new::<ButtonStyleKey>("craft_ui.home-new", home_new_look);
const HOME_OPEN_LOOK: CustomVariant = CustomVariant::new::<ButtonStyleKey>("craft_ui.home-open", home_open_look);
/// A row of the Home rail (Home, Learn, the community links): no edge or fill at rest, muted ink that turns normal
/// under the pointer. The selected row keeps normal ink and an accent bar at its leading edge.
const HOME_ROW_LOOK: CustomVariant = CustomVariant::new::<ButtonStyleKey>("craft_ui.home-row", home_row_look);
const HOME_ROW_SELECTED_LOOK: CustomVariant = CustomVariant::new::<ButtonStyleKey>("craft_ui.home-row-selected", home_row_selected_look);
/// The revealed part of a recent row that takes the file off the list.
pub(super) const REMOVE: TrailingPart = TrailingPart::new(0);
@@ -586,9 +593,9 @@ impl HomeLayout<'_> {
Stack::new().id_salt("home-page").fill().pad(Pad::Regular).gap(gap).scroll(Scroll::vertical()).show_at(ui, content, |ui, cx| {
let top = ui.available_rect_before_wrap().top();
if !wide {
let _ = Row::new().gap(Gap::Tight).fill_width().show(ui, |ui, _| new_and_open(page, ui, Sizing::FillWidth));
let _ = Row::new().gap(Gap::Tight).fill_width().show(ui, |ui, _| home_new_and_open(page, ui));
}
let _ = Text::new(self.title.clone()).role(TypeRole::Display).show(ui);
let _ = Text::new(self.title.clone()).role(TypeRole::Heading).show(ui);
home_divider(ui);
sections(ui, cx, top + content.height() / 2.0, wide);
if !wide {
@@ -604,7 +611,7 @@ impl HomeLayout<'_> {
let stack = || Stack::new().id_salt("home-rail").pad(Pad::Regular).gap(Gap::Section);
let top = |ui: &mut Ui| {
let _ = Stack::new().id_salt("home-actions").gap(Gap::Stack).fill_width().show(ui, |ui, _| {
new_and_open(page, ui, Sizing::FillWidth);
home_new_and_open(page, ui);
});
home_divider(ui);
home_links(ui, page, "home-nav", links, Gap::Section);
@@ -654,7 +661,8 @@ fn home_columns(room: Rect, rtl: bool) -> (Rect, Rect) {
fn home_links(ui: &mut Ui, page: &Page<'_>, id: &'static str, links: &[StartLink], gap: Gap) {
if !links.is_empty() {
let _ = Stack::new().id_salt(id).gap(gap).label(page.words.start_links.clone()).fill_width().show(ui, |ui, _| link_items(ui, links, true));
let _ =
Stack::new().id_salt(id).gap(gap).label(page.words.start_links.clone()).fill_width().show(ui, |ui, cx| home_link_items(ui, cx, links));
}
}
@@ -675,6 +683,78 @@ fn home_edge(tokens: &Tokens) -> Rgba {
if color.line.divider == color.surface.canvas { color.text.faint } else { color.line.divider }
}
fn home_new_look(tokens: &Tokens) -> VariantLook {
Variant::PRIMARY.resolve(tokens).radius(RadiusStep::Control)
}
fn home_open_look(tokens: &Tokens) -> VariantLook {
home_drop_look(tokens)
}
fn home_row_look(tokens: &Tokens) -> VariantLook {
let mut look = Variant::GHOST.resolve(tokens).radius(RadiusStep::Control);
look.text.rest = tokens.color.text.muted;
look.muted.rest = tokens.color.text.muted;
look
}
fn home_row_selected_look(tokens: &Tokens) -> VariantLook {
Variant::GHOST.resolve(tokens).radius(RadiusStep::Control)
}
/// New and Open on the desktop Home page, filling the rail (or the narrow page's row).
fn home_new_and_open(page: &Page<'_>, ui: &mut Ui) {
let words = page.words;
let new = Button::new(words.new.clone()).id_salt("new").variant(Variant::Custom(HOME_NEW_LOOK)).sizing(Sizing::FillWidth);
if clicked(&new.show(ui)) {
page.push(StartAction::New);
}
let open = Button::new(words.open.clone()).id_salt("open").variant(Variant::Custom(HOME_OPEN_LOOK)).sizing(Sizing::FillWidth);
if clicked(&open.show(ui)) {
page.push(StartAction::Open);
}
}
/// The rows of a Home rail group: each link is a full-width row with its icon, a URL opening in the browser (the URL
/// is its tooltip) and a command firing as a pointer activation. A selected row has an accent bar at its leading edge.
fn home_link_items(ui: &mut Ui, cx: &mut BodyCx<'_>, links: &[StartLink]) {
for (at, link) in links.iter().enumerate() {
let look = if link.selected { HOME_ROW_SELECTED_LOOK } else { HOME_ROW_LOOK };
let mut button =
Button::new(link.label.clone()).id_salt(("start-link", at)).variant(Variant::Custom(look)).align(HAlign::Start).sizing(Sizing::FillWidth);
if let Some(icon) = &link.icon {
button = button.icon(icon.clone());
}
if let StartLinkTarget::Url(url) = &link.target {
button = button.tooltip(url.clone());
}
let shown = button.show(ui);
if link.selected {
home_selected_bar(ui, shown.response().rect);
}
if clicked(&shown) {
match &link.target {
StartLinkTarget::Url(url) => cx.open_url(url, false),
StartLinkTarget::Command(command) => {
let _ = commands::fire(ui.ctx(), command.clone(), FireSource::Pointer);
}
}
}
}
}
/// The accent bar at the leading edge of the selected Home row, as tall as its icon.
fn home_selected_bar(ui: &mut Ui, row: Rect) {
let env = Env::of(ui);
let style = StyleCx::of_env(ui.ctx(), &env);
// The accent mark's look: `accent.solid`, `stroke.thick` wide.
let look = style.rule(RuleKind::DropMark);
let scale = ui.ctx().pixels_per_point();
let bar = Rect::from_center_size(row.center(), vec2(row.width(), env.tokens.size.icon.md.min(row.height())));
let side = if env.direction.is_rtl() { RectSide::Right } else { RectSide::Left };
ui.painter().extend(Rule::edge(&look, bar, side, scale));
}
fn home_drop_look(tokens: &Tokens) -> VariantLook {
let mut look = Variant::SECONDARY.resolve(tokens).radius(RadiusStep::Control);
if let Some(edge) = &mut look.edge {
+34
View File
@@ -210,6 +210,40 @@ fn the_home_screen_places_navigation_to_the_left_of_recent_files() {
assert!(rect("GitHub").top() - rect("Discord").bottom() >= 6.0);
}
/// The Home rail's links are rows as wide as the rail, as New and Open are, not inline links; the selected row (Home)
/// shows a bar at its leading edge and the others none.
#[trial]
fn the_home_rail_shows_its_links_as_rows_with_a_bar_on_the_selected_one() {
use egui::{Shape, vec2};
let (mut fixture, _) = home_screen(true);
fixture.room(vec2(1100.0, 700.0)).settle();
let new = fixture.by_label("New…").expect("New").rect;
let rows: Vec<_> =
["Home", "Learn", "Website", "Discord", "GitHub"].into_iter().map(|label| (label, fixture.by_label(label).expect(label).rect)).collect();
for (label, row) in &rows {
assert!((row.width() - new.width()).abs() < 1.0, "{label} {row:?} is a row as wide as New {new:?}");
}
let rect = |label: &str| rows.iter().find(|(name, _)| *name == label).map(|(_, row)| *row).expect(label);
// Upright lines at the rail's leading edge: the selected row's bar.
let bars: Vec<_> = fixture
.frame_shapes()
.into_iter()
.filter_map(|shape| match shape {
Shape::LineSegment { points, .. } if (points[0].x - points[1].x).abs() < 0.5 && (points[0].x - new.left()).abs() <= 2.0 => Some(points),
_ => None,
})
.collect();
let on = |label| {
let row = rect(label);
bars.iter().any(|p| row.y_range().contains(p[0].y) && row.y_range().contains(p[1].y))
};
assert!(on("Home"), "the selected Home row has a bar at its leading edge: {bars:?}");
for label in ["Learn", "Website", "Discord", "GitHub"] {
assert!(!on(label), "{label} is not selected and has no bar: {bars:?}");
}
}
/// A desktop Recent tile gives its picture and filename room while keeping the whole card clickable.
#[trial]
fn desktop_home_recent_cards_give_the_picture_and_caption_room() {