Collection members run their parts, update and finish: a member's parts are sensed with it, its output gives the item event, its parts' nodes sit under its node; TabStrip's tabs are members

This commit is contained in:
aiongg
2026-11-12 14:32:41 +00:00
parent dae805591c
commit 73fc9dc801
10 changed files with 295 additions and 84 deletions
@@ -1,14 +1,12 @@
//! Items that are members of the collection's run (`Collection::MEMBERS`): sensed in the collection's arena,
//! painted as faces, reported as sub-nodes of the collection.
//! Items that are members of the collection's run (`Collection::MEMBERS`): sensed with their parts in the collection's
//! arena, updated, painted and finished at their rows, reported as sub-nodes of the collection.
use super::{ITEM_NODE, ItemsHooks, key_hash};
use crate::contract::collection::ShownRow;
use crate::contract::run::{self, FaceSource};
use crate::contract::tooltip::MemberTip;
use crate::contract::{Collection, Component as _, Cx, Internal, ItemOpener, Meta as _};
use crate::primitives::PartResult;
use crate::contract::collection::{CollectionEvent, OpenChange, ShownRow};
use crate::contract::run;
use crate::contract::{Collection, Component as _, Cx, Internal, ItemOpener, ItemOutput as _, Meta as _};
use crate::primitives::sensing::{self, MemberSpec};
use crate::runtime::access::{self, Name, SetPosition, SubDecl, SubNode};
use crate::runtime::access::{self, SetPosition};
use crate::runtime::env::{ArenaId, Env};
use crate::style::Flags;
use craft_behavior::Sense;
@@ -32,83 +30,67 @@ pub(super) struct Member<K, I> {
}
impl<'r, C: Collection> ItemsHooks<'_, 'r, C> {
/// Joins the members to the collection's arena in one read, then paints each as the face of its item part,
/// reports its sub-node, and leaves the hovered member's tooltip for step 16.
/// Runs each member's parts step, joins the members to the collection's arena in one read, then runs each member's
/// update, paint, report and finish at its row; leaves the hovered member's tooltip for step 16 and reports its
/// output as the collection's item events.
pub(super) fn show_members(
&mut self,
comp: &mut C,
ui: &mut Ui,
cx: &mut Cx<'_, C>,
((ctx, id, rtl), env): ((&Context, Id, bool), &Env),
mut members: Vec<Member<C::Key, C::Item<'r>>>,
members: Vec<Member<C::Key, C::Item<'r>>>,
shown_rows: &mut [ShownRow<C::Key>],
) {
let enabled = cx.core.resolved.enabled;
let parent = access::fold::owner_of(ctx, id).unwrap_or(id);
let facts: Vec<(bool, Sense, Option<crate::contract::Tooltip>)> = members
.iter_mut()
let hover = sensing::read_outcome(ctx, ArenaId::new(id)).hover.map(|hit| hit.owner);
let mut prepared: Vec<(Member<C::Key, ()>, Id, bool, Sense, run::MemberPrep<C::Item<'r>>)> = members
.into_iter()
.map(|member| {
let common = member.item.common_mut(Internal::new());
let on = enabled && common.enabled.unwrap_or(true);
let tip = common.tooltip.take();
(on, member.item.sense(), tip)
let Member { at, key, mut item, row, clip, flags, position, renaming, openers, shown } = member;
let member_id = item_id(id, &key);
let on = enabled && item.common_mut(Internal::new()).enabled.unwrap_or(true);
let item_sense = item.sense();
let prep = run::member_prepare(ui, env, member_id, row, hover == Some(member_id), item);
let member = Member { at, key, item: (), row, clip, flags, position, renaming, openers, shown };
(member, member_id, on, item_sense, prep)
})
.collect();
let specs: Vec<MemberSpec<'_>> = members
let specs: Vec<MemberSpec<'_>> = prepared
.iter()
.zip(&facts)
// A member senses the pointer over it, never the press: the collection's root takes the click and the
// focus (17.2), as for an item that runs.
.map(|(member, (on, _, _))| MemberSpec { id: item_id(id, &member.key), rect: member.row, sense: Sense::HOVER, parts: &[], enabled: *on })
.map(|(member, member_id, on, _, prep)| MemberSpec {
id: *member_id,
rect: member.row,
sense: prep.sense,
parts: prep.decls.parts(),
enabled: *on,
})
.collect();
let sensed = sensing::sense_members(ui, ArenaId::new(id), &specs);
drop(specs);
let clip = ui.clip_rect();
for ((member, (on, sense, tip)), sensed) in members.into_iter().zip(facts).zip(sensed) {
let Member { at, key, item, row, clip: row_clip, flags, position, renaming, openers, shown } = member;
let part = ITEM_NODE.at(key_hash(&key));
let hovered = sensed.response.hovered();
let result = PartResult { rect: row, press: sensed.press, hovered, hover_pos: None, flags, inactive: false };
let source = FaceSource {
id,
result: &result,
focus: None,
response: &sensed.response,
ink: None,
muted: None,
flags: Flags::empty(),
enabled: on,
};
for ((member, member_id, on, item_sense, prep), sensed) in prepared.drain(..).zip(sensed) {
let Member { at, key, row, clip: row_clip, flags, position, renaming, openers, shown, .. } = member;
let node = run::MemberNode { owner: id, part: ITEM_NODE.at(key_hash(&key)), parent, position, flags, enabled: on, item_sense };
ui.set_clip_rect(row_clip);
let (record, facts) = run::paint_face(ui, env, &source, part, item);
let run::MemberShown { output, tip } = run::member_show(ui, env, (member_id, row), prep, sensed, &node);
ui.set_clip_rect(clip);
let mut node = SubNode::new(part, facts.role.unwrap_or(record.role));
node.name = Name::Text(record.name);
node.value = facts.value;
node.color = facts.color;
node.position = Some(position);
node.flags = flags;
let decl = SubDecl {
owner: id,
component: "",
node: &node,
rect: row,
enabled: on,
focusable: on && sense.contains(Sense::FOCUS),
clickable: on && sense.contains(Sense::CLICK),
active: false,
face: None,
label: "",
parent,
};
access::report_sub(ctx, &decl);
if hovered && let Some(tip) = tip {
cx.core.member_tip = Some(MemberTip { part, spec: tip.spec().clone(), rect: row, pressed: sensed.press.phase.is_press() });
if tip.is_some() {
cx.core.member_tip = tip;
}
if let Some(shown) = shown_rows.get_mut(shown) {
shown.openers = self.item_openers(ui, ctx, id, enabled, openers);
}
let label = output.label_rect().unwrap_or(row);
if let Some(ask) = output.open_request() {
self.events.push(CollectionEvent::Open(OpenChange { key: key.clone(), open: ask.open, all: ask.all }));
}
if let Some(event) = output.into_event() {
self.events.push(CollectionEvent::Item(key.clone(), event));
}
if renaming {
self.rename_row(comp, ui, (ctx, id, rtl), (at, &key), row);
self.rename_row(comp, ui, (ctx, id, rtl), (at, &key), label);
}
}
}
+6 -5
View File
@@ -474,11 +474,12 @@ pub trait Collection: Component + HasProps + Meta<Shape = shape::Items> {
type ItemEvent: 'static;
/// Whether the items are members of the collection's run instead of runs of their own. Each visible item is then
/// sensed as a member of the collection's arena, painted as a face at its row with the row's flags, and reported as
/// an access sub-node of the collection with the facts the face's `access` declares; its `tooltip` shows as the
/// collection's while the pointer rests on it. Of the item's hooks only those a face uses run (style, measure,
/// sense, flags, paint, access), so a member reports no output: no item event, open request or label rect. A
/// member declares no parts of its own and takes no rich tooltip.
/// sensed with its parts as a member of the collection's arena, painted at its row with the row's flags, and
/// reported as an access sub-node of the collection, its parts' nodes under it; its `tooltip`, or its hovered part's,
/// shows as the collection's while the pointer rests on it. The item's `style`, `measure`, `sense`, `flags`,
/// `parts`, `update`, `paint`, `paint_over`, `access` and `finish` run, so its output gives the item event, open
/// request and label rect as a run's does. A member has no stop and no focusable part, shows no popup, edits no
/// value and takes no rich tooltip.
const MEMBERS: bool = false;
/// Plain data: selection mode, reorder, rename, columns.
+1 -1
View File
@@ -165,7 +165,7 @@ impl PaintUi<'_> {
let focus = self.active.filter(|(active, _)| *active == part).map(|(_, visible)| visible);
let source =
FaceSource { id: self.id, result, focus, response: self.response, ink, muted: self.muted, flags: self.flags, enabled: self.enabled };
let (record, _) = run::paint_face(self.ui, self.env, &source, part, face);
let record = run::paint_face(self.ui, self.env, &source, part, face);
let mut own = self.record.borrow_mut();
if let Some(baseline) = record.baseline {
own.baseline.get_or_insert(baseline);
+4 -1
View File
@@ -28,7 +28,10 @@ use std::sync::Arc;
mod typed;
pub(crate) use typed::{measure_container, measure_under, measured_extent, paint_face, show_container, show_container_taking, show_items, show_leaf};
pub(crate) use typed::{
MemberNode, MemberPrep, MemberShown, measure_container, measure_under, measured_extent, member_prepare, member_show, paint_face, show_container,
show_container_taking, show_items, show_leaf,
};
/// Where a component is placed.
#[derive(Clone, Copy)]
+196 -4
View File
@@ -572,7 +572,7 @@ pub(crate) fn measured_extent<C: Component>(
/// A face run is steps 1, 2, 4 (read only), 12 and 13 of the face component, inside the composite's step 13, under
/// the composite's `env`. It registers no id, senses nothing, opens no memory stage and fires nothing. Returns the
/// record step 16 fills the part's sub-node from, and the facts the face's `access` declared.
pub(crate) fn paint_face<C: Show>(ui: &mut Ui, env: &Env, source: &super::FaceSource<'_>, part: PartRef, mut face: C) -> (FaceRecord, Access) {
pub(crate) fn paint_face<C: Show>(ui: &mut Ui, env: &Env, source: &super::FaceSource<'_>, part: PartRef, mut face: C) -> FaceRecord {
let ctx = ui.ctx().clone();
let common = std::mem::take(face.common_mut(Internal::new()));
debug_assert!(common.tooltip.is_none(), "a face instance carries no tooltip; use `PartBuilder::tooltip`");
@@ -643,7 +643,199 @@ pub(crate) fn paint_face<C: Show>(ui: &mut Ui, env: &Env, source: &super::FaceSo
// The face's own `access` adds its facts; the composite's step 16 fills the part's sub-node from the record.
let mut access = Access::default();
face.access(&mut access, &cx);
let record =
FaceRecord { part, name, flags, role: C::ROLE, numeric: access.numeric.clone(), expanded: access.expanded, enabled: step1.enabled, baseline };
(record, access)
FaceRecord { part, name, flags, role: C::ROLE, numeric: access.numeric, expanded: access.expanded, enabled: step1.enabled, baseline }
}
/// A member of a collection's run (`Collection::MEMBERS`) after steps 1, 2, 4 (read only) and 7: what the batch join
/// reads and what [`member_show`] runs on.
pub(crate) struct MemberPrep<C: Component> {
item: C,
common: Common,
step1: steps::EnvStep,
style: Arc<C::Style>,
shown: Option<Arc<ValueOf<C>>>,
mixed: bool,
pub decls: crate::contract::cx::Decls,
/// What the member senses of its own: the item's sense less the press and the focus, which the collection's root
/// takes (17.2), as for an item that runs.
pub sense: Sense,
pub tooltip: Option<crate::contract::Tooltip>,
}
/// Steps 1, 2, 4 (read only) and 7 of the member `id` at `row`; `hovered` is the arena's hover of the member this pass,
/// which `PartsCx::hovered` reads.
pub(crate) fn member_prepare<C: Show>(ui: &Ui, env: &Env, id: Id, row: Rect, hovered: bool, mut item: C) -> MemberPrep<C> {
let ctx = ui.ctx();
let mut common = std::mem::take(item.common_mut(Internal::new()));
let tooltip = common.tooltip.take();
let step1 = steps::env(ctx, env, &common, steps::variants::<C>(common.variant));
let style = steps::style::<C>(ctx, &steps::style_cx(ctx, env, &step1), item.style_key());
let (shown, mixed) = steps::peek_value(&mut item, ctx, id, step1.command.as_deref());
if let Some(key) = item.bind().and_then(|bind| bind.key(id)) {
reads::note(ctx, key, id, crate::runtime::measure::active(ctx), &[]);
}
let mut parts = PartsStep { decls: Default::default(), rovings: Vec::new(), scrolls: Vec::new(), text: Default::default() };
if C::PARTS {
let resolved = steps::resolved(id, &step1, &common);
let flow = Flow::new(row, env.direction.is_rtl());
let content_rect = flow.inset(StyleView::metrics(&*style).padding);
let input = MeasureIn { ui, env, proposal: Proposal::Ideal, room: None };
let mut pcx = PartsCx {
content_rect,
flow,
decls: &mut parts.decls,
rovings: &mut parts.rovings,
scrolls: &mut parts.scrolls,
text: &mut parts.text,
last_state: (hovered, false),
measure: steps::measure_cx::<C>(&input, &style, &resolved, shown.as_deref()),
items: None,
};
item.parts(row, &mut pcx);
}
debug_assert!(
parts.rovings.is_empty() && parts.scrolls.is_empty() && parts.text.decl.is_none() && parts.decls.iter().all(|(_, extras)| !extras.focusable),
"a member of a collection's run declares no stop, roving group, scroll part or text part"
);
let sense = item.sense().difference(Sense::CLICK | Sense::FOCUS) | Sense::HOVER;
MemberPrep { item, common, step1, style, shown, mixed, decls: parts.decls, sense, tooltip }
}
/// Where a member's sub-node goes: the collection's node `owner`, the item part it reports as, and its row facts.
pub(crate) struct MemberNode {
pub owner: Id,
pub part: PartRef,
pub parent: Id,
pub position: SetPosition,
/// The row's flags: selected, lead, expanded, current, dragging, drop target.
pub flags: Flags,
pub enabled: bool,
/// The member's sense as an item: whether its sub-node takes AccessKit focus and clicks, which the collection serves.
pub item_sense: Sense,
}
/// What a member's show leaves for the collection: its output, and its tooltip while the pointer rests on it.
pub(crate) struct MemberShown<O> {
pub output: O,
pub tip: Option<crate::contract::tooltip::MemberTip>,
}
/// Steps 9 (update), 12, 13, 16 and the finish of a member that joined the arena as `sensed`: the item's `update`
/// reads its parts and its press, its `paint` and `paint_over` draw at its row, its node and its parts' nodes are
/// reported under the collection's node, and `finish` makes its output.
pub(crate) fn member_show<C: Show>(
ui: &mut Ui,
env: &Env,
(id, row): (Id, Rect),
prep: MemberPrep<C>,
sensed: crate::primitives::sensing::MemberResult,
node: &MemberNode,
) -> MemberShown<C::Output> {
let ctx = ui.ctx().clone();
let MemberPrep { mut item, common, step1, style, shown, mixed, decls, sense: _, tooltip } = prep;
let rtl = env.direction.is_rtl();
let resolved = steps::resolved(id, &step1, &common);
let enabled = node.enabled && step1.enabled;
let hovered = sensed.response.hovered();
let result = crate::primitives::PartResult { rect: row, press: sensed.press, hovered, hover_pos: None, flags: node.flags, inactive: false };
let part_state = steps::part_state(&result, enabled, None);
let mut flags = part_state.flags | item.flags();
if (shown.as_deref().map(|value| value as &dyn std::any::Any)).and_then(|value| value.downcast_ref::<bool>()) == Some(&true) {
flags |= Flags::CHECKED;
}
if mixed {
flags |= Flags::MIXED;
}
let on = f32::from(u8::from(flags.intersects(Flags::ON)));
let state = StateSet::new(part_state.state, flags, crate::style::StateMix::new(part_state.t.hover, part_state.t.press, on));
// A peek that opens no lifetime stage and is dropped without a write-back, as a face's.
let mut stage = MemoryStage::open_peek(&ctx, id);
stage.face = true;
let mut core = blank_core(env.view(), &resolved, &mut stage, ctx.clone(), env.ink, sensed.response, step1.command.clone());
let flow = Flow::new(row, rtl);
core.rect = row;
core.content_rect = flow.inset(StyleView::metrics(&*style).padding);
core.flow = flow;
core.state = state;
core.stated = true;
core.ink = steps::surface_ink(StyleView::surface(&*style), &state, env.ink);
core.visible = row.intersect(ui.clip_rect());
core.part_cursors = crate::primitives::sensing::hovered_cursor(decls.parts(), &sensed.parts).into_iter().collect();
core.results = sensed.parts;
core.press = sensed.press;
core.member_of = Some(node.owner);
core.intents = crate::runtime::keys::intents_of(&ctx, Some(id), rtl);
let mut cx = Cx::<C> { core, style: &style, shown, mixed, events: Vec::new(), applied: 0, validity: Validity::Ok };
item.update(&mut cx);
steps::paint_surface(ui, env, &cx.core, &*style);
steps::paint_part_layers(ui, env, &cx.core);
item.paint(&mut super::paint_ui(ui, env, &cx.core, &*style), &cx);
item.paint_over(&mut super::paint_ui(ui, env, &cx.core, &*style), &cx);
let mut access = Access::default();
item.access(&mut access, &cx);
let member_node = report_member(&cx.core, &access, node, C::ROLE);
{
let paint = cx.core.paint.borrow();
steps::report_parts(&cx.core, &decls, &access.nodes, &paint.faces, member_node);
}
crate::contract::cx::write_cursor(&cx.core);
let tip = member_tip(&cx.core, &decls, node.part, tooltip, row);
MemberShown { output: item.finish(cx), tip }
}
/// The member's own sub-node of the collection's node: the facts the item's `access` declared, its row's place and
/// flags. Returns the node's id, which its parts' nodes attach to.
fn report_member(core: &CxCore<'_>, access: &Access, node: &MemberNode, role: crate::contract::Role) -> Id {
use crate::runtime::access::{Name, SubDecl, SubNode};
let name = match &access.name {
Name::FromLabel => Name::Text(core.paint.borrow().elided.clone().unwrap_or_else(|| core.resolved.label.to_owned())),
name => name.clone(),
};
let mut sub = SubNode::new(node.part, access.role.unwrap_or(role));
sub.name = name;
sub.description = access.description.clone();
sub.value = access.value.clone();
sub.color = access.color;
sub.numeric = access.numeric.clone();
sub.expanded = access.expanded;
sub.position = Some(node.position);
sub.flags = node.flags;
let decl = SubDecl {
owner: node.owner,
component: "",
node: &sub,
rect: core.rect,
enabled: node.enabled,
focusable: node.enabled && node.item_sense.contains(Sense::FOCUS),
clickable: node.enabled && node.item_sense.contains(Sense::CLICK),
active: false,
face: None,
label: "",
parent: node.parent,
};
crate::runtime::access::report_sub(&core.ctx, &decl);
crate::runtime::access::sub_node_id(node.owner, node.part)
}
/// The tooltip of a hovered member: its hovered part's, else its own. A part's subject is keyed by the member, so two
/// members' same part are two subjects.
fn member_tip(
core: &CxCore<'_>,
decls: &crate::contract::cx::Decls,
member: PartRef,
own: Option<crate::contract::Tooltip>,
row: Rect,
) -> Option<crate::contract::tooltip::MemberTip> {
if !core.response.hovered() {
return None;
}
let pressed = core.press.phase.is_press();
let hash = member.index.unwrap_or(0);
let part = decls.iter().find_map(|(decl, extras)| {
let result = core.results.get(&(decl.key, decl.index)).filter(|result| result.hovered)?;
let tip = extras.tooltip.as_ref()?;
let index = decl.index.map_or(hash, |index| hash ^ index.rotate_left(32));
Some(crate::contract::tooltip::MemberTip { part: decl.key.at(index), spec: tip.spec().clone(), rect: result.rect, pressed })
});
part.or_else(|| own.map(|tip| crate::contract::tooltip::MemberTip { part: member, spec: tip.spec().clone(), rect: row, pressed }))
}
+2 -2
View File
@@ -24,7 +24,7 @@ mod update;
mod value;
pub(crate) use apply::{ValueEdit, apply_values, rerun_after_edit};
pub(crate) use env::{env, resolved, variants};
pub(crate) use env::{EnvStep, env, resolved, variants};
pub(crate) use finish::{before_finish, inert_response, record_size, value_changed};
pub(super) use id::measuring;
pub(crate) use id::{draft, id, keeping_ids};
@@ -33,7 +33,7 @@ pub(crate) use measure::{MeasureIn, guard, measure, measure_content, measure_cx}
pub(crate) use paint::{paint_focus, paint_part_layers, paint_surface, surface_ink};
pub(crate) use parts::{PartsStep, check_parts, declares_none};
pub(crate) use place::place;
pub(crate) use report::{ReportIn, report, report_inert, validity_of};
pub(crate) use report::{ReportIn, report, report_inert, report_parts, validity_of};
#[cfg(feature = "testing")]
pub(crate) use scroll_owner::queue_reveal;
pub(crate) use scroll_owner::{child_reveal, peek_reveal, peek_scroll_moves, queue_child_reveal, take_reveal, take_scroll_moves};
@@ -172,7 +172,6 @@ fn report_access(p: &dyn ErasedPass<'_>, facts: &TypeFacts, input: &ReportIn<'_>
if core.member_of.is_some() && flags.contains(Flags::FOCUSED) {
access::set_focus(ctx, id);
}
let mut seen = Vec::new();
let facts = core.env.facts_of(id);
for node in &mut access.nodes {
// A cell of an item row knows its row; its column is the position of its column key among the columns the
@@ -192,19 +191,27 @@ fn report_access(p: &dyn ErasedPass<'_>, facts: &TypeFacts, input: &ReportIn<'_>
..node.grid
};
}
for node in &access.nodes {
let parent = access::fold::owner_of(ctx, id).unwrap_or(id);
report_parts(core, input.decls, &access.nodes, &paint.faces, parent);
}
/// The sub-nodes of a component's parts: the nodes its `access` declared, each with the face painted for it, then a
/// node for every other face. `parent` is the node a part attaches to unless it names one (`SubNode::under`).
pub(crate) fn report_parts(core: &CxCore<'_>, decls: &Decls, nodes: &[SubNode], faces: &[FaceRecord], parent: Id) {
let mut seen = Vec::with_capacity(nodes.len());
for node in nodes {
seen.push(node.part);
report_sub(core, input, node, paint.faces.iter().find(|face| face.part == node.part));
report_sub(core, decls, node, faces.iter().find(|face| face.part == node.part), parent);
}
for face in paint.faces.iter().filter(|face| !seen.contains(&face.part)) {
report_sub(core, input, &SubNode::new(face.part, face.role), Some(face));
for face in faces.iter().filter(|face| !seen.contains(&face.part)) {
report_sub(core, decls, &SubNode::new(face.part, face.role), Some(face), parent);
}
}
fn report_sub(core: &CxCore<'_>, input: &ReportIn<'_>, node: &SubNode, face: Option<&FaceRecord>) {
fn report_sub(core: &CxCore<'_>, decls: &Decls, node: &SubNode, face: Option<&FaceRecord>, parent: Id) {
let key = (node.part.key, node.part.index);
let result = core.results.get(&key);
let declared = input.decls.iter().find(|(decl, _)| (decl.key, decl.index) == key);
let declared = decls.iter().find(|(decl, _)| (decl.key, decl.index) == key);
let mut node = node.clone();
node.flags |= result.map_or(Flags::empty(), |result| result.flags);
let decl = SubDecl {
@@ -218,7 +225,7 @@ fn report_sub(core: &CxCore<'_>, input: &ReportIn<'_>, node: &SubNode, face: Opt
active: core.active == Some(node.part),
face: face.map(|face| FaceFacts { name: &face.name, flags: face.flags, numeric: face.numeric.as_ref(), expanded: face.expanded }),
label: core.resolved.label,
parent: node.under.map_or_else(|| access::fold::owner_of(&core.ctx, core.id).unwrap_or(core.id), |under| access::sub_node_id(core.id, under)),
parent: node.under.map_or(parent, |under| access::sub_node_id(core.id, under)),
};
access::report_sub(&core.ctx, &decl);
}
+1
View File
@@ -457,6 +457,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> Collection
type Selection = Selection<K>;
type Item<'r> = Tab<'r>;
type ItemEvent = TabPartEvent;
const MEMBERS: bool = true;
fn items(&self) -> &CollectionProps {
&self.items
+26 -1
View File
@@ -1,8 +1,10 @@
//! The tab strip's keys.
//! The tab strip's keys, and a tab's close button, which the tab declares as a part while it is a member of the
//! strip's run.
use craft_behavior::{SelectionChange, keyed};
use craft_ui::contract::{CollectionEvent, ShowCollection as _};
use craft_ui::tabs::{Tab, TabStrip};
use craft_ui::testing::focus::AccessActionKind;
use craft_ui::testing::{Fixture, trial};
use egui::{Key, Modifiers};
use std::cell::{Cell, RefCell};
@@ -39,3 +41,26 @@ fn an_arrow_moves_the_focus_and_enter_shows_the_tab() {
fixture.idle(2);
assert_eq!(shown.get(), 1, "Enter shows the focused tab");
}
/// A click on a tab's close button closes the tab, and the close button is a node under its tab's node that an
/// AccessKit Click closes.
#[trial]
fn the_close_button_and_its_node_close_a_tab() {
let closed = Rc::new(RefCell::new(Vec::new()));
let seen = closed.clone();
let mut fixture = Fixture::new(move |ui| {
let keys = [0_usize, 1, 2];
let source = keyed(&keys, |key: &usize| *key);
let out = TabStrip::new("Documents").shown(0).show_items(ui, &source, &mut |key, _| Tab::new(TITLES[*key]));
seen.borrow_mut().extend(out.closed);
});
fixture.settle();
let tab = fixture.by_label("Two").expect("the tab's node");
let close = fixture.by_label("Close Two").expect("the close button's node");
assert_eq!(fixture.tree().parent_of_key(close.node), Some(tab.node), "the close button's node is under its tab's");
fixture.click(&close);
assert_eq!(closed.borrow().clone(), vec![1], "the close button closes its tab");
let first = fixture.by_label("Close One").expect("the close button's node");
fixture.access(AccessActionKind::Click, &first).idle(1);
assert_eq!(closed.borrow().clone(), vec![1, 0], "an AccessKit Click on the close node closes its tab");
}
+1 -1
View File
@@ -292,7 +292,7 @@ Content runs in every pass, and its sizes come from this pass. Layouts also read
- A scroll position the framework holds is also named by content: the first child at or after the view's start and its place in the view (`lazy::Anchor`, kept with the offset). When extents before that child change (estimates replaced by real extents, rows regrouped), the offset follows the child and the pass runs again, so the content in view does not move. An offset bound to the app (`Component::scroll`) is the app's plain offset, and a region that follows its end follows the end.
- A scroll area that does not run (a tab switched away) keeps its children's entries, and its content extent lives beside its offset (`ScrollState`) with the same lifetime, so it shows again at the same offset after any length of hide; one that runs drops the entries of the children it did not reach.
- A collection builds the rows in view, plus its lead, anchor, renaming and grabbed rows. Its rows are no Tab entries (Tab moves past the collection, arrows move its lead), so a row out of view has no stops to keep. It places the rows it does not build by the extents they had when last built, from the same store, and its output lists the rows in view and the kept rows. Rows it never built take its item layout's estimate, as a `Lazy` takes its own, so a long list is never built whole.
- Each built row is a run of the collection's item component, or, for a collection that sets `Collection::MEMBERS` (a colour table's cells), a member of the collection's own run: sensed in its arena, painted as a face and reported as an access sub-node of the collection, with no run of its own. Selection, activation, drags and AccessKit requests are the collection's either way.
- Each built row is a run of the collection's item component, or, for a collection that sets `Collection::MEMBERS` (a tab strip's tabs, a colour table's cells), a member of the collection's own run: sensed with its parts in its arena, updated, painted and finished at its row, and reported as an access sub-node of the collection with its parts' nodes under it, with no run of its own. Its output gives the item event, as a run's does. Selection, activation, drags and AccessKit requests on the row are the collection's either way.
- The access tree covers the view, by the same rule: content that runs reports its access nodes (a collection's built rows and their section headings included). A component that lays out section rows as its own parts (TileGrid's group headings and tail rows) reports the nodes of those in view. Content out of view (`Lazy` children and collection rows) is absent from the access tree until it scrolls in. AccessKit scroll actions still reach it, because they move the offset.
- Content that was never shown has only its estimate and no stops: Tab reaches it once it was shown. An app brings it into view with `.reveal(true)`.