Summary card: the description wraps onto its two reserved lines

This commit is contained in:
Dylan M. Taylor
2026-11-22 07:05:30 -05:00
parent 03c211ab6b
commit 35c78eaf3d
2 changed files with 31 additions and 2 deletions
+7 -2
View File
@@ -996,8 +996,13 @@ impl Component for Tile<'_> {
draw.galley(egui::pos2(title_x, title_area.top()), &title_layout);
if !centered {
if let Some(detail) = &self.detail {
let run = TextRun::new(detail.as_str()).role(style.detail.role).color(cx.resolve(&style.detail.color)).elide();
let layout = draw.layout(&run, picture.width());
// The description wraps, onto the two lines the card reserves for it, as production's cards do.
let run = TextRun::new(detail.as_str()).role(style.detail.role).color(cx.resolve(&style.detail.color)).wrap(Wrap::Wrap);
let mut layout = draw.layout(&run, picture.width());
// More than the two reserved lines would run into the action: cut that description with an ellipsis.
if layout.galley.rows.len() > 2 {
layout = draw.layout(&run.elide(), picture.width());
}
draw.galley(egui::pos2(self.text_x(picture, layout.size().x, cx), icon.bottom() + style.sizes.tight), &layout);
}
let run = TextRun::new(action.as_str()).role(style.detail.role).color(style.range).elide();
@@ -60,6 +60,30 @@ fn summary_card_paints_title_description_and_action() {
}
}
/// A summary card's description wraps onto a second line, as production's recommended-tool cards do, instead of being
/// cut with an ellipsis; the action stays below it.
#[trial]
fn a_summary_cards_long_description_wraps_instead_of_eliding() {
const DETAIL: &str = "Sticky note \u{b7} Highlight text \u{b7} Underline";
let mut frames = Frames::new();
let mut shapes = Vec::new();
for _ in 0..3 {
shapes = frames.frame_shapes(|ui| {
Tile::new("Add comments").icon(craft_behavior::IconId::new("grid")).detail(DETAIL).summary_action("Use now").card().show(ui);
});
}
let text = |wanted: &str| {
shapes.iter().find_map(|shape| match shape {
Shape::Text(text) if text.galley.job.text.starts_with(wanted) => Some((text.galley.rows.len(), text.visual_bounding_rect())),
_ => None,
})
};
let (lines, detail) = text("Sticky note").expect("the description is painted");
let (_, action) = text("Use now").expect("the action is painted");
assert!(lines >= 2, "the description wraps onto {lines} line(s) instead of being cut");
assert!(detail.max.y <= action.min.y + 0.5, "the description {detail:?} stays above the action {action:?}");
}
#[trial]
fn the_badge_bar_leaves_out_what_does_not_fit_and_never_overlaps() {
let (_, glyphs, dots) = badges(400.0);