gled-ui 2.31.1

gled's egui interface, shared by the desktop app and the browser
Documentation
//! 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,
        }
    }
}