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
16
src/main.rs
16
src/main.rs
|
|
@ -1,17 +1,17 @@
|
|||
mod node;
|
||||
mod socket;
|
||||
|
||||
use iced::{Element, Point};
|
||||
use node::Node;
|
||||
use iced::{Element};
|
||||
|
||||
use crate::node::{NodeMessage, Nodes};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct State {
|
||||
nodes: Vec<Node>
|
||||
nodes: Nodes
|
||||
}
|
||||
|
||||
pub enum Message {
|
||||
MoveNode(usize, Point),
|
||||
SocketDragStart,
|
||||
SocketDragEnd,
|
||||
NodeMessage(NodeMessage)
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
|
@ -19,7 +19,9 @@ impl State {
|
|||
todo!();
|
||||
}
|
||||
pub fn update(&mut self, message: Message) {
|
||||
todo!();
|
||||
match message {
|
||||
Message::NodeMessage(message) => self.nodes.update(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
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!();
|
||||
}
|
||||
|
|
|
|||
15
src/socket.rs
Normal file
15
src/socket.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
pub struct Socket {
|
||||
pub name: Option<String>,
|
||||
pub kind: SocketType,
|
||||
pub data: SocketData
|
||||
}
|
||||
|
||||
pub enum SocketType {
|
||||
Input,
|
||||
Output,
|
||||
}
|
||||
|
||||
pub enum SocketData {
|
||||
F32(f32)
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue