pub struct NodeGraph<'a> { /* private fields */ }Implementations§
Source§impl<'a> NodeGraph<'a>
impl<'a> NodeGraph<'a>
pub fn new( nodes: Vec<NodeLayout<'a>>, connections: Vec<Connection<'a>>, width: usize, height: usize, ) -> Self
Sourcepub fn with_direction(self, direction: FlowDirection) -> Self
pub fn with_direction(self, direction: FlowDirection) -> Self
Set the graph’s FlowDirection (which edge the root anchors to and
which way children flow). The graph is marked dirty; call
calculate before reading positions.
Defaults to FlowDirection::Rtl (the original hard-coded behavior).
Sourcepub fn direction(&self) -> FlowDirection
pub fn direction(&self) -> FlowDirection
The graph’s configured FlowDirection.
Sourcepub fn highlight_style(self, style: Style) -> Self
pub fn highlight_style(self, style: Style) -> Self
Set the highlight Style applied to the selected node’s border
during stateful render (see FlowState::selection). The hover
node’s border gets this style with an added Modifier::DIM so the two
states stay visually distinct. Defaults to bold yellow foreground.
Only the border is recolored (the port glyphs on the border keep their symbols and pick up the highlight’s fg/modifier); node content is never touched.
Sourcepub fn show_arrows(self, on: bool) -> Self
pub fn show_arrows(self, on: bool) -> Self
Toggle drawing a direction arrow on each connection’s to (in) port,
pointing in the flow direction (e.g. ◄ for Rtl, ▶ for Ltr, ▼
for Ttb). Off by default — pass true to replace the in-port
connection glyph (┤/┴ family) with an arrow so the flow direction
reads at a glance. The from (out) port always keeps its ├/┬ glyph.
Sourcepub fn add_node(&mut self, node: NodeLayout<'a>) -> NodeId
pub fn add_node(&mut self, node: NodeLayout<'a>) -> NodeId
Sourcepub fn add_node_with_id(
&mut self,
id: NodeId,
node: NodeLayout<'a>,
) -> Result<(), AddNodeError>
pub fn add_node_with_id( &mut self, id: NodeId, node: NodeLayout<'a>, ) -> Result<(), AddNodeError>
Append a node with a caller-chosen NodeId. Returns
AddNodeError::ConflictingId if id is already in use; otherwise the
node is inserted (preserving render order) and the graph is marked dirty.
The id need not be contiguous — this is the path used to support
non-contiguous node ids. The auto-increment counter is bumped past id
only if id would otherwise collide with a future add_node result.
Sourcepub fn add_connection(&mut self, conn: Connection<'a>)
pub fn add_connection(&mut self, conn: Connection<'a>)
Append a Connection. The graph is marked dirty.
Sourcepub fn remove_node(&mut self, id: NodeId) -> bool
pub fn remove_node(&mut self, id: NodeId) -> bool
Remove the node with the given NodeId and cascade-delete every
Connection that references it (on either endpoint). No-op (returns
false) if id is not in the graph. The graph is marked dirty.
Returns true if a node was actually removed.
Sourcepub fn remove_connection(
&mut self,
from: NodeId,
from_port: PortId,
to: NodeId,
to_port: PortId,
) -> bool
pub fn remove_connection( &mut self, from: NodeId, from_port: PortId, to: NodeId, to_port: PortId, ) -> bool
Remove the first Connection matching the given endpoints. No-op
(returns false) if no such connection exists. The graph is marked dirty.
Returns true if a connection was removed.
Sourcepub fn has_node(&self, id: NodeId) -> bool
pub fn has_node(&self, id: NodeId) -> bool
true if a node with the given NodeId exists in the graph.
Sourcepub fn node_rect(&self, id: NodeId) -> Option<Rect>
pub fn node_rect(&self, id: NodeId) -> Option<Rect>
The full-frame Rect (border included, canvas coordinates) of a
single node, or None if the node was not placed (unreachable / unknown
/ never calculated).
pub fn calculate(&mut self)
Sourcepub fn diagnostics(&self) -> &[Diagnostic]
pub fn diagnostics(&self) -> &[Diagnostic]
Non-fatal problems detected during the most recent
calculate: unreachable (unplaced) nodes, ignored
out-of-bounds connections, and connections that couldn’t be routed.
The slice is cleared at the start of each calculate, so it always
reflects the latest run. Each entry is also emitted via log::warn!.
pub fn split(&self, area: Rect) -> Vec<Rect>
Sourcepub fn hit_test(&self, area: Rect, x: u16, y: u16) -> Option<NodeId>
pub fn hit_test(&self, area: Rect, x: u16, y: u16) -> Option<NodeId>
Hit-test a screen coordinate against the placed nodes and return the
NodeId of the node whose full frame (border included) contains
(x, y), or None if the point falls in empty space or on a node that
was never placed.
(x, y) is interpreted relative to area’s top-left corner (i.e. they
are screen coordinates within area), exactly like the rects returned by
split / split_named. The hit area
is each node’s bordered rect (a point on the border counts as a hit),
matching the granularity used by the off-screen canvas — so the inner
content rects from split_named are strictly contained in the hit rects.
Must be called after calculate; before that,
positions is empty and hit_test always returns
None. The transformation honors direction (the same
canvas→screen mirror as split_named), so hit testing is correct for
Ltr/Rtl/Ttb/Btt.
Nodes never overlap in canvas space, so at most one node can contain a
given point; the first match (in render order) is returned. Viewport
offset is not applied here — for a scrolled graph use the upcoming
hit_test_viewport (Step 6), or pre-translate (x, y) by the offset.
Sourcepub fn split_viewport(&self, area: Rect, viewport: &Viewport) -> Vec<Rect>
👎Deprecated since 0.1.0: use split_stateful(area, &FlowState) with a FlowState whose view_offset is set
pub fn split_viewport(&self, area: Rect, viewport: &Viewport) -> Vec<Rect>
use split_stateful(area, &FlowState) with a FlowState whose view_offset is set
Like split, but returns each node’s content rect in
screen coordinates for a scrolled viewport.
Each rect is the node’s canvas-rect (mirrored, inner border removed),
translated by -viewport.offset + area.origin, then clipped to area.
A node fully scrolled off-screen yields a 0×0 rect (render it only when
width > 0 && height > 0).
Typical per-frame usage:
let zones = graph.split_viewport(view_area, &viewport);
for (i, z) in zones.iter().enumerate() {
if z.width > 0 && z.height > 0 {
f.render_widget(my_content[i], *z);
}
}
f.render_widget(NodeGraphView::new(&graph).viewport(viewport), view_area);Sourcepub fn split_stateful(
&self,
area: Rect,
state: &FlowState,
) -> Vec<(NodeId, Rect)>
pub fn split_stateful( &self, area: Rect, state: &FlowState, ) -> Vec<(NodeId, Rect)>
Like split_named, but each content rect is
translated by state.view_offset and clipped to area — i.e. it returns
the screen-coordinate content rects for a scrolled/panned view driven by
a FlowState.
This is the stateful-path counterpart of
split_viewport: it yields (NodeId, Rect)
pairs (so the caller can route content to the right node), and the rect
math is identical — each node’s canvas-rect (mirrored, inner border
removed) is shifted by -view_offset + area.origin and clipped to area.
A node fully scrolled off-screen yields a 0×0 rect (render it only when
width > 0 && height > 0).
Typical per-frame usage with the stateful render path:
let zones = graph.split_stateful(view_area, &flow_state);
for (id, z) in &zones {
if z.width > 0 && z.height > 0 {
f.render_widget(my_content_for(id), *z);
}
}
f.render_stateful_widget(graph, view_area, &mut flow_state);Trait Implementations§
Source§impl<'a> StatefulWidget for NodeGraph<'a>
impl<'a> StatefulWidget for NodeGraph<'a>
Auto Trait Implementations§
impl<'a> Freeze for NodeGraph<'a>
impl<'a> RefUnwindSafe for NodeGraph<'a>
impl<'a> Send for NodeGraph<'a>
impl<'a> Sync for NodeGraph<'a>
impl<'a> Unpin for NodeGraph<'a>
impl<'a> UnsafeUnpin for NodeGraph<'a>
impl<'a> UnwindSafe for NodeGraph<'a>
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