ui-widgets: the multi-row ListRow stories show their rows as one set in a Stack

Shown bare, a nested row had no position in its set and rows that hug their text stayed at the left edge in
right-to-left.
This commit is contained in:
bflatastic
2026-11-22 08:03:01 +07:00
parent 1f7df2dd4d
commit 14d4948c2d
+23 -22
View File
@@ -1,7 +1,8 @@
//! Stories of the row types of the list family: `ListRow`.
use super::{LabelUnderline, ListRow, RowInk, RowRun, ThumbSize, TrailingFace, TrailingPart};
use crate::contract::Show as _;
use crate::contract::{SetPosition, Show as _, ShowContainer as _, show_item_in_flow};
use crate::layout_components::Stack;
use crate::primitives::{ContentPainterCx, IconSpec, Span, StrokeWidth};
use crate::style::{Corners, DataColor, SurfaceKind};
use crate::testing::{Drive, StoryData, StoryOutput, show_as_only_item, story};
@@ -83,12 +84,16 @@ fn list_row_clamped_description_with_rail(ui: &mut Ui, _: &mut StoryData) -> Sto
show_as_only_item(ui, row).into()
}
/// Shows `rows` one under the other and reports the last one's output.
fn show_rows(ui: &mut Ui, rows: Vec<ListRow<'static>>) -> StoryOutput {
/// Shows the rows `rows` builds one under the other, as the items of one set, and reports the last one's output.
fn show_rows(ui: &mut Ui, rows: impl Fn() -> Vec<ListRow<'static>>) -> StoryOutput {
let mut shown = StoryOutput::default();
for row in rows {
shown = row.show(ui).into();
}
Stack::new().show(ui, |ui, _| {
let rows = rows();
let count = rows.len();
for (at, row) in rows.into_iter().enumerate() {
shown = show_item_in_flow(ui, row, SetPosition::new(at).of(count)).into();
}
});
shown
}
@@ -100,44 +105,41 @@ const STRIPE: DataColor = DataColor::new(Color32::from_rgb(0x2e, 0x7d, 0xd1));
#[story(ListRow<'static>, covers = [], drive = Drive::Never)]
fn list_row_label_emphasis(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
show_rows(
ui,
show_rows(ui, || {
vec![
ListRow::new("Italic").italic(true),
ListRow::new("Solid underline").underline(LabelUnderline::Solid),
ListRow::new("Dashed underline").underline(LabelUnderline::Dashed),
ListRow::new("Italic and dashed").italic(true).underline(LabelUnderline::Dashed),
ListRow::new("A dashed label far longer than the room its row gives it").underline(LabelUnderline::Dashed),
],
)
]
})
}
/// The stripe in the two widths, the current row's corner mark, a stripe on a nested row. The suite shows it in
/// right-to-left too.
#[story(ListRow<'static>, covers = [], drive = Drive::Never)]
fn list_row_stripe_and_corner_mark(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
show_rows(
ui,
show_rows(ui, || {
vec![
ListRow::new("Thick").stripe(STRIPE, StrokeWidth::Thick),
ListRow::new("Heavy").stripe(STRIPE, StrokeWidth::Heavy),
ListRow::new("Heavy with corner mark").stripe(STRIPE, StrokeWidth::Heavy).corner_mark(true),
ListRow::new("Nested").depth(1).stripe(STRIPE, StrokeWidth::Heavy),
],
)
]
})
}
#[story(ListRow<'static>, covers = [], drive = Drive::Never)]
fn list_row_runs(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
show_rows(
ui,
show_rows(ui, || {
vec![
ListRow::new("Alone").run(RowRun::Alone),
ListRow::new("First").run(RowRun::First),
ListRow::new("Middle").run(RowRun::Middle),
ListRow::new("Last").run(RowRun::Last),
],
)
]
})
}
#[story(ListRow<'static>, covers = [], drive = Drive::Never)]
@@ -150,12 +152,11 @@ fn list_row_thumbnails_only(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
#[story(ListRow<'static>, covers = [], drive = Drive::Never)]
fn list_row_thumb_height(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let icon = || IconSpec::svg(IconId::new("eye"));
show_rows(
ui,
show_rows(ui, || {
vec![
ListRow::new("Small").thumb_height(ThumbSize::Small).icon(icon()),
ListRow::new("Medium").thumb_height(ThumbSize::Medium).icon(icon()),
ListRow::new("Large").thumb_height(ThumbSize::Large).icon(icon()),
],
)
]
})
}