mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 20:25:06 +00:00
Picker headings are ListRow's heading rows: one heading mechanism in ListRow
This commit is contained in:
@@ -178,7 +178,6 @@ pub struct ListRow<'a> {
|
||||
#[prop(into)]
|
||||
pub(super) accessible_name: Option<String>,
|
||||
pub(super) spacer: bool,
|
||||
pub(super) caption: bool,
|
||||
pub(super) cells: Vec<(ColumnKey, Rect)>,
|
||||
/// Each column's alignment and whether its figures are tabular, from `columns(..)`.
|
||||
pub(super) aligns: Vec<(ColumnKey, HAlign, bool)>,
|
||||
@@ -271,7 +270,6 @@ impl<'a> ListRow<'a> {
|
||||
progress: None,
|
||||
accessible_name: None,
|
||||
spacer: false,
|
||||
caption: false,
|
||||
cells: Vec::new(),
|
||||
aligns: Vec::new(),
|
||||
muted: Vec::new(),
|
||||
@@ -312,15 +310,6 @@ impl<'a> ListRow<'a> {
|
||||
row
|
||||
}
|
||||
|
||||
/// A caption over the rows after it (a group's name in a picker's list): `label` in the caption role and
|
||||
/// `text.muted` at the row's start, a row high. Like a spacer it senses nothing and takes no lead; its AccessKit
|
||||
/// node is a heading. Mark its position `ItemSource::is_section` so keys and clicks skip it.
|
||||
pub fn caption(label: impl Into<Label>) -> Self {
|
||||
let mut row = Self::new(label);
|
||||
row.caption = true;
|
||||
row
|
||||
}
|
||||
|
||||
/// The rects of the row's columns, which the item context lists (`ItemCx::cells`): toggle cells and text cells
|
||||
/// draw in theirs and the rest of the row lays out in what they leave.
|
||||
#[must_use]
|
||||
|
||||
@@ -24,7 +24,7 @@ const MIN_LABEL_HEIGHTS: f32 = 3.0;
|
||||
pub(super) struct Sizes {
|
||||
pub(super) row: f32,
|
||||
pub(super) icon: f32,
|
||||
pub(super) pad: f32,
|
||||
pad: f32,
|
||||
pub(super) gap: f32,
|
||||
trailing_pad: f32,
|
||||
pub(super) min_label: f32,
|
||||
|
||||
@@ -49,7 +49,7 @@ pub(super) fn named(pattern: &Label, row: &str) -> String {
|
||||
impl Component for ListRow<'_> {
|
||||
const ROLE: Role = Role::LIST_ITEM;
|
||||
const OVERLAYS: bool = false;
|
||||
const ALT_ROLES: &'static [Role] = &[Role::TREE_ITEM, Role::LIST_BOX_OPTION, Role::HEADING];
|
||||
const ALT_ROLES: &'static [Role] = &[Role::TREE_ITEM, Role::LIST_BOX_OPTION];
|
||||
type Style = ListRowStyle;
|
||||
type Output = RowOutput;
|
||||
|
||||
@@ -116,10 +116,6 @@ impl Component for ListRow<'_> {
|
||||
if self.spacer {
|
||||
return Vec2::ZERO;
|
||||
}
|
||||
if self.caption {
|
||||
let caption = cx.layout_at(&TextRun::new(cx.resolved.label).role(cx.style.detail.role), f32::INFINITY).size();
|
||||
return Vec2::new(caption.x + 2.0 * sizes.pad, sizes.row.max(caption.y));
|
||||
}
|
||||
let above = if self.space_above { sizes.gap_row } else { 0.0 };
|
||||
let height = sizes.height(self.thumb, self.detail_line());
|
||||
let rtl = cx.env.direction().is_rtl();
|
||||
@@ -166,12 +162,12 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
if self.spacer || self.caption { Sense::empty() } else { Sense::CLICK | Sense::FOCUS }
|
||||
if self.spacer { Sense::empty() } else { Sense::CLICK | Sense::FOCUS }
|
||||
}
|
||||
|
||||
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
self.record_toggle_names(cx);
|
||||
if self.spacer || self.caption {
|
||||
if self.spacer {
|
||||
return;
|
||||
}
|
||||
self.adopt_toggle_columns(&cx.env, cx.resolved.id);
|
||||
@@ -287,7 +283,7 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
if self.spacer || self.caption {
|
||||
if self.spacer {
|
||||
return;
|
||||
}
|
||||
if let Some(open) = self.group
|
||||
@@ -352,10 +348,6 @@ impl Component for ListRow<'_> {
|
||||
access.name(Name::Decorative);
|
||||
return;
|
||||
}
|
||||
if self.caption {
|
||||
access.role(Role::HEADING);
|
||||
return;
|
||||
}
|
||||
let words = cx.words::<ListWords>();
|
||||
let label = cx.resolved.label;
|
||||
let name = match (&self.accessible_name, &self.detail) {
|
||||
@@ -452,16 +444,6 @@ impl Component for ListRow<'_> {
|
||||
let sizes = &style.sizes;
|
||||
let rtl = cx.env.direction().is_rtl();
|
||||
let rect = cx.rect;
|
||||
if self.caption {
|
||||
let draw = ui.draw();
|
||||
let content = rect.shrink2(Vec2::new(sizes.pad, 0.0));
|
||||
let run = TextRun::new(cx.resolved.label).role(style.detail.role).color(cx.resolve(&style.detail.color)).elide();
|
||||
let layout = draw.layout(&run, content.width());
|
||||
let size = layout.size();
|
||||
let x = if rtl { content.max.x - size.x } else { content.min.x };
|
||||
draw.galley(Pos2::new(x, content.center().y - size.y / 2.0), &layout);
|
||||
return;
|
||||
}
|
||||
let widths = self.widths(sizes, &|run| ui.draw().layout(run, f32::INFINITY).size().x);
|
||||
let placed = self.place(sizes, &widths, rect, rtl);
|
||||
self.label_rect = placed.label;
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<'e, 'l, T> EntryRows<'e, 'l, T> {
|
||||
let entries: &'e [Entry<T>] = self.entries;
|
||||
let entry = &entries[at];
|
||||
let Some(value) = entry.value() else {
|
||||
return if entry.is_heading() { ListRow::caption(self.labels[at].clone()) } else { ListRow::spacer() };
|
||||
return if entry.is_heading() { ListRow::new(self.labels[at].clone()).heading() } else { ListRow::spacer() };
|
||||
};
|
||||
let row = ListRow::new(self.labels[at].clone()).option().check(chosen == Some(at)).enabled(entry.is_enabled());
|
||||
let row = match entry.icon_spec() {
|
||||
|
||||
@@ -35,7 +35,7 @@ impl<'a, V: NumberValue + 'static> NumberField<'a, V> {
|
||||
if rows[*at].is_separator() {
|
||||
ListRow::spacer()
|
||||
} else if rows[*at].is_heading() {
|
||||
ListRow::caption(labels[*at].clone())
|
||||
ListRow::new(labels[*at].clone()).heading()
|
||||
} else {
|
||||
ListRow::new(labels[*at].clone()).enabled(rows[*at].is_enabled()).option().check(marked == Some(*at))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user