1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! What the pointer did to one fixture on the patch canvas this frame.
use crate::canvas::rotated_rect::RotatedRect;
use crate::fixture_editor::drag::FixtureEnd;
use crate::fixture_editor::fixtures::FloatingConnection;
use std::sync::Arc;
#[derive(Default)]
pub(crate) struct NodeResponse {
/// The canvas is dragged by a press on this fixture.
pub(crate) dragged: bool,
pub(crate) clicked: bool,
/// The fixture as it is outlined on screen, while the pointer is over it.
pub(crate) hovered: Option<RotatedRect>,
/// A connection dropped onto the fixture.
pub(crate) released_payload: Option<Arc<FloatingConnection>>,
/// A connection held over the fixture, and the fixture's outline on
/// screen.
pub(crate) hover_payload: Option<(RotatedRect, Arc<FloatingConnection>)>,
pub(crate) has_unhandled_pointer_down: bool,
/// The chain's network output was clicked, not the fixture.
pub(crate) network_clicked: bool,
/// A drag started on the handle at this end of the fixture.
pub(crate) end_drag: Option<FixtureEnd>,
}
impl NodeResponse {
/// `response` is the canvas as a whole — fixtures are hit-tested by hand —
/// so anything that is about the pointer being over *this* fixture has to
/// be gated on `hovering`. Without that gate a dragged connection lit up
/// every fixture the draw loop touched, not the one under the cursor.
/// Likewise a drag is this fixture's only when it was `pressed` on it:
/// without that, a rubber band pulled onto a fixture moved it.
pub(crate) fn from_response(
response: &egui::Response,
rect: &RotatedRect,
has_unhandled_pointer_down: bool,
hovering: bool,
pressed: bool,
) -> Self {
NodeResponse {
dragged: pressed && response.dragged(),
clicked: response.clicked(),
hovered: (hovering && response.hovered()).then_some(*rect),
has_unhandled_pointer_down,
released_payload: hovering
.then(|| response.dnd_release_payload::<FloatingConnection>())
.flatten(),
hover_payload: hovering
.then(|| response.dnd_hover_payload::<FloatingConnection>())
.flatten()
.map(|x| (*rect, x)),
network_clicked: false,
end_drag: None,
}
}
}