mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 01:44:25 +00:00
Collection row height: CollectionProps::row_height picks control-high or text rows, one resolver for the item layouts, the min_rows fill and ListRow's least height, which each ListRow collection sets in dress
This commit is contained in:
@@ -12,7 +12,8 @@ pub use events::{
|
||||
CollectionEvent, ColumnEvent, ColumnRequest, ContextMenuRequest, HeaderMenuRequest, ListDrag, OpenChange, Rename, ReorderMove, ToggleEdit,
|
||||
};
|
||||
pub use props::{
|
||||
ActivateOn, CollectionProps, DragPayload, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowPressed, RowState, SelectMode, SpaceAction,
|
||||
ActivateOn, CollectionProps, DragPayload, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowHeight, RowPressed, RowState, SelectMode,
|
||||
SpaceAction,
|
||||
};
|
||||
pub(crate) use response::Gestures;
|
||||
pub(crate) use response::ItemsOut;
|
||||
|
||||
@@ -4,6 +4,7 @@ use super::columns::{ColumnSort, ColumnSpec};
|
||||
use super::events::ListDrag;
|
||||
use crate::contract::Notch;
|
||||
use crate::runtime::env::{Counted, Label};
|
||||
use crate::style::StyleCx;
|
||||
use craft_behavior::{Axis, ColumnKey};
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
@@ -117,6 +118,29 @@ pub enum LeadOnOpen {
|
||||
First,
|
||||
}
|
||||
|
||||
/// How tall a collection's rows are. Read-only display tables (a metadata table) take text rows; lists the user picks
|
||||
/// from or navigates keep control-high rows, a pointer target as tall as a control. A row with a thumbnail or a
|
||||
/// detail line is as tall as those need either way.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum RowHeight {
|
||||
/// A control high: `size.control` at the collection's control size.
|
||||
#[default]
|
||||
Control,
|
||||
/// One text line and a tight gap: `size.row.text`.
|
||||
Text,
|
||||
}
|
||||
|
||||
impl RowHeight {
|
||||
/// The height of one row under `cx`.
|
||||
pub fn of(self, cx: &StyleCx<'_>) -> f32 {
|
||||
match self {
|
||||
RowHeight::Control => cx.control().height,
|
||||
RowHeight::Text => cx.tokens.size.row.text,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What a collection reads from the app: plain data. A new builder's name is added to the forwarder list in
|
||||
/// `crates/ui-macros/src/props.rs`, so the components that embed these props forward it.
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -191,12 +215,14 @@ pub struct CollectionProps {
|
||||
/// the lead scrolls the page to keep the row in view. For short collections only; a long one keeps its own
|
||||
/// scroll and is shown outside a scrolling body (16.3).
|
||||
pub natural_height: bool,
|
||||
/// The least number of rows the collection is tall: rows it does not have count the control height, so an empty
|
||||
/// The least number of rows the collection is tall: rows it does not have count the row height, so an empty
|
||||
/// collection stays a target of its size.
|
||||
pub min_rows: u16,
|
||||
/// The most rows the collection shows: past them it is as tall as its first `max_rows` rows and scrolls them. It
|
||||
/// owns that scroll inside a scrolling body too, since its height is bounded and the wheel passes on at its ends.
|
||||
pub max_rows: Option<u16>,
|
||||
/// How tall the rows are.
|
||||
pub row_height: RowHeight,
|
||||
/// A Cmd/Ctrl click on an item, on its own area or a part that picks it, is a command on the item, not a pick: the
|
||||
/// selection stays and the release reports `CollectionEvent::CommandClick`.
|
||||
pub command_click: bool,
|
||||
@@ -287,6 +313,7 @@ impl CollectionProps {
|
||||
natural_height: false,
|
||||
min_rows: 0,
|
||||
max_rows: None,
|
||||
row_height: RowHeight::Control,
|
||||
command_click: false,
|
||||
notch: None,
|
||||
overflow: Axis::Y,
|
||||
@@ -507,6 +534,13 @@ impl CollectionProps {
|
||||
self
|
||||
}
|
||||
|
||||
/// The rows are `height` tall (see [`RowHeight`]).
|
||||
#[must_use]
|
||||
pub const fn row_height(mut self, height: RowHeight) -> Self {
|
||||
self.row_height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// A Cmd/Ctrl click on an item is a command, not a pick (see [`CollectionProps::command_click`]).
|
||||
#[must_use]
|
||||
pub const fn command_click(mut self, on: bool) -> Self {
|
||||
|
||||
@@ -228,7 +228,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
let content = layout.content_size();
|
||||
self.content = Vec2::new(content.x as f32, content.y as f32);
|
||||
let props = comp.items();
|
||||
let row = scx.control().height;
|
||||
let row = props.row_height.of(scx);
|
||||
let floor = rows_height(&layout, self.source.len(), props.min_rows, row);
|
||||
let cap = props.max_rows.map(|rows| rows_height(&layout, self.source.len(), rows, row).max(floor));
|
||||
self.columns = layout.column_count() as u32;
|
||||
@@ -904,8 +904,8 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The height of the first `rows` rows of `layout` over `len` items: the rows it lays out, and the control height `row`
|
||||
/// for each one it does not have.
|
||||
/// The height of the first `rows` rows of `layout` over `len` items: the rows it lays out, and the row height `row` for
|
||||
/// each one it does not have.
|
||||
fn rows_height(layout: &impl ItemLayout, len: usize, rows: u16, row: f32) -> f32 {
|
||||
let rows = usize::from(rows);
|
||||
let laid = rows.min(len);
|
||||
|
||||
@@ -51,7 +51,7 @@ pub use body::pad_of;
|
||||
pub use collection::{
|
||||
ActivateOn, CollectionEvent, CollectionProps, CollectionResponse, ColumnAlign, ColumnEvent, ColumnKind, ColumnRequest, ColumnSort, ColumnSpec,
|
||||
ContextMenuRequest, DragPayload, DropAt, DropKind, DropPayload, DropPlace, HeaderMenuRequest, ItemKeys, LeadOnOpen, LeadSource, ListDrag,
|
||||
OpenChange, PendingDrop, Rename, ReorderMove, ReorderRule, RowPressed, RowState, SelectMode, ShownRow, SpaceAction, ToggleColumn, ToggleEdit,
|
||||
OpenChange, PendingDrop, Rename, ReorderMove, ReorderRule, RowHeight, RowPressed, RowState, SelectMode, ShownRow, SpaceAction, ToggleColumn, ToggleEdit,
|
||||
};
|
||||
#[doc(hidden)]
|
||||
pub use container::InBar;
|
||||
|
||||
@@ -189,8 +189,13 @@ const COLLECTION: &[Forwarded] = &[
|
||||
("deletable", "bool", "Delete and Backspace at the lead report the items to delete."),
|
||||
("drag_count", "::craft_ui::runtime::env::Counted", "The drag badge reads this count word for the dragged items, one included."),
|
||||
("natural_height", "bool", "The collection takes its full content height and owns no scroll: for a short collection inside a scrolling page."),
|
||||
("min_rows", "u16", "The collection is at least this many rows tall; rows it does not have count the control height."),
|
||||
("min_rows", "u16", "The collection is at least this many rows tall; rows it does not have count the row height."),
|
||||
("max_rows", "u16", "The collection shows at most this many rows and scrolls the rest, inside a scrolling body too."),
|
||||
(
|
||||
"row_height",
|
||||
"::craft_ui::contract::RowHeight",
|
||||
"How tall the rows are: text rows for a read-only display table, control-high rows for a list the user picks from.",
|
||||
),
|
||||
("notch", "::craft_ui::contract::Notch", "The distance one wheel notch scrolls the rows."),
|
||||
("command_click", "bool", "A Cmd/Ctrl click on an item is a command (`CollectionEvent::CommandClick`), not a pick."),
|
||||
(
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
use super::view_words::EventWords;
|
||||
use super::{ListRow, RowEvent};
|
||||
use crate::contract::{
|
||||
Bind, BindMut, Collection, CollectionProps, CollectionResponse, Common, Component, ContainerProps, Cx, Props as _, Role, SelectMode, Sizing,
|
||||
Bind, BindMut, Collection, CollectionProps, CollectionResponse, Common, Component, ContainerProps, Cx, Props as _, Role, RowState, SelectMode,
|
||||
Sizing,
|
||||
};
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::env::{Label, WordSet as _};
|
||||
@@ -247,7 +248,11 @@ impl Collection for EventList<'_> {
|
||||
}
|
||||
|
||||
fn item_layout(&self, source: &dyn ItemSource<u64>, width: f32, cx: &StyleCx<'_>) -> SpanLayout {
|
||||
SpanLayout::sized(source, width, cx.control().height)
|
||||
SpanLayout::sized(source, width, self.items.row_height.of(cx))
|
||||
}
|
||||
|
||||
fn dress<'r>(&self, row: Self::Item<'r>, _: &RowState) -> Self::Item<'r> {
|
||||
row.rows(self.items.row_height)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::words::ListWords;
|
||||
use super::{ListRow, RowEvent};
|
||||
use crate::contract::{
|
||||
ActivateOn, Bind, BindMut, Collection, CollectionProps, CollectionResponse, Common, Component, ContainerProps, Cx, MeasureCx, PaintUi,
|
||||
Props as _, Role, SelectMode, Sizing, Styled as _, WordSetCx as _,
|
||||
Props as _, Role, RowState, SelectMode, Sizing, Styled as _, WordSetCx as _,
|
||||
};
|
||||
use crate::primitives::{IconSpec, TextRun, glyph};
|
||||
use crate::runtime::env::{Label, WordSet as _};
|
||||
@@ -208,7 +208,11 @@ impl Collection for FindingsList<'_> {
|
||||
}
|
||||
|
||||
fn item_layout(&self, source: &dyn ItemSource<u64>, width: f32, cx: &StyleCx<'_>) -> SpanLayout {
|
||||
SpanLayout::sized(source, width, cx.control().height)
|
||||
SpanLayout::sized(source, width, self.items.row_height.of(cx))
|
||||
}
|
||||
|
||||
fn dress<'r>(&self, row: Self::Item<'r>, _: &RowState) -> Self::Item<'r> {
|
||||
row.rows(self.items.row_height)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
use super::toggle::ToggleCell;
|
||||
use super::words::ListWords;
|
||||
use crate::contract::{Common, OpenChange, RowPressed, RowState, Show};
|
||||
use crate::contract::{Common, OpenChange, RowHeight, RowPressed, RowState, Show};
|
||||
use crate::primitives::{ContentPainterCx, HAlign, IconSpec};
|
||||
use crate::runtime::env::Label;
|
||||
use craft_behavior::ColumnKey;
|
||||
@@ -133,6 +133,9 @@ pub struct ListRow<'a> {
|
||||
#[style_key]
|
||||
#[prop]
|
||||
pub(super) role: Option<TypeRole>,
|
||||
/// How tall the row is: its collection sets it from `CollectionProps::row_height` in `Collection::dress`.
|
||||
#[style_key]
|
||||
pub(super) rows: RowHeight,
|
||||
/// The label in italics.
|
||||
#[prop]
|
||||
pub(super) italic: bool,
|
||||
@@ -257,6 +260,7 @@ impl<'a> ListRow<'a> {
|
||||
layer: false,
|
||||
striped: false,
|
||||
role: None,
|
||||
rows: RowHeight::Control,
|
||||
italic: false,
|
||||
highlight: false,
|
||||
clipped: false,
|
||||
@@ -329,6 +333,13 @@ impl<'a> ListRow<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// The row is `rows` tall: the height its collection's rows take.
|
||||
#[must_use]
|
||||
pub(crate) fn rows(mut self, rows: RowHeight) -> Self {
|
||||
self.rows = rows;
|
||||
self
|
||||
}
|
||||
|
||||
/// The row state the collection gives the item: the rename editor, the stripe, the app's mark and the press the
|
||||
/// collection holds on the row.
|
||||
#[must_use]
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::show::named;
|
||||
use super::style::ListRowStyle;
|
||||
use super::thumb::{Thumb, ThumbSize};
|
||||
use super::trailing::{TrailingItem, trailing_run};
|
||||
use crate::contract::{ColumnAlign, PartsCx, WordSetCx as _};
|
||||
use crate::contract::{ColumnAlign, PartsCx, RowHeight, WordSetCx as _};
|
||||
use crate::layout::{ShrinkOrder, ShrinkUnit, shrink_widths};
|
||||
use crate::list::toggle::ToggleState;
|
||||
use crate::list::words::ListWords;
|
||||
@@ -44,11 +44,11 @@ pub(super) struct Sizes {
|
||||
}
|
||||
|
||||
impl Sizes {
|
||||
pub(super) fn of(cx: &StyleCx<'_>, role: TypeRole) -> Sizes {
|
||||
pub(super) fn of(cx: &StyleCx<'_>, role: TypeRole, rows: RowHeight) -> Sizes {
|
||||
let (control, tokens) = (cx.control(), cx.tokens);
|
||||
let thumbs = &tokens.size.thumb;
|
||||
Sizes {
|
||||
row: control.height,
|
||||
row: rows.of(cx),
|
||||
icon: control.icon,
|
||||
pad: control.pad_x,
|
||||
gap: control.gap,
|
||||
@@ -76,8 +76,8 @@ impl Sizes {
|
||||
thumb.pick(self.thumbs)
|
||||
}
|
||||
|
||||
/// The height of a row with a thumbnail of `thumb` and, if `detail`, a detail line: the control height, the
|
||||
/// thumbnail with its padding (at least `thumb_row`), or the two lines of text, whichever is tallest.
|
||||
/// The height of a row with a thumbnail of `thumb` and, if `detail`, a detail line: the row height, the thumbnail
|
||||
/// with its padding (at least `thumb_row`), or the two lines of text, whichever is tallest.
|
||||
pub(super) fn height(&self, thumb: ThumbSize, detail: bool) -> f32 {
|
||||
let base = match self.side(thumb) {
|
||||
0.0 => self.row,
|
||||
@@ -95,10 +95,10 @@ pub(super) fn halign(align: ColumnAlign) -> HAlign {
|
||||
}
|
||||
|
||||
impl ListRow<'_> {
|
||||
/// The height of a row with a thumbnail of `thumb` and, if `detail`, a detail line, for the item layout of a
|
||||
/// list of such rows.
|
||||
/// The height of a control-high row with a thumbnail of `thumb` and, if `detail`, a detail line, for the item
|
||||
/// layout of a list of such rows.
|
||||
pub fn row_height(cx: &StyleCx<'_>, thumb: ThumbSize, detail: bool) -> f32 {
|
||||
Sizes::of(cx, TypeRole::Body).height(thumb, detail)
|
||||
Sizes::of(cx, TypeRole::Body, RowHeight::Control).height(thumb, detail)
|
||||
}
|
||||
|
||||
/// Where this row's disclosure lies when it fills `rect` under `style`, with texts `text_width` wide: the rect at
|
||||
|
||||
@@ -80,7 +80,7 @@ impl Component for ListRow<'_> {
|
||||
};
|
||||
let weight = key.strong || key.heading;
|
||||
let role = key.role.unwrap_or(if weight { TypeRole::BodyStrong } else { TypeRole::Body });
|
||||
let sizes = Sizes::of(cx, role);
|
||||
let sizes = Sizes::of(cx, role, key.rows);
|
||||
let muted = if key.ink == RowInk::Dimmed { text.faint } else { text.muted };
|
||||
ListRowStyle {
|
||||
surface,
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::view_words::UndoWords;
|
||||
use super::{ListRow, RowEvent};
|
||||
use crate::contract::{
|
||||
ActivateOn, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, Common, Component, ContainerProps, Cx, Props as _,
|
||||
Role, SelectMode, Sizing,
|
||||
Role, RowState, SelectMode, Sizing,
|
||||
};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
@@ -178,6 +178,10 @@ impl Collection for UndoList<'_> {
|
||||
}
|
||||
|
||||
fn item_layout(&self, source: &dyn ItemSource<usize>, width: f32, cx: &StyleCx<'_>) -> SpanLayout {
|
||||
SpanLayout::new(source, width, cx.control().height)
|
||||
SpanLayout::new(source, width, self.items.row_height.of(cx))
|
||||
}
|
||||
|
||||
fn dress<'r>(&self, row: Self::Item<'r>, _: &RowState) -> Self::Item<'r> {
|
||||
row.rows(self.items.row_height)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,11 +208,12 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for List<'_, K> {
|
||||
}
|
||||
|
||||
fn item_layout(&self, source: &dyn ItemSource<K>, width: f32, cx: &StyleCx<'_>) -> SpanLayout {
|
||||
let layout = SpanLayout::sized(source, width, cx.control().height);
|
||||
let layout = SpanLayout::sized(source, width, self.items.row_height.of(cx));
|
||||
if self.tree { layout.tree() } else { layout }
|
||||
}
|
||||
|
||||
fn dress<'r>(&self, row: Self::Item<'r>, _: &RowState) -> Self::Item<'r> {
|
||||
let row = row.rows(self.items.row_height);
|
||||
if self.row_menu { row.row_menu() } else { row }
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ use super::words::TableWords;
|
||||
use crate::contract::overlay::Anchor;
|
||||
use crate::contract::{
|
||||
Bind, BindMut, Collection, CollectionProps, CollectionResponse, ColumnCommands, ColumnRequest, ColumnSpec, Common, Component, ContainerProps, Cx,
|
||||
DropKind, EditResponse, ListDrag, OverlayUi, Overlays as _, Props as _, Role, SelectMode, Show as _, ShowContainer as _, Sizing, WordSetCx as _,
|
||||
DropKind, EditResponse, ListDrag, OverlayUi, Overlays as _, Props as _, Role, RowState, SelectMode, Show as _, ShowContainer as _, Sizing,
|
||||
WordSetCx as _,
|
||||
};
|
||||
use crate::display::Divider;
|
||||
use crate::list::{DropTest, ListRow, RowEvent, RowTest, RowText};
|
||||
@@ -192,12 +193,16 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for Table<'_, K> {
|
||||
self.reveal.as_ref()
|
||||
}
|
||||
|
||||
/// Column widths come from the specs and the header's memory; a row is a control high.
|
||||
/// Column widths come from the specs and the header's memory; a row is as tall as `CollectionProps::row_height`.
|
||||
fn item_layout(&self, source: &dyn ItemSource<K>, width: f32, cx: &StyleCx<'_>) -> SpanLayout {
|
||||
let layout = SpanLayout::sized(source, width, cx.control().height);
|
||||
let layout = SpanLayout::sized(source, width, self.items.row_height.of(cx));
|
||||
if self.tree { layout.tree() } else { layout }
|
||||
}
|
||||
|
||||
fn dress<'r>(&self, row: Self::Item<'r>, _: &RowState) -> Self::Item<'r> {
|
||||
row.rows(self.items.row_height)
|
||||
}
|
||||
|
||||
fn rename_draft(&self, key: &K) -> Option<String> {
|
||||
self.rename_draft.as_ref().and_then(|draft| draft.text(key))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user