mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 16:59:56 +01:00
pilot-fw red 1: graph wires in the body layer (q133), annotation pointer-only reasons and access clicks, body-part moves in the rows' space, story fixes
This commit is contained in:
1 parent
79d8f0066c
commit
ebe23c6a2f
9 files changed
+143
-61
No files matched your search
@@ -746,10 +746,12 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
|
||||
/// The press of the part of the collection that holds the pointer's press, when the collection moves the selection
|
||||
/// from it (`Collection::moves_from_part`). That press is the part's own, never the collection's: its phase drives
|
||||
/// the move, its release commits it and its cancel cancels it.
|
||||
fn moving_part_press(comp: &C, cx: &Cx<'_, C>) -> Option<PressPhase> {
|
||||
/// the move, its release commits it and its cancel cancels it. With it, whether the part is a body part, whose
|
||||
/// phase reads in the rows' space already.
|
||||
fn moving_part_press(comp: &C, cx: &Cx<'_, C>) -> Option<(PressPhase, bool)> {
|
||||
let part = crate::runtime::pointer::pressed_part(&cx.core.ctx, cx.core.id).filter(|&part| comp.moves_from_part(part))?;
|
||||
Some(cx.part_if_declared(part)?.press.phase).filter(PressPhase::is_press)
|
||||
let result = cx.part_if_declared(part)?;
|
||||
Some((result.press.phase, result.body)).filter(|(phase, _)| phase.is_press())
|
||||
}
|
||||
|
||||
/// Step 9: sweeps, row drags, drops and the free-layout move, from the collection's own press (or the press of a
|
||||
@@ -766,17 +768,20 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
let free = matches!(layout.nav(), NavShape::Spatial);
|
||||
let part_phase = if free { Self::moving_part_press(comp, cx) } else { None };
|
||||
let from_part = part_phase.is_some();
|
||||
let phase = part_phase.unwrap_or(cx.core.press.phase);
|
||||
let in_rows = part_phase.is_some_and(|(_, body)| body);
|
||||
let phase = part_phase.map_or(cx.core.press.phase, |(phase, _)| phase);
|
||||
if !from_part && phase.is_press() && !matches!(phase, PressPhase::Cancel { .. }) {
|
||||
self.sweep_to(cx, layout, Placement { rect, offset, rtl }, phase);
|
||||
}
|
||||
// The pointer comes in screen space; the rows and a move's offset are in the rows' own space.
|
||||
// The pointer comes in screen space, a body part's press in the rows' own space, where the rows and a move's
|
||||
// offset are.
|
||||
let xf = self.xf;
|
||||
let layer = |point: Pos2| xf.map_or(point, |map| map.to_layer(point));
|
||||
let pressed = |point: Pos2| if in_rows { point } else { layer(point) };
|
||||
match phase {
|
||||
// A sweep opens only from the collection's own press, so none runs beside a part's move.
|
||||
PressPhase::DragStart { start, pos, .. } | PressPhase::Drag { start, pos, .. } if start.button == PointerButton::Primary && from_part => {
|
||||
self.free_move(cx, layer(start.origin), layer(pos));
|
||||
self.free_move(cx, pressed(start.origin), pressed(pos));
|
||||
}
|
||||
PressPhase::DragStart { start, pos, .. } | PressPhase::Drag { start, pos, .. } if start.button == PointerButton::Primary => {
|
||||
let origin = layer(start.origin);
|
||||
@@ -796,7 +801,11 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
}
|
||||
PressPhase::Release { start, pos, .. } => {
|
||||
if let Some(gesture) = self.drags.moving.take() {
|
||||
self.events.push(CollectionEvent::Move(EditEvent::commit(gesture, Mixed::Same(Vec2::ZERO), layer(pos) - layer(start.origin))));
|
||||
self.events.push(CollectionEvent::Move(EditEvent::commit(
|
||||
gesture,
|
||||
Mixed::Same(Vec2::ZERO),
|
||||
pressed(pos) - pressed(start.origin),
|
||||
)));
|
||||
}
|
||||
for (gesture, before, after) in self.drags.sweep.take().map(|sweep| sweep.open).unwrap_or_default() {
|
||||
self.events.push(CollectionEvent::Toggle(EditEvent::commit(gesture, Mixed::Same(before), after)));
|
||||
|
||||
@@ -898,6 +898,7 @@ pub(crate) fn member_show<C: Show>(
|
||||
sense,
|
||||
inactive: false,
|
||||
held: false,
|
||||
body: false,
|
||||
};
|
||||
let part_state = steps::part_state(&result, enabled || faded, None);
|
||||
// A peek that opens no lifetime stage and is dropped without a write-back, as a face's.
|
||||
|
||||
@@ -47,6 +47,8 @@ pub struct PartResult {
|
||||
pub inactive: bool,
|
||||
/// The component holds a press on the part that the part does not sense itself: it paints pressed.
|
||||
pub held: bool,
|
||||
/// A collection's part in its rows' space (`PartsCx::in_body`): its press reads in that space.
|
||||
pub(crate) body: bool,
|
||||
}
|
||||
|
||||
impl PartResult {
|
||||
@@ -60,6 +62,7 @@ impl PartResult {
|
||||
sense: Sense::empty(),
|
||||
inactive: false,
|
||||
held: false,
|
||||
body: false,
|
||||
};
|
||||
|
||||
/// The part paints pressed: its own press, or one its component holds on it.
|
||||
@@ -1327,6 +1330,7 @@ fn part_results_in(
|
||||
sense: decl.sense,
|
||||
inactive: decl.inactive,
|
||||
held: decl.held,
|
||||
body: decl.body,
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
@@ -24,6 +24,9 @@ pub(super) const MARKER: PartKey = PartKey::new("marker");
|
||||
/// What every annotation part senses: a press selects, a drag moves or resizes, a secondary click asks for the menu.
|
||||
const SENSE: Sense = Sense::PRESS.union(Sense::CONTEXT_CLICK);
|
||||
|
||||
/// Why an annotation part takes the pointer only (q134): the app's annotation commands act on the selected annotation.
|
||||
const POINTER_ONLY: &str = "the app's annotation commands act on the selected annotation: move, resize, edit and delete";
|
||||
|
||||
/// Which annotation: the kind and the app's id.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
@@ -252,7 +255,7 @@ impl<'a> Layers<'a> {
|
||||
let frame = in_body(origin, backdrop.rect);
|
||||
let key = AnnotationKey::Backdrop(backdrop.id);
|
||||
let stacking = u32::try_from(order).unwrap_or(u32::MAX);
|
||||
let body = cx.in_body(BACKDROP.at(backdrop.id), frame).sense(SENSE).stacking(stacking).flags(self.flags(key));
|
||||
let body = cx.in_body(BACKDROP.at(backdrop.id), frame).sense(SENSE).stacking(stacking).flags(self.flags(key)).pointer_only(POINTER_ONLY);
|
||||
if let Some(title) = backdrop.title {
|
||||
body.node(Role::GROUP, title);
|
||||
}
|
||||
@@ -274,6 +277,7 @@ impl<'a> Layers<'a> {
|
||||
.priority(HitPriority::new(HitLevel::Body, 0))
|
||||
.over()
|
||||
.flags(self.flags(key))
|
||||
.pointer_only(POINTER_ONLY)
|
||||
.node(Role::PARAGRAPH, note.text);
|
||||
}
|
||||
for marker in self.markers {
|
||||
@@ -285,6 +289,7 @@ impl<'a> Layers<'a> {
|
||||
.priority(HitPriority::new(HitLevel::Body, 1))
|
||||
.over()
|
||||
.flags(self.flags(key))
|
||||
.pointer_only(POINTER_ONLY)
|
||||
.node(Role::BUTTON, marker.label);
|
||||
}
|
||||
}
|
||||
@@ -359,9 +364,9 @@ impl<'a> Layers<'a> {
|
||||
for (part, key, resize) in parts {
|
||||
let Some(result) = cx.part_if_declared(part) else { continue };
|
||||
let press = result.press;
|
||||
if let PressPhase::Down { start, .. } = press.phase
|
||||
&& start.button == PointerButton::Primary
|
||||
{
|
||||
// An assistive technology's click selects as a primary press does.
|
||||
let by_access = matches!(cx.part_activated(part), Some(crate::runtime::commands::FireSource::Access));
|
||||
if by_access || matches!(press.phase, PressPhase::Down { start, .. } if start.button == PointerButton::Primary) {
|
||||
pressed = Some(key);
|
||||
}
|
||||
self.gesture(press, key, resize, (zoom, origin, min), cx, &mut events);
|
||||
|
||||
@@ -127,7 +127,8 @@ fn backdrop_resizing(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// A note longer than its rect, which wraps and grows down, beside a backdrop whose description is clipped to it.
|
||||
#[story(NodeGraph<'static, ()>, covers = [LongText], drive = Drive::Never)]
|
||||
fn long_note(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let notes = [Note::new(1, Rect::from_min_size(Pos2::new(400.0, 64.0), Vec2::new(160.0, 40.0)), LONG_NOTE)];
|
||||
// Under the backdrop and inside the story's room, which clips the graph's body.
|
||||
let notes = [Note::new(1, Rect::from_min_size(Pos2::new(32.0, 164.0), Vec2::new(352.0, 24.0)), LONG_NOTE)];
|
||||
let small = Rect::from_min_max(FRAME.min, Pos2::new(FRAME.max.x, 150.0));
|
||||
annotated_graph(ui, data, &Annotated { frame: small, notes: ¬es, markers: &MARKERS, selected: None })
|
||||
}
|
||||
@@ -296,12 +296,17 @@ impl<'a, E: 'static> NodeGraph<'a, E> {
|
||||
self
|
||||
}
|
||||
|
||||
/// A port's position on screen: the node's place from the graph plus the kind's `port_offset`, through the
|
||||
/// zoom. The one function behind the wires' parts, their paint and the loose wire.
|
||||
fn port_point(&self, origin: Pos2, port: PortRef) -> Option<Pos2> {
|
||||
/// A port's position in the rows' space: the node's place from the graph's top left at `origin` plus the kind's
|
||||
/// `port_offset`, in document units. The one function behind the wires' parts, their paint and the loose wire.
|
||||
fn port_in_body(&self, origin: Pos2, port: PortRef) -> Option<Pos2> {
|
||||
let rect = self.positions.get(port.node.0 as usize)?;
|
||||
let kind = self.kinds.get(port.node.0 as usize)?;
|
||||
Some(origin + self.zoom.to_layer(port_center(*kind, *rect, port.port)).to_vec2())
|
||||
Some(origin + port_center(*kind, *rect, port.port).to_vec2())
|
||||
}
|
||||
|
||||
/// A point of the rows' space in the graph's layer, where the pointer and the loose wire are: through the zoom.
|
||||
fn to_layer(&self, origin: Pos2, at: Pos2) -> Pos2 {
|
||||
origin + self.zoom.to_layer((at - origin).to_pos2()).to_vec2()
|
||||
}
|
||||
|
||||
/// The side of its node a port sits on, as the node's kind places it.
|
||||
@@ -309,17 +314,13 @@ impl<'a, E: 'static> NodeGraph<'a, E> {
|
||||
Some(self.kinds.get(port.node.0 as usize)?.port_side(port.port))
|
||||
}
|
||||
|
||||
/// The curve of `wire` in the rows' space, from the graph's top left at `origin`.
|
||||
fn wire_curve(&self, origin: Pos2, wire: &Wire) -> Option<Vec<Pos2>> {
|
||||
let (from, from_side) = (self.port_point(origin, wire.from)?, self.port_side(wire.from)?);
|
||||
let (to, to_side) = (self.port_point(origin, wire.to)?, self.port_side(wire.to)?);
|
||||
let (from, from_side) = (self.port_in_body(origin, wire.from)?, self.port_side(wire.from)?);
|
||||
let (to, to_side) = (self.port_in_body(origin, wire.to)?, self.port_side(wire.to)?);
|
||||
Some(sampled(wire_controls(from, from_side, to, to_side)))
|
||||
}
|
||||
|
||||
/// A point of the graph's layer, as press positions come, in document units: `port_point` undone.
|
||||
fn to_document(&self, origin: Pos2, at: Pos2) -> Pos2 {
|
||||
((at - origin - self.zoom.offset) / self.zoom.scale).to_pos2()
|
||||
}
|
||||
|
||||
/// The annotation layers, handed the graph's own slices.
|
||||
fn layers(&self) -> Layers<'a> {
|
||||
Layers::of(self)
|
||||
@@ -374,8 +375,9 @@ impl<E: 'static> Component for NodeGraph<'_, E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The annotations' parts, then each wire as a polyline part at `Edge` priority: a press on a port beats the
|
||||
/// wire, which sits under the nodes. A wire in `wire_selection` carries `Flags::SELECTED`, so it resolves to its
|
||||
/// The annotations' parts, then each wire as a polyline part in the rows' space at `Edge` priority, through the
|
||||
/// zoom with the nodes: a press on a port beats the wire, which sits under the nodes and over the backdrops, so a
|
||||
/// press inside a backdrop reaches it. A wire in `wire_selection` carries `Flags::SELECTED`, so it resolves to its
|
||||
/// on look.
|
||||
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
self.layers().parts(rect.min, cx);
|
||||
@@ -383,8 +385,7 @@ impl<E: 'static> Component for NodeGraph<'_, E> {
|
||||
for wire in self.wires {
|
||||
let Some(points) = self.wire_curve(rect.min, wire) else { continue };
|
||||
let flags = if selected.is_some_and(|wires| wires.contains(&wire.id)) { Flags::SELECTED } else { Flags::empty() };
|
||||
|
||||
cx.part(WIRE.at(wire.id), HitShape::polyline(points, false))
|
||||
cx.in_body(WIRE.at(wire.id), HitShape::polyline(points, false))
|
||||
.sense(Sense::CLICK | Sense::DRAG | Sense::CONTEXT_CLICK)
|
||||
.priority(HitPriority::new(HitLevel::Edge, 0))
|
||||
.flags(flags)
|
||||
@@ -392,35 +393,35 @@ impl<E: 'static> Component for NodeGraph<'_, E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads each wire's press: it selects wires, and a double click, a secondary press and a primary press past the
|
||||
/// slop report `WireEvent`s. A plain primary press on a node or on empty space (the collection's own press)
|
||||
/// clears the wires. `Down` and `DragStart` come once per press, in the pass that applies that input, so a
|
||||
/// second pass in the frame selects and reports nothing again. Then the annotation layers read the pointer.
|
||||
/// Reads each wire's press, which reads in the rows' space: document units from the graph's top left. It selects
|
||||
/// wires, and a double click, a secondary press and a primary press past the slop report `WireEvent`s. A plain
|
||||
/// primary press on a node or on empty space (the collection's own press) clears the wires. `Down` and
|
||||
/// `DragStart` come once per press, in the pass that applies that input, so a second pass in the frame selects and
|
||||
/// reports nothing again. Then the annotation layers read the pointer.
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
let origin = cx.rect.min;
|
||||
let document = |at: Pos2| (at - origin).to_pos2();
|
||||
for wire in self.wires {
|
||||
let Some(press) = cx.part_if_declared(WIRE.at(wire.id)).map(|result| result.press) else { continue };
|
||||
match press.phase {
|
||||
PressPhase::Down { start, .. } => {
|
||||
if press.double_pressed() {
|
||||
let at = self.to_document(origin, start.origin);
|
||||
self.wire_events.push(WireEvent::DoubleClicked { wire: wire.id, at });
|
||||
self.wire_events.push(WireEvent::DoubleClicked { wire: wire.id, at: document(start.origin) });
|
||||
}
|
||||
if start.button == PointerButton::Secondary {
|
||||
self.wire_events.push(WireEvent::ContextMenu { wire: wire.id, at: start.origin });
|
||||
self.wire_events.push(WireEvent::ContextMenu { wire: wire.id, at: self.to_layer(origin, start.origin) });
|
||||
}
|
||||
if matches!(start.button, PointerButton::Primary | PointerButton::Secondary) {
|
||||
self.press_wire(cx, wire.id, press.mods, start.button == PointerButton::Secondary);
|
||||
}
|
||||
}
|
||||
PressPhase::DragStart { start, pos, .. } if start.button == PointerButton::Primary => {
|
||||
let at = self.to_document(origin, pos);
|
||||
self.wire_events.push(WireEvent::Pulled { wire: wire.id, at });
|
||||
self.wire_events.push(WireEvent::Pulled { wire: wire.id, at: document(pos) });
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let Some(at) = press.context {
|
||||
self.wire_events.push(WireEvent::ContextMenu { wire: wire.id, at });
|
||||
self.wire_events.push(WireEvent::ContextMenu { wire: wire.id, at: self.to_layer(origin, at) });
|
||||
}
|
||||
}
|
||||
let own = *cx.press();
|
||||
@@ -435,29 +436,13 @@ impl<E: 'static> Component for NodeGraph<'_, E> {
|
||||
self.annotation_events = layers.update(self.zoom, origin, cx, self.annotation_selection.as_mut(), self.selection.as_mut());
|
||||
}
|
||||
|
||||
/// The wires, under the nodes. A selected wire is its on look and a hovered one its hover look, both thick; a wire
|
||||
/// that only touches a selected node is `hot`; the wire a drag detaches is not drawn.
|
||||
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
let detached = cx.dragging::<WireDrag>().and_then(|(drag, _)| drag.detached);
|
||||
let selected = self.wire_selection.as_ref().and_then(Bind::value);
|
||||
let nodes = self.selection.as_ref().and_then(Bind::value);
|
||||
let draw = ui.draw();
|
||||
for wire in self.wires.iter().filter(|wire| Some(wire.id) != detached) {
|
||||
let Some(points) = self.wire_curve(cx.rect.min, wire) else { continue };
|
||||
let picked = selected.is_some_and(|wires| wires.contains(&wire.id));
|
||||
let hovered = cx.part(WIRE.at(wire.id)).hovered;
|
||||
let hot = !picked && !hovered && nodes.is_some_and(|nodes| nodes.contains(&wire.from.node) || nodes.contains(&wire.to.node));
|
||||
let width = if picked || hovered { StrokeWidth::Thick } else { StrokeWidth::Medium };
|
||||
let color = if hot { cx.style.hot } else { cx.resolve_part(WIRE.at(wire.id), &cx.style.wire) };
|
||||
draw.stroke(&PaintShape::Path(points), width, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// The loose wire from the port a drag started on to the pointer. Its free end enters by the side facing the start
|
||||
/// port's.
|
||||
/// The loose wire from the port a drag started on to the pointer, in the graph's layer. Its free end enters by the
|
||||
/// side facing the start port's.
|
||||
fn paint_over(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
let Some((wire, at)) = cx.dragging::<WireDrag>() else { return };
|
||||
if let (Some(from), Some(side)) = (self.port_point(cx.rect.min, wire.from), self.port_side(wire.from)) {
|
||||
let origin = cx.rect.min;
|
||||
let from = self.port_in_body(origin, wire.from).map(|port| self.to_layer(origin, port));
|
||||
if let (Some(from), Some(side)) = (from, self.port_side(wire.from)) {
|
||||
let points = sampled(wire_controls(from, side, at, opposite(side)));
|
||||
ui.draw().stroke(&PaintShape::Path(points), StrokeWidth::Medium, cx.style.loose);
|
||||
}
|
||||
@@ -497,9 +482,24 @@ impl<E: 'static> Collection for NodeGraph<'_, E> {
|
||||
node.in_graph(fed, self.port_labels).placed(place)
|
||||
}
|
||||
|
||||
/// The backdrops, under the nodes and through the zoom with them.
|
||||
/// The backdrops, then the wires over them, under the nodes and through the zoom with them. A selected wire is its
|
||||
/// on look and a hovered one its hover look, both thick; a wire that only touches a selected node is `hot`; the wire
|
||||
/// a drag detaches is not drawn.
|
||||
fn paint_body_under(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
self.layers().paint_under(cx.rect.min, ui, cx);
|
||||
let detached = cx.dragging::<WireDrag>().and_then(|(drag, _)| drag.detached);
|
||||
let selected = self.wire_selection.as_ref().and_then(Bind::value);
|
||||
let nodes = self.selection.as_ref().and_then(Bind::value);
|
||||
let draw = ui.draw();
|
||||
for wire in self.wires.iter().filter(|wire| Some(wire.id) != detached) {
|
||||
let Some(points) = self.wire_curve(cx.rect.min, wire) else { continue };
|
||||
let picked = selected.is_some_and(|wires| wires.contains(&wire.id));
|
||||
let hovered = cx.part(WIRE.at(wire.id)).hovered;
|
||||
let hot = !picked && !hovered && nodes.is_some_and(|nodes| nodes.contains(&wire.from.node) || nodes.contains(&wire.to.node));
|
||||
let width = if picked || hovered { StrokeWidth::Thick } else { StrokeWidth::Medium };
|
||||
let color = if hot { cx.style.hot } else { cx.resolve_part(WIRE.at(wire.id), &cx.style.wire) };
|
||||
draw.stroke(&PaintShape::Path(points), width, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// The notes and markers, over the nodes and through the zoom with them.
|
||||
|
||||
@@ -323,7 +323,8 @@ impl<E: 'static> Component for Node<'_, E> {
|
||||
let press = cx.part(PORT.at(port as u64)).press;
|
||||
if matches!(press.phase, PressPhase::DragStart { .. }) {
|
||||
cx.start_drag(self.wire_from(port), DragPreview::None);
|
||||
} else if primary_click(&press) {
|
||||
} else if primary_click(&press) || matches!(cx.part_activated(PORT.at(port as u64)), Some(crate::runtime::commands::FireSource::Access)) {
|
||||
// An assistive technology's click is a primary click with no modifiers.
|
||||
self.event = Some(NodeEvent::Clicked { port: Some(port), mods: press.mods });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +402,9 @@ fn release_loose(fixture: &mut Fixture) {
|
||||
fixture.drag_at(output.center(), Vec2::new(0.0, 40.0));
|
||||
fixture.drag_at(output.center(), input.center() - output.center());
|
||||
let after = fixture.data().note("loose", Vec::<Pos2>::new()).len();
|
||||
assert!(after >= before + 2, "a release on empty canvas and one on a refused port each report a loose end");
|
||||
// A disabled graph starts no wire, which the disabled case checks.
|
||||
let disabled = fixture.tree().is_disabled_key(output.node);
|
||||
assert!(after >= before + 2 || disabled, "a release on empty canvas and one on a refused port each report a loose end");
|
||||
}
|
||||
|
||||
#[story(NodeGraph<'static, ()>, covers = [Many], drive = Drive::Custom(release_loose))]
|
||||
|
||||
@@ -207,3 +207,62 @@ fn a_backdrop_drag_and_grip_drag_report_one_gesture_each() {
|
||||
assert_eq!(menus.len(), 1, "a secondary click asks for the backdrop's menu once");
|
||||
assert!(menus[0].distance(from) < 0.5, "the menu opens at the click in the parent's layer space, not through the zoom");
|
||||
}
|
||||
|
||||
/// A node with an input on its left edge and an output on its right, at mid height.
|
||||
struct Ported(&'static str, [&'static str; 2]);
|
||||
|
||||
impl NodeKind<()> for Ported {
|
||||
fn title(&self) -> &str {
|
||||
self.0
|
||||
}
|
||||
|
||||
fn port_count(&self) -> usize {
|
||||
2
|
||||
}
|
||||
|
||||
fn port_name(&self, port: usize) -> String {
|
||||
self.1[port].to_owned()
|
||||
}
|
||||
|
||||
fn port_offset(&self, port: usize, size: Vec2) -> Vec2 {
|
||||
Vec2::new(if port == 0 { 0.0 } else { size.x }, size.y / 2.0)
|
||||
}
|
||||
|
||||
fn port_direction(&self, port: usize) -> craft_ui::graph::PortDirection {
|
||||
if port == 0 { craft_ui::graph::PortDirection::Input } else { craft_ui::graph::PortDirection::Output }
|
||||
}
|
||||
}
|
||||
|
||||
/// q133: the wires lie in the body over the backdrops, through the zoom with the nodes: a press on a wire where it
|
||||
/// crosses a backdrop takes the wire, not the backdrop.
|
||||
#[trial]
|
||||
fn a_press_on_a_wire_inside_a_backdrop_takes_the_wire_at_a_zoom() {
|
||||
use craft_ui::graph::{PortRef, Wire};
|
||||
let (wired, annotation) = (Rc::new(RefCell::new(Selection::<u64>::default())), Rc::new(RefCell::new(None::<AnnotationKey>)));
|
||||
let (wired_in, annotation_in) = (Rc::clone(&wired), Rc::clone(&annotation));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let (a, b) = (Ported("A", ["A in", "A out"]), Ported("B", ["B in", "B out"]));
|
||||
let kinds: [&dyn NodeKind<()>; 2] = [&a, &b];
|
||||
let ids = [NodeId::new(0), NodeId::new(1)];
|
||||
let source = keyed(&ids, |id: &NodeId| *id);
|
||||
let wires = [Wire::new(9, PortRef::new(NodeId::new(0), 1), PortRef::new(NodeId::new(1), 0))];
|
||||
// Around both nodes, so the wire between them crosses it.
|
||||
let around = Rect::from_min_max(Pos2::new(20.0, 20.0), Pos2::new(400.0, 160.0));
|
||||
let backdrops = [Backdrop::new(0, around, DataColor::new(Color32::from_rgba_premultiplied(40, 80, 48, 96))).title("Group")];
|
||||
let (mut wired, mut annotation) = (wired_in.borrow_mut(), annotation_in.borrow_mut());
|
||||
let _ = NodeGraph::new(&NODES, &kinds, &wires)
|
||||
.label("Graph")
|
||||
.zoom(CanvasTransform::new(2.0, Vec2::ZERO))
|
||||
.backdrops(&backdrops)
|
||||
.wire_selection(Bind::bound(&mut *wired))
|
||||
.annotation_selection(Bind::bound(&mut *annotation))
|
||||
.show_items(ui, &source, &mut |id, _| Node::new(*id, kinds[id.0 as usize]));
|
||||
});
|
||||
fixture.room(Vec2::new(900.0, 400.0)).settle();
|
||||
// The wire runs level between ports at one height, so its middle lies halfway between them.
|
||||
let middle = rect_of(&fixture, "A out").center().lerp(rect_of(&fixture, "B in").center(), 0.5);
|
||||
assert!(rect_of(&fixture, "Group").contains(middle), "the trial presses the wire inside the backdrop");
|
||||
fixture.click_at(middle);
|
||||
assert_eq!(wired.borrow().items, [9], "the press takes the wire over the backdrop");
|
||||
assert_eq!(*annotation.borrow(), None, "and not the backdrop under it");
|
||||
}
|
||||
Reference in new issue
Block a user