mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:24:24 +00:00
Host tests find a list row's pointer-only parts from the row's node
craft-ui testing part_rect_of_node reads a part's rect from the shape record by the owner's AccessKit node, the lookup Fixture::part_rect makes by id. ThumbTarget::part and TrailingPart::part name a row's thumbnail and trailing parts; the row declares its parts through them. LayerInfo::thumb maps a layer part to the thumbnail that shows it, over the order the panel reads thumbnail clicks by, and craft-layers testing thumb_rect and fx_badge_rect give a host test the rect of a layer row's thumbnail or fx badge. The drag, menu and frame trials find thumbnails and the badge this way.
This commit is contained in:
@@ -6,8 +6,29 @@
|
||||
|
||||
pub mod ui;
|
||||
|
||||
/// The stories and trials this crate registers.
|
||||
/// The stories and trials this crate registers, and where a host test finds the parts of a layer row that have no
|
||||
/// access node of their own: a test finds the row by the layer's name and passes the row's node.
|
||||
#[cfg(feature = "screen-testing")]
|
||||
pub mod testing {
|
||||
use crate::ui::tree::{LayerInfo, LayerPart};
|
||||
use craft_ui::list::{ThumbTarget, TrailingPart};
|
||||
use craft_ui::testing::pointer::part_rect_of_node;
|
||||
use egui::accesskit::NodeId;
|
||||
use egui::{Context, Rect};
|
||||
|
||||
craft_ui::testing_registered!();
|
||||
|
||||
/// The rect of the thumbnail that shows `part` of the layer `info`, in the row whose node is `row`, as the row
|
||||
/// recorded it last pass; `None` when the row shows no such thumbnail. `row` is the layer's row, or for
|
||||
/// [`LayerPart::FilterMask`] the layer's Smart Filters row, whose thumbnail the filter mask is.
|
||||
pub fn thumb_rect(ctx: &Context, row: NodeId, info: &LayerInfo, part: LayerPart) -> Option<Rect> {
|
||||
let thumb = if part == LayerPart::FilterMask { ThumbTarget::First } else { info.thumb(part)? };
|
||||
part_rect_of_node(ctx, row, thumb.part())
|
||||
}
|
||||
|
||||
/// The rect of the `fx` badge of the layer row whose node is `row`, as the row recorded it last pass: the badge
|
||||
/// is a drag handle, named in the row's description; `None` when the layer has no effects.
|
||||
pub fn fx_badge_rect(ctx: &Context, row: NodeId) -> Option<Rect> {
|
||||
part_rect_of_node(ctx, row, TrailingPart::new(crate::ui::panel::FX_BADGE).part())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ mod rows;
|
||||
|
||||
use map::map_events;
|
||||
pub(in crate::ui::panel) use map::start_rename;
|
||||
pub(in crate::ui::panel) use rows::{LayerRows, ToggleSweeps, extra_parts, reveal_plan, thumb_click_replaces_select};
|
||||
pub(in crate::ui::panel) use rows::{LayerRows, ToggleSweeps, reveal_plan, thumb_click_replaces_select};
|
||||
use rows::{RevealPlan, list_selection};
|
||||
|
||||
use craft_behavior::{ColumnWidth, IconId};
|
||||
|
||||
@@ -14,7 +14,7 @@ use super::super::drag::{LayersDrag, drop_event, part_drop_event};
|
||||
use super::super::events::{ActivateOn, LayerColumn, LayerSelect, LayerToggle, LayersEvent, MenuTarget};
|
||||
use super::super::menu::{OpenMenu, shared_label};
|
||||
use super::super::row::{EYE, FX_PART, LOCK_PART, NAME, OPTIONS_PART};
|
||||
use super::rows::{ToggleSweeps, extra_parts, thumb_click_replaces_select, thumb_part};
|
||||
use super::rows::{ToggleSweeps, thumb_click_replaces_select, thumb_part};
|
||||
use crate::ui::tree::{LayerRowKey, LayerTree};
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -140,7 +140,7 @@ pub(super) fn map_events<T: LayerTree>(
|
||||
}
|
||||
CollectionEvent::Item(row, RowEvent::LinkToggled { thumb, linked, .. }) => {
|
||||
let info = tree.info(row.layer());
|
||||
if let Some(&part) = extra_parts(&info).get(thumb).filter(|part| info.masks.iter().any(|mask| mask.part == **part)) {
|
||||
if let Some(part) = info.thumb_shows(ThumbTarget::Extra(thumb)).filter(|part| info.masks.iter().any(|mask| mask.part == *part)) {
|
||||
events.push(LayersEvent::MaskLink { layer: row.layer().clone(), part, linked });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use super::super::context::PanelContext;
|
||||
use super::super::events::LayerColumn;
|
||||
use super::super::row::{EYE, LOCK};
|
||||
use crate::ui::filter::LayerFilter;
|
||||
use crate::ui::tree::{LayerInfo, LayerKind, LayerPart, LayerRowKey, LayerTree, SubRowGroup};
|
||||
use crate::ui::tree::{LayerInfo, LayerPart, LayerRowKey, LayerTree, SubRowGroup};
|
||||
|
||||
/// One displayed row.
|
||||
pub(in crate::ui::panel) struct DisplayRow<Id> {
|
||||
@@ -246,23 +246,14 @@ pub(in crate::ui::panel) fn thumb_click_replaces_select(part: LayerPart, mods: M
|
||||
if on_mask { mods.shift || mods.alt } else { mods.alt && !mods.shift }
|
||||
}
|
||||
|
||||
/// The part the thumbnail `which` of the row `key` shows: a Smart Filters row's is the filter mask.
|
||||
pub(super) fn thumb_part<Id>(key: &LayerRowKey<Id>, info: &LayerInfo, which: ThumbTarget) -> LayerPart {
|
||||
match which {
|
||||
ThumbTarget::First if matches!(key, LayerRowKey::Filters(_, None)) => LayerPart::FilterMask,
|
||||
ThumbTarget::First if info.kind == LayerKind::Frame => LayerPart::FrameShape,
|
||||
ThumbTarget::First => LayerPart::Pixels,
|
||||
ThumbTarget::Extra(i) => extra_parts(info).get(i).copied().unwrap_or(LayerPart::Pixels),
|
||||
_ => LayerPart::Pixels,
|
||||
which => info.thumb_shows(which).unwrap_or(LayerPart::Pixels),
|
||||
}
|
||||
}
|
||||
|
||||
/// The parts of a layer row's thumbnails after the first, in the order the row adds them: a frame's content, then the
|
||||
/// masks.
|
||||
pub(in crate::ui::panel) fn extra_parts(info: &LayerInfo) -> Vec<LayerPart> {
|
||||
let content = (info.kind == LayerKind::Frame).then_some(LayerPart::FrameContent);
|
||||
content.into_iter().chain(info.masks.iter().map(|mask| mask.part)).collect()
|
||||
}
|
||||
|
||||
/// The readers of the eye and lock sweeps, kept across passes while the pointer is held.
|
||||
#[derive(Clone)]
|
||||
pub(in crate::ui::panel) struct ToggleSweeps {
|
||||
|
||||
@@ -21,6 +21,8 @@ pub use events::{
|
||||
};
|
||||
pub use footer::{LayersFooterAction, LayersFooterButton};
|
||||
pub use menu::{LayersMenuAction, LayersPanelCommands, LayersPanelKeys, panel_rows};
|
||||
#[cfg(feature = "screen-testing")]
|
||||
pub(crate) use row::FX_BADGE;
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ use egui::emath::GuiRounding as _;
|
||||
use egui::{Color32, Rect, Stroke, pos2, vec2};
|
||||
|
||||
use super::LayersPanelWords;
|
||||
use super::body::{extra_parts, thumb_click_replaces_select};
|
||||
use super::body::thumb_click_replaces_select;
|
||||
use super::context::{PanelContext, ThumbHost};
|
||||
use super::drag::LayersDrag;
|
||||
use crate::ui::thumbs::LayerThumb;
|
||||
@@ -34,7 +34,7 @@ pub(super) const FX_PART: u16 = 1;
|
||||
/// A Smart Filter's trailing Blending Options button.
|
||||
pub(super) const OPTIONS_PART: u16 = 2;
|
||||
/// The trailing `fx` badge: a drag handle that carries the layer's effects.
|
||||
pub(super) const FX_BADGE: u16 = 3;
|
||||
pub(crate) const FX_BADGE: u16 = 3;
|
||||
|
||||
/// The cross over a disabled mask is a fixed data colour, like the label colours.
|
||||
const DISABLED_MASK: LabelColor = LabelColor::Red;
|
||||
@@ -290,13 +290,12 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR
|
||||
row = with_load_cursor(row, cx.held, target, part, &info);
|
||||
}
|
||||
if active {
|
||||
let extra = |part: LayerPart| extra_parts(&info).iter().position(|held| *held == part).map(ThumbTarget::Extra);
|
||||
match cx.selection.target {
|
||||
LayerPart::FilterMask => {}
|
||||
// A frame as a whole: its shape and its content.
|
||||
LayerPart::Pixels if frame => row = row.thumb_target([ThumbTarget::First, ThumbTarget::Extra(0)]),
|
||||
LayerPart::Pixels | LayerPart::FrameShape => row = row.thumb_target(ThumbTarget::First),
|
||||
part => row = row.thumb_target(extra(part).unwrap_or(ThumbTarget::First)),
|
||||
part => row = row.thumb_target(info.thumb(part).unwrap_or(ThumbTarget::First)),
|
||||
}
|
||||
}
|
||||
} else if let Some(icon) = kind_icon(info.kind) {
|
||||
|
||||
@@ -12,6 +12,7 @@ use craft_behavior::IconId;
|
||||
use craft_keymap::Mods;
|
||||
use craft_theme::LabelColor;
|
||||
use craft_ui::contract::{Entry, ReorderMove};
|
||||
use craft_ui::list::ThumbTarget;
|
||||
|
||||
use super::filter::{EffectKind, LayerFilter, SmartSource};
|
||||
use super::panel::MenuTarget;
|
||||
@@ -206,6 +207,35 @@ impl LayerInfo {
|
||||
description: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The parts a layer row's thumbnails show, in the row's order: the layer's pixels (a frame's shape), a frame's
|
||||
/// content, then the masks. A row at thumbnail size None, and an artboard's row without masks, shows none of them.
|
||||
fn thumb_parts(&self) -> impl Iterator<Item = LayerPart> {
|
||||
let frame = self.kind == LayerKind::Frame;
|
||||
let first = if frame { LayerPart::FrameShape } else { LayerPart::Pixels };
|
||||
let content = frame.then_some(LayerPart::FrameContent);
|
||||
std::iter::once(first).chain(content).chain(self.masks.iter().map(|mask| mask.part))
|
||||
}
|
||||
|
||||
/// The part the layer row's thumbnail `which` shows; `None` past the last.
|
||||
pub(crate) fn thumb_shows(&self, which: ThumbTarget) -> Option<LayerPart> {
|
||||
let mut parts = self.thumb_parts();
|
||||
match which {
|
||||
ThumbTarget::First => parts.next(),
|
||||
ThumbTarget::Extra(i) => parts.nth(i + 1),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The thumbnail of the layer's row that shows `part`; `None` when none does ([`LayerPart::Pixels`] of a frame,
|
||||
/// whose shape and content are two). A host test finds its place with `testing::thumb_rect`.
|
||||
pub fn thumb(&self, part: LayerPart) -> Option<ThumbTarget> {
|
||||
let mut parts = self.thumb_parts();
|
||||
if parts.next() == Some(part) {
|
||||
return Some(ThumbTarget::First);
|
||||
}
|
||||
parts.position(|shown| shown == part).map(ThumbTarget::Extra)
|
||||
}
|
||||
}
|
||||
|
||||
/// What a layer is.
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
use craft_behavior::EditEvent;
|
||||
use craft_behavior::{Cursor, CursorBadge, CursorIcon, PaintedCursor, SelectionChange};
|
||||
use craft_layers::testing;
|
||||
use craft_layers::ui::mock::FakeLayers;
|
||||
use craft_layers::ui::panel::{LayerDrop, LayerSelect, LayersDrag, LayersEvent, LayersPanel, MaskMove};
|
||||
use craft_layers::ui::tree::{LayerPart, LayerRowKey};
|
||||
use craft_layers::ui::tree::{LayerPart, LayerRowKey, LayerTree as _};
|
||||
use craft_theme::LabelColor;
|
||||
use craft_ui::contract::Entry;
|
||||
use craft_ui::testing::{Fixture, Target, pointer, trial};
|
||||
@@ -49,21 +50,30 @@ fn right_click(fixture: &mut Fixture, at: Pos2) {
|
||||
fixture.idle(3);
|
||||
}
|
||||
|
||||
/// The middle of the painted `fx` badge of the row named `layer`.
|
||||
/// The sample tree's layer with a layer mask.
|
||||
const MASKED: u32 = 3;
|
||||
|
||||
/// The middle of the `fx` badge of the row named `layer`, found from the row's node as a host test finds it.
|
||||
fn fx_badge(fixture: &Fixture, layer: &str) -> Pos2 {
|
||||
let row = node(fixture, layer).rect;
|
||||
let badge = fixture.texts().iter().find(|text| text.text == "fx" && row.contains(text.rect.center())).expect("the row's fx badge");
|
||||
badge.rect.center()
|
||||
let row = node(fixture, layer);
|
||||
testing::fx_badge_rect(fixture.ctx(), row.node.into()).expect("the row's fx badge").center()
|
||||
}
|
||||
|
||||
fn node(fixture: &Fixture, label: &str) -> Target {
|
||||
fixture.by_label(label).unwrap_or_else(|| panic!("no node named {label:?}"))
|
||||
}
|
||||
|
||||
/// A point on the layer mask thumbnail of `layer`, which follows its link chain.
|
||||
fn mask_thumb(fixture: &Fixture, layer: &str) -> Pos2 {
|
||||
let link = node(fixture, &format!("Unlink layer mask of {layer}"));
|
||||
Pos2::new(link.rect.right() + link.rect.width() * 0.75, link.rect.center().y)
|
||||
/// The middle of the thumbnail that shows `part` in the row of the sample tree's layer `id`, found from the row's
|
||||
/// node as a host test finds it.
|
||||
fn thumb(fixture: &Fixture, id: u32, part: LayerPart) -> Pos2 {
|
||||
let info = FakeLayers::sample().info(&id);
|
||||
let row = node(fixture, &info.name);
|
||||
testing::thumb_rect(fixture.ctx(), row.node.into(), &info, part).unwrap_or_else(|| panic!("no {part:?} thumbnail in {:?}", info.name)).center()
|
||||
}
|
||||
|
||||
/// The middle of the layer mask thumbnail of the sample tree's layer `id`.
|
||||
fn mask_thumb(fixture: &Fixture, id: u32) -> Pos2 {
|
||||
thumb(fixture, id, LayerPart::LayerMask)
|
||||
}
|
||||
|
||||
/// Drags from `from` and releases on the middle of the row named `onto`.
|
||||
@@ -99,13 +109,13 @@ fn transfers(seen: &Seen) -> Vec<(Vec<LayerRowKey<u32>>, u32, bool)> {
|
||||
#[trial]
|
||||
fn a_mask_thumbnail_dropped_on_another_layer_moves_the_mask_there() {
|
||||
let (mut fixture, seen, _) = rig();
|
||||
let from = mask_thumb(&fixture, "Masked");
|
||||
let from = mask_thumb(&fixture, MASKED);
|
||||
drag_onto(&mut fixture, from, "Title");
|
||||
assert_eq!(mask_drops(&seen), [MaskMove::new(3, LayerPart::LayerMask, 4, false)], "onto Title");
|
||||
assert_eq!(mask_drops(&seen), [MaskMove::new(MASKED, LayerPart::LayerMask, 4, false)], "onto Title");
|
||||
fixture.hold(Modifiers::ALT);
|
||||
drag_onto(&mut fixture, from, "Title");
|
||||
fixture.hold(Modifiers::NONE);
|
||||
assert_eq!(mask_drops(&seen), [MaskMove::new(3, LayerPart::LayerMask, 4, true)], "Alt copies");
|
||||
assert_eq!(mask_drops(&seen), [MaskMove::new(MASKED, LayerPart::LayerMask, 4, true)], "Alt copies");
|
||||
drag_onto(&mut fixture, from, "Levels 1");
|
||||
assert_eq!(mask_drops(&seen), [], "Levels 1 has a layer mask already");
|
||||
}
|
||||
@@ -121,7 +131,7 @@ fn a_row_drag_carries_its_layers_for_targets_outside_the_panel() {
|
||||
fixture.drag_hold_at(title, away);
|
||||
assert_eq!(held(&fixture).layers(), [&4], "the dragged row's layer");
|
||||
fixture.release_at(title + away).idle(2);
|
||||
let mask = mask_thumb(&fixture, "Masked");
|
||||
let mask = mask_thumb(&fixture, MASKED);
|
||||
fixture.drag_hold_at(mask, away);
|
||||
assert!(held(&fixture).layers().is_empty(), "a mask is no layer");
|
||||
fixture.release_at(mask + away).idle(2);
|
||||
@@ -175,6 +185,25 @@ fn the_fx_badge_drags_the_layers_effects_and_a_click_on_it_selects_the_row() {
|
||||
assert_eq!(selects.last().map(|select| &select.change), Some(&SelectionChange::Set(vec![7])), "the click selects Styled");
|
||||
}
|
||||
|
||||
/// A Cmd/Ctrl click on a thumbnail a host test finds from the row's node loads that thumbnail's part: the layer's
|
||||
/// pixels, then its layer mask.
|
||||
#[trial]
|
||||
fn a_cmd_click_on_a_thumbnail_found_from_its_row_loads_its_part() {
|
||||
for part in [LayerPart::Pixels, LayerPart::LayerMask] {
|
||||
let (mut fixture, seen, _) = rig();
|
||||
let at = thumb(&fixture, MASKED, part);
|
||||
fixture.hold(Modifiers::COMMAND);
|
||||
fixture.click_at(at).idle(2);
|
||||
fixture.hold(Modifiers::NONE);
|
||||
let loads: Vec<(u32, LayerPart)> = seen
|
||||
.borrow()
|
||||
.iter()
|
||||
.filter_map(|event| if let LayersEvent::ThumbClick { layer, part, .. } = event { Some((*layer, *part)) } else { None })
|
||||
.collect();
|
||||
assert_eq!(loads, [(MASKED, part)], "{part:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// With Cmd/Ctrl held over a thumbnail a click would load as a selection, the cursor is the pointing hand, with the
|
||||
/// mark of the operation Shift or Alt picks; without Cmd/Ctrl it is not.
|
||||
#[trial]
|
||||
@@ -187,7 +216,7 @@ fn cmd_over_a_thumbnail_shows_the_load_cursor() {
|
||||
fixture.hold(Modifiers::NONE);
|
||||
cursor
|
||||
};
|
||||
let mask = mask_thumb(&fixture, "Masked");
|
||||
let mask = mask_thumb(&fixture, MASKED);
|
||||
assert_eq!(cursor_over(&mut fixture, mask, Modifiers::COMMAND), Some(Cursor::System(CursorIcon::PointingHand)), "a new selection");
|
||||
assert_eq!(
|
||||
cursor_over(&mut fixture, mask, Modifiers::COMMAND | Modifiers::SHIFT),
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
//! Options button, and a frame's masks after its content thumbnail: linked and dragged by their own index.
|
||||
|
||||
use craft_behavior::{EditEvent, SelectionChange};
|
||||
use craft_layers::testing;
|
||||
use craft_layers::ui::mock::{FakeLayers, sub_row};
|
||||
use craft_layers::ui::panel::{ActivateOn, LayerDrop, LayersEvent, LayersPanel, MaskMove};
|
||||
use craft_layers::ui::tree::{LayerInfo, LayerKind, LayerPart, LayerRowKey, LayerSelection, MaskInfo, SubRow, SubRows};
|
||||
use craft_ui::testing::{Fixture, Target, pointer, trial};
|
||||
use egui::{Key, Modifiers, Pos2, Vec2};
|
||||
use egui::{Key, Modifiers, Vec2};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
@@ -171,11 +172,11 @@ fn a_frames_mask_thumbnail_drags_the_mask() {
|
||||
frame.masks.push(MaskInfo::new(LayerPart::LayerMask, true, true));
|
||||
let mut tree = FakeLayers::default();
|
||||
tree.add(None, LayerInfo::new("Title", LayerKind::Text), false);
|
||||
let id = tree.add(None, frame, false);
|
||||
let id = tree.add(None, frame.clone(), false);
|
||||
let (mut fixture, app) = rig(tree);
|
||||
take(&app);
|
||||
let link = node(&fixture, "Unlink layer mask of Frame 1").rect;
|
||||
let from = Pos2::new(link.right() + link.width() * 0.75, link.center().y);
|
||||
let row = node(&fixture, "Frame 1").node.into();
|
||||
let from = testing::thumb_rect(fixture.ctx(), row, &frame, LayerPart::LayerMask).expect("the frame's layer mask thumbnail").center();
|
||||
let to = node(&fixture, "Title").center();
|
||||
fixture.drag_hold_at(from, to - from).release_at(to).idle(2);
|
||||
let moves: Vec<_> = take(&app)
|
||||
|
||||
@@ -22,6 +22,13 @@ impl NodeKey {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NodeKey> for NodeId {
|
||||
/// The AccessKit id of the node, for lookups that take what a host test holds (`testing::pointer::part_rect_of_node`).
|
||||
fn from(key: NodeKey) -> NodeId {
|
||||
NodeId(key.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// An action a node declares.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
|
||||
@@ -365,6 +365,16 @@ pub(crate) fn sensing_parts(ctx: &Context, root: Id, sense: craft_behavior::Sens
|
||||
/// The bounds of the part `part` of `owner` (the arena root or a member) in last pass's shape record: pointer-only
|
||||
/// parts have no access node, so this record is where their place is read.
|
||||
pub(crate) fn part_bounds(ctx: &Context, owner: Id, part: craft_behavior::PartRef) -> Option<egui::Rect> {
|
||||
owned_part_bounds(ctx, |shape_owner| shape_owner == owner, part)
|
||||
}
|
||||
|
||||
/// [`part_bounds`] of the owner whose AccessKit node is `node`, for a test that holds the node it found, not the id.
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn node_part_bounds(ctx: &Context, node: accesskit::NodeId, part: craft_behavior::PartRef) -> Option<egui::Rect> {
|
||||
owned_part_bounds(ctx, |shape_owner| shape_owner.accesskit_id() == node, part)
|
||||
}
|
||||
|
||||
fn owned_part_bounds(ctx: &Context, owner: impl Fn(Id) -> bool, part: craft_behavior::PartRef) -> Option<egui::Rect> {
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
PerViewport::<Shapes>::with(ctx, viewport, |record| {
|
||||
record
|
||||
@@ -372,7 +382,7 @@ pub(crate) fn part_bounds(ctx: &Context, owner: Id, part: craft_behavior::PartRe
|
||||
.values()
|
||||
.flat_map(|roots| roots.values())
|
||||
.flat_map(|root| root.shapes.iter())
|
||||
.find(|shape| shape.owner == owner && shape.part == Some(part))
|
||||
.find(|shape| owner(shape.owner) && shape.part == Some(part))
|
||||
.map(|shape| shape.shape.bounds())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -91,6 +91,14 @@ pub fn cancel_captured_presses(ctx: &egui::Context) {
|
||||
crate::runtime::pointer::cancel_press(ctx, craft_behavior::PressCancel::Escape);
|
||||
}
|
||||
|
||||
/// The rect of the part `part` of the component whose AccessKit node is `node`, as the sensing step recorded it last
|
||||
/// pass: how a host test that found a component by its node (a list row by its name) finds a pointer-only part of it
|
||||
/// (a thumbnail, a drag handle), which has no node of its own. [`Fixture::part_rect`](super::Fixture::part_rect) is
|
||||
/// the same lookup by the component's id. Callers assert how rects relate (inside, below), not their size.
|
||||
pub fn part_rect_of_node(ctx: &egui::Context, node: accesskit::NodeId, part: impl Into<craft_behavior::PartRef>) -> Option<egui::Rect> {
|
||||
crate::runtime::pointer::node_part_bounds(ctx, node, part.into())
|
||||
}
|
||||
|
||||
/// Whether an open press holds the pointer in the running viewport, as Escape reads it.
|
||||
pub fn press_captured(ctx: &egui::Context) -> bool {
|
||||
crate::runtime::pointer::press_captured(ctx)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::ListRow;
|
||||
use super::placement::Placed;
|
||||
use super::show::{TEXT_CELL, TOGGLE, TRAILING};
|
||||
use super::show::{TEXT_CELL, TOGGLE};
|
||||
use super::style::ListRowStyle;
|
||||
use super::thumb::{RowThumb, target_at};
|
||||
use super::trailing::{TrailingFace, TrailingItem, cell_key, field_key, trailing_run};
|
||||
@@ -40,7 +40,7 @@ impl ListRow<'_> {
|
||||
}
|
||||
}
|
||||
TrailingItem::Part { part, face, enabled, revealed, .. } => {
|
||||
let key = TRAILING.at(u64::from(part.0));
|
||||
let key = part.part();
|
||||
let shown = !*revealed
|
||||
|| cx.response.hovered()
|
||||
|| selected
|
||||
|
||||
@@ -264,7 +264,7 @@ impl Component for ListRow<'_> {
|
||||
TrailingItem::Part { part, face, name, enabled, .. } => {
|
||||
// A text face takes its whole slot; the other faces the icon square in it.
|
||||
let shape = if matches!(face, TrailingFace::Strong(_)) { *slot } else { shape };
|
||||
let key = TRAILING.at(u64::from(part.0));
|
||||
let key = part.part();
|
||||
if self.drag_at(RowDragSpot::Trailing(*part)).is_some() {
|
||||
cx.part(key, shape)
|
||||
.sense(Sense::CLICK | Sense::DRAG | Sense::PICKS_ITEM)
|
||||
@@ -288,7 +288,7 @@ impl Component for ListRow<'_> {
|
||||
let target = target_at(at);
|
||||
let sense =
|
||||
if self.drag_at(RowDragSpot::Thumb(target)).is_some() { Sense::CLICK | Sense::DRAG } else { Sense::CLICK } | Sense::PICKS_ITEM;
|
||||
let part = cx.part(THUMB.at(at as u64), thumb).sense(sense).pointer_only("A thumbnail is a pointer target; the keys act on the row");
|
||||
let part = cx.part(target.part(), thumb).sense(sense).pointer_only("A thumbnail is a pointer target; the keys act on the row");
|
||||
if let Some((_, cursor)) = self.cursors.iter().find(|(held, _)| *held == target) {
|
||||
part.cursor(cursor.clone());
|
||||
}
|
||||
@@ -332,16 +332,16 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
}
|
||||
for at in 0..=self.extras.len() {
|
||||
let Some(result) = cx.part_if_declared(THUMB.at(at as u64)) else { continue };
|
||||
let target = target_at(at);
|
||||
let Some(result) = cx.part_if_declared(target.part()) else { continue };
|
||||
let phase = result.press.phase;
|
||||
if let (PressPhase::DragStart { .. }, Some(payload)) = (phase, self.drag_at(RowDragSpot::Thumb(target))) {
|
||||
let preview = DragPreview::frame(self.thumb_size(&cx.style.sizes), None);
|
||||
crate::runtime::drag::start(&cx.ctx, cx.id, payload.clone(), None, preview);
|
||||
self.event = Some(RowEvent::PartDrag(RowDragSpot::Thumb(target)));
|
||||
} else if let Some(source) = cx.part_activated(THUMB.at(at as u64)) {
|
||||
} else if let Some(source) = cx.part_activated(target.part()) {
|
||||
let clicks = part_clicks(source, phase);
|
||||
self.event = Some(RowEvent::ThumbClicked { target, mods: part_mods(cx, THUMB.at(at as u64), source), clicks });
|
||||
self.event = Some(RowEvent::ThumbClicked { target, mods: part_mods(cx, target.part(), source), clicks });
|
||||
}
|
||||
}
|
||||
if self.lead_text.is_some()
|
||||
@@ -352,7 +352,7 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
for trailing in &self.trailing {
|
||||
let TrailingItem::Part { part, .. } = &trailing.item else { continue };
|
||||
let key = TRAILING.at(u64::from(part.0));
|
||||
let key = part.part();
|
||||
if let Some(payload) = self.drag_at(RowDragSpot::Trailing(*part)) {
|
||||
// A handle's click is the row's: only its drag is its own.
|
||||
if let Some(result) = cx.part_if_declared(key)
|
||||
@@ -473,7 +473,7 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
TrailingItem::Part { part, face, name, .. } => {
|
||||
let name = self.part_name(*part, name, &words, label);
|
||||
let node = access.node(TRAILING.at(u64::from(part.0)), Role::BUTTON);
|
||||
let node = access.node(part.part(), Role::BUTTON);
|
||||
node.name = Name::Text(name.as_str().to_owned());
|
||||
if let TrailingFace::Disclosure { open } = face {
|
||||
node.expanded(*open);
|
||||
|
||||
@@ -87,6 +87,16 @@ impl ThumbTarget {
|
||||
let at = part.index.filter(|_| part.key == super::show::THUMB)?;
|
||||
usize::try_from(at).ok().map(target_at)
|
||||
}
|
||||
|
||||
/// The row part this thumbnail is, the inverse of [`ThumbTarget::of_part`]: a thumbnail is a pointer-only part
|
||||
/// with no access node, so a test finds its place by this part.
|
||||
pub fn part(self) -> craft_behavior::PartRef {
|
||||
let at = match self {
|
||||
ThumbTarget::First => 0,
|
||||
ThumbTarget::Extra(i) => i + 1,
|
||||
};
|
||||
super::show::THUMB.at(at as u64)
|
||||
}
|
||||
}
|
||||
|
||||
/// The thumbnails a row's editing is aimed at, framed with corner brackets: usually one, several when the edit goes to
|
||||
|
||||
@@ -20,6 +20,11 @@ impl TrailingPart {
|
||||
pub const fn new(n: u16) -> Self {
|
||||
TrailingPart(n)
|
||||
}
|
||||
|
||||
/// The row part this item is: a drag handle has no access node, so a test finds its place by this part.
|
||||
pub fn part(self) -> craft_behavior::PartRef {
|
||||
super::show::TRAILING.at(u64::from(self.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// How a trailing part looks.
|
||||
|
||||
Reference in New Issue
Block a user