Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }

Implementations§

Source§

impl Graph

Source

pub fn copy_nodes(&self, ids: &[NodeId]) -> Clip

复制节点及其子树;只保留两端都在片段内的边。片段根节点的 parent 被清空。

Source

pub fn paste_op(&mut self, clip: &Clip, offset: Vec2) -> (GraphOp, Vec<NodeId>)

生成粘贴操作:所有 ID 重新分配,根节点平移 offset。返回操作与新的根节点 ID。

Source§

impl Graph

Source

pub fn new() -> Self

Source

pub fn alloc_node_id(&mut self) -> NodeId

Source

pub fn alloc_port_id(&mut self) -> PortId

Source

pub fn alloc_edge_id(&mut self) -> EdgeId

Source

pub fn revision(&self) -> u64

每次修改递增;视图层据此判断缓存(可见集合、空间索引)是否失效。

Source

pub fn node(&self, id: NodeId) -> Option<&Node>

Source

pub fn port(&self, id: PortId) -> Option<&Port>

Source

pub fn edge(&self, id: EdgeId) -> Option<&Edge>

Source

pub fn node_count(&self) -> usize

Source

pub fn edge_count(&self) -> usize

Source

pub fn nodes(&self) -> impl Iterator<Item = &Node>

按绘制顺序遍历节点。

Source

pub fn node_ids(&self) -> &[NodeId]

Source

pub fn edges(&self) -> impl Iterator<Item = &Edge>

Source

pub fn ports_of(&self, node: NodeId) -> impl Iterator<Item = &Port>

Source

pub fn edges_of_port(&self, port: PortId) -> &[EdgeId]

Source

pub fn connected_edges(&self, node: NodeId) -> Vec<EdgeId>

与节点相连的所有边(gpui-flow get_connected_edges)。

Source

pub fn incomers(&self, node: NodeId) -> Vec<NodeId>

上游节点(gpui-flow get_incomers)。

Source

pub fn outgoers(&self, node: NodeId) -> Vec<NodeId>

下游节点(gpui-flow get_outgoers)。

Source

pub fn edge_nodes(&self, edge: &Edge) -> Option<(NodeId, NodeId)>

边的 (源节点, 目标节点)。

Source

pub fn children_of(&self, parent: NodeId) -> &[NodeId]

Source

pub fn subtree(&self, root: NodeId) -> Vec<NodeId>

节点及其全部后代(先序)。

Source

pub fn is_ancestor(&self, ancestor: NodeId, node: NodeId) -> bool

Source

pub fn world_pos(&self, id: NodeId) -> Option<Vec2>

节点左上角的世界坐标(累加父链的局部坐标)。

Source

pub fn world_rect(&self, id: NodeId) -> Option<Rect>

Source

pub fn to_local(&self, world: Vec2, parent: Option<NodeId>) -> Option<Vec2>

世界坐标换算到 parent 的局部坐标。

Source

pub fn bounds(&self) -> Option<Rect>

所有节点的世界包围盒(fit view 用)。

Source

pub fn nodes_in_rect(&self, rect: &Rect, fully: bool) -> Vec<NodeId>

与矩形相交(fully = false)或被完全包含(fully = true)的节点,按绘制顺序。

Source

pub fn node_at(&self, p: Vec2) -> Option<NodeId>

自顶向下命中最上层节点。

Source

pub fn topo_order(&self) -> Result<Vec<NodeId>, NodeId>

节点级拓扑序;有环时返回参与环的任一节点。

Source

pub fn has_cycle(&self) -> bool

Source

pub fn would_create_cycle(&self, from: NodeId, to: NodeId) -> bool

新增 from → to 是否会成环(to 能否到达 from)。

Source

pub fn set_status(&mut self, id: NodeId, status: NodeStatus) -> bool

运行状态不进入撤销历史。

Source

pub fn set_edge_state(&mut self, id: EdgeId, state: EdgeState) -> bool

Source

pub fn bring_to_front(&mut self, id: NodeId)

置顶(含子树,保证子节点仍画在父节点之上)。

Source

pub fn add_node_with( &mut self, kind: &str, pos: Vec2, size: Size2, inputs: usize, outputs: usize, ) -> (NodeId, Vec<PortId>, Vec<PortId>)

创建一个节点(不进历史,适合初始化)。返回节点 ID 与 (输入端口, 输出端口)。

Source

pub fn connect( &mut self, from: PortId, to: PortId, ) -> Result<EdgeId, GraphError>

直接连线(不校验、不进历史,适合初始化)。

Source

pub fn to_json(&self) -> Value

Source

pub fn from_json(value: Value) -> Result<Self, GraphError>

Source§

impl Graph

Source

pub fn apply(&mut self, op: GraphOp) -> Result<GraphOp, GraphError>

应用操作并返回逆操作。Batch 为原子操作:中途失败会回滚已应用的部分。

Source

pub fn delete_ops(&self, nodes: &[NodeId], edges: &[EdgeId]) -> GraphOp

删除节点(含全部后代)与边的级联操作:先删边,再自叶向根删节点。

Source

pub fn reparent_op(&self, id: NodeId, parent: Option<NodeId>) -> Option<GraphOp>

将节点移入 / 移出分组,保持其世界坐标不变。

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Graph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for Graph

§

impl Freeze for Graph

§

impl Move for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph
where RawTable<(NodeId, Node)>: Send, RawTable<(PortId, Port)>: Send, RawTable<(EdgeId, Edge)>: Send, RawVecInner: Send, RawTable<(PortId, Vec<EdgeId>)>: Send, RawTable<(NodeId, Vec<NodeId>)>: Send,

§

impl Sync for Graph
where RawTable<(NodeId, Node)>: Sync, RawTable<(PortId, Port)>: Sync, RawTable<(EdgeId, Edge)>: Sync, RawVecInner: Sync, RawTable<(PortId, Vec<EdgeId>)>: Sync, RawTable<(NodeId, Vec<NodeId>)>: Sync,

§

impl Unpin for Graph
where *const u8 is !null: Unpin, Arc<str>: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Box<PortType>: Unpin,

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.