refactor: split node and socket, delegated node updating and view to Nodes struct
This commit is contained in:
parent
d327311719
commit
7de9ce4a5e
3 changed files with 47 additions and 24 deletions
46
src/node.rs
46
src/node.rs
|
|
@ -1,30 +1,36 @@
|
|||
use iced::{Element, Point};
|
||||
|
||||
use crate::Message;
|
||||
use crate::socket::{Socket,SocketData};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Nodes {
|
||||
pub nodes: Vec<Node>,
|
||||
pub sockets: Vec<Socket>
|
||||
}
|
||||
|
||||
impl Nodes {
|
||||
pub fn update(&mut self, message: NodeMessage) {
|
||||
todo!();
|
||||
}
|
||||
pub fn view(&self) -> Element<'_, crate::Message> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
pub enum NodeMessage {
|
||||
MoveNode(usize, Point),
|
||||
SocketDragStart(usize),
|
||||
SocketDragEnd(usize),
|
||||
}
|
||||
|
||||
pub struct Node {
|
||||
pub name: String,
|
||||
pub inputs: Vec<Socket>,
|
||||
pub outputs: Vec<Socket>,
|
||||
pub inputs: Vec<usize>,
|
||||
pub outputs: Vec<usize>,
|
||||
pub position: Point,
|
||||
pub function: Box<dyn Fn([&Socket]) -> Vec<Socket>>
|
||||
pub function: Box<dyn Fn([&SocketData]) -> Vec<SocketData>>
|
||||
}
|
||||
|
||||
pub struct Socket {
|
||||
name: Option<String>,
|
||||
kind: SocketType,
|
||||
data: SocketData
|
||||
}
|
||||
|
||||
pub enum SocketType {
|
||||
Input,
|
||||
Output,
|
||||
}
|
||||
|
||||
pub enum SocketData {
|
||||
F32(f32)
|
||||
}
|
||||
|
||||
pub fn node(from: &Node, node_index: usize) -> Element<'_,Message> {
|
||||
pub fn node(from: &Node, node_index: usize) -> Element<'_,crate::Message> {
|
||||
todo!();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue