ui-widgets list rows: ThumbRows, a root style value; under ThumbRows::Tight a thumbnail row pads its thumbnail by space.gap.tight with no floor of a standard control and the panel padding (at least the row's own height), and a tree level indents by a small icon and space.gap.tight. ThumbRows::Roomy, the default, keeps today's rows and indent, so no other app changes. ListRow story under Tight; trial

This commit is contained in:
bflatastic
2026-11-25 10:24:16 +07:00
parent 36522691ec
commit e70ddf25cf
6 changed files with 81 additions and 11 deletions
+2 -1
View File
@@ -22,7 +22,8 @@ pub use predicate::{DropTest, RowTest, RowText};
pub(crate) use row::RowThumb;
pub use row::{
CellStatus, CommandHighlight, HueTarget, LabelUnderline, ListRow, ListRowStyle, RowDragSpot, RowEvent, RowInk, RowLines, RowOutput, RowRun,
RowStyleCx, ThumbAspect, ThumbPaint, ThumbSize, ThumbTarget, ThumbTargets, TrailingFace, TrailingPart, TreeLeaves, label_color_label, tree_steps,
RowStyleCx, ThumbAspect, ThumbPaint, ThumbRows, ThumbSize, ThumbTarget, ThumbTargets, TrailingFace, TrailingPart, TreeLeaves, label_color_label,
tree_steps,
};
pub use toggle::{ToggleCell, ToggleFace, ToggleState};
pub use tree::OpenSet;
+1 -1
View File
@@ -41,7 +41,7 @@ pub use placement::indent_steps;
#[doc(hidden)]
pub use placement::placement_under_fixed_sizes;
pub use placement::{TreeLeaves, tree_steps};
pub use style::{CommandHighlight, ListRowStyle, RowStyleCx};
pub use style::{CommandHighlight, ListRowStyle, RowStyleCx, ThumbRows};
pub(crate) use thumb::RowThumb;
pub(super) use thumb::Thumb;
use thumb::ThumbPayload;
+17 -7
View File
@@ -2,7 +2,7 @@
use super::ListRow;
use super::show::named;
use super::style::ListRowStyle;
use super::style::{ListRowStyle, ThumbRows};
use super::thumb::{Thumb, ThumbSize};
use super::trailing::{TrailingFace, TrailingItem, trailing_run};
use crate::buttons::Link;
@@ -24,8 +24,10 @@ const MIN_LABEL_HEIGHTS: f32 = 3.0;
#[derive(Clone, Copy, Debug, PartialEq)]
pub(super) struct Sizes {
pub(super) row: f32,
/// The slot of an icon, a toggle cell's mark or a step of indent.
/// The slot of an icon or a toggle cell's mark.
pub(super) icon: f32,
/// A level of indent (`ThumbRows`).
indent: f32,
/// The side the row's icon and its toggle marks draw at in their slots: the control's icon side, the small
/// control's in a sub-row.
pub(super) mark: f32,
@@ -55,18 +57,21 @@ 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;
Sizes {
row: if sub_row { small.height } else { rows.of(cx) },
row,
icon: control.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,
trailing_pad: tokens.space.pad.regular,
min_label: MIN_LABEL_HEIGHTS * control.height,
thumbs: [thumbs.sm, thumbs.md, thumbs.lg],
thumb_pad: tokens.space.gap.stack,
thumb_pad: if tight { tokens.space.gap.tight } else { tokens.space.gap.stack },
// A standard control and the panel padding, as the old `thumb_row_min`.
thumb_row: tokens.size.control.md + tokens.space.pad.regular,
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,
@@ -333,7 +338,11 @@ impl ListRow<'_> {
/// The indent a row asks for before it gives way to the label's least width.
pub(super) fn indent_full(&self, sizes: &Sizes) -> f32 {
(self.steps() + usize::from(self.clipped)) as f32 * sizes.icon
// A leaf's extra step (`tree_steps`) passes its parent's disclosure column, an icon slot wide; the others are
// levels.
let steps = self.steps();
let past_disclosure = usize::from(steps > 0 && self.group.is_none());
(steps - past_disclosure + usize::from(self.clipped)) as f32 * sizes.indent + past_disclosure as f32 * sizes.icon
}
/// The column no text or toggle cell claims, which holds the label.
@@ -457,7 +466,7 @@ impl ListRow<'_> {
let cells_of = if self.sub_row {
let toggle = |key: &ColumnKey| self.toggle_columns.contains(key) || self.toggles.iter().any(|toggle| toggle.column == *key);
let mut cells = columns.to_vec();
craft_behavior::sub_row_cells(&mut cells, toggle, self.sub_steps as f32 * sizes.icon, rtl);
craft_behavior::sub_row_cells(&mut cells, toggle, self.sub_steps as f32 * sizes.indent, rtl);
moved = cells;
&moved[..]
} else {
@@ -618,6 +627,7 @@ pub fn placement_under_fixed_sizes(row: &ListRow<'_>, width: f32, rtl: bool) ->
let sizes = Sizes {
row: 20.0,
icon: 16.0,
indent: 16.0,
mark: 16.0,
pad: 6.0,
gap: 4.0,
+15
View File
@@ -87,6 +87,21 @@ pub enum CommandHighlight {
Hover,
}
/// How tall a row with a thumbnail stands, and how far a tree row indents per level. An app sets it at its root or on
/// the scope of a list (`with_env`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)]
#[env(style)]
#[non_exhaustive]
pub enum ThumbRows {
/// The thumbnail with `space.gap.stack` around it, at least a standard control and the panel padding high; a level
/// of indent is an icon slot.
#[default]
Roomy,
/// The thumbnail with `space.gap.tight` around it, at least the row's own height; a level of indent is a small
/// icon and `space.gap.tight`: VectorCraft's Layers panel.
Tight,
}
/// What the row fill depends on.
#[derive(Clone, Copy)]
pub(super) struct FillKey {
+22 -2
View File
@@ -1,10 +1,10 @@
//! Stories of the row types of the list family: `ListRow`.
use super::{CellStatus, HueTarget, LabelUnderline, ListRow, RowInk, RowRun, ThumbSize, TrailingFace, TrailingPart};
use super::{CellStatus, HueTarget, LabelUnderline, ListRow, RowInk, RowRun, ThumbRows, ThumbSize, TrailingFace, TrailingPart};
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::runtime::env::Env;
use crate::runtime::env::{Env, with_env};
use crate::style::{Corners, DataColor, SurfaceKind};
use crate::testing::{Drive, StoryData, StoryOutput, show_as_only_item, show_as_only_item_across, story};
use craft_behavior::{ColumnKey, IconId};
@@ -163,6 +163,26 @@ fn list_row_thumb_height(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
})
}
/// Thumbnail rows of a list under `ThumbRows::Tight` (VectorCraft's Layers panel): the thumbnail with a tight gap, no
/// taller than a control, and a nested row indented by a small icon and a tight gap.
#[story(ListRow<'static>, covers = [], drive = Drive::Never)]
fn list_row_tight_thumb_rows(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
with_env(
ui,
|overrides| {
overrides.values.set(ThumbRows::Tight);
},
|ui| {
show_rows(ui, || {
vec![
ListRow::new("Layer 1").depth(0).thumb(ThumbSize::Medium, thumb),
ListRow::new("Ellipse").depth(1).thumb(ThumbSize::Medium, thumb),
]
})
},
)
}
/// A colour from the document's data: a bookmark's or a tag's own colour.
const DATA_RED: DataColor = DataColor::new(egui::Color32::from_rgb(0xd0, 0x30, 0x30));
+24
View File
@@ -1900,3 +1900,27 @@ fn page_down_on_a_control_in_a_row_pages_the_capped_list() {
fixture.key(Key::PageDown, Modifiers::NONE).settle();
assert!(!in_view(&fixture, "Layer 0") && in_view(&fixture, "Layer 8"), "PageDown on the row's control paged the rows");
}
/// The height of a thumbnail row and how far a nested row's label starts after a top-level one's, under `rows`.
fn thumb_row_geometry(rows: craft_ui::list::ThumbRows) -> (f32, f32) {
use craft_ui::list::ThumbSize;
let mut fixture = Fixture::new(|ui| {
let keys = [0_usize, 1];
let source = keyed(&keys, |key: &usize| *key);
let _ = List::new("Layers").show_items(ui, &source, &mut |key, _| ListRow::new(NAMES[*key]).depth(*key).thumb(ThumbSize::Medium, |_, _| {}));
});
fixture.root_value(rows).room(Vec2::new(300.0, 200.0)).settle();
let label_x = |name: &str| fixture.texts().iter().find(|text| text.text == name).expect("the row paints its label").rect.left();
let height = fixture.by_label(NAMES[0]).expect("the top-level row").rect.height();
(height, label_x(NAMES[1]) - label_x(NAMES[0]))
}
/// A list under `ThumbRows::Tight` (VectorCraft's Layers panel) stands its thumbnail rows lower, the thumbnail with a
/// tight gap and no control-and-padding floor, and indents a level by less than an icon slot.
#[trial]
fn tight_thumbnail_rows_stand_lower_and_indent_less() {
use craft_ui::list::ThumbRows;
let ((roomy_height, roomy_indent), (tight_height, tight_indent)) = (thumb_row_geometry(ThumbRows::Roomy), thumb_row_geometry(ThumbRows::Tight));
assert!(tight_height < roomy_height, "the tight row ({tight_height}) is lower than the roomy one ({roomy_height})");
assert!(0.0 < tight_indent && tight_indent < roomy_indent, "a level indents less ({tight_indent}) than an icon slot ({roomy_indent})");
}