pub struct EditorHandle { /* private fields */ }Expand description
A consumer-side handle to a NodeEditor instance.
The editor provides its registry via context, which flows DOWN — so a handler
mounted on an ancestor of the editor (an HTML5 drop target wrapping the graph,
a toolbar, a sibling pane) has no way to reach the live pan/zoom transform.
Construct a handle, pass it to NodeEditor, and it works from anywhere:
let handle = EditorHandle::new();
view! {
<div
on:dragover=|ev: web_sys::DragEvent| ev.prevent_default()
on:drop=move |ev: web_sys::DragEvent| {
ev.prevent_default();
if let Some(pos) = handle.client_to_canvas(ev.client_x() as f64, ev.client_y() as f64) {
// `pos` is in canvas space, correct under any pan/zoom.
}
}
>
<NodeEditor handle=handle ...>...</NodeEditor>
</div>
}Prefer this over reading the canvas element’s CSS transform: the class names and the transform’s representation are internal and may change, whereas this is the supported surface.
Implementations§
Source§impl EditorHandle
impl EditorHandle
pub fn new() -> Self
Sourcepub fn viewport(&self) -> RwSignal<ViewportTransform>
pub fn viewport(&self) -> RwSignal<ViewportTransform>
The editor’s live pan/zoom transform. Reading this in a reactive context subscribes to it, so it also drives consumer-side minimaps, zoom readouts and “frame the graph” controls.
When this handle is passed to a NodeEditor, the editor uses THIS
signal as its own — writing to it pans/zooms the graph.
Sourcepub fn client_to_canvas(&self, client_x: f64, client_y: f64) -> Option<Position>
pub fn client_to_canvas(&self, client_x: f64, client_y: f64) -> Option<Position>
Convert viewport client coordinates — MouseEvent/DragEvent client_x
and client_y — into canvas coordinates.
This subtracts the container’s own offset before applying the transform, which is the step that’s easy to miss: any padding, border or chrome between the event’s target and the editor’s container shifts the result, and the error only shows up once the layout gains that spacing.
None before the editor has mounted. Reads are untracked, so this is safe
to call from event handlers without creating a subscription.
Sourcepub fn canvas_to_client(&self, canvas: Position) -> Option<Position>
pub fn canvas_to_client(&self, canvas: Position) -> Option<Position>
Inverse of Self::client_to_canvas: canvas coordinates to viewport
client coordinates, for placing consumer-owned DOM over a graph position.
Trait Implementations§
Source§impl Clone for EditorHandle
impl Clone for EditorHandle
impl Copy for EditorHandle
Source§impl Debug for EditorHandle
impl Debug for EditorHandle
Auto Trait Implementations§
impl Freeze for EditorHandle
impl RefUnwindSafe for EditorHandle
impl Send for EditorHandle
impl Sync for EditorHandle
impl Unpin for EditorHandle
impl UnsafeUnpin for EditorHandle
impl UnwindSafe for EditorHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more