tui_nodes/
node.rs

1use ratatui::{
2	style::Style,
3	widgets::{Block, BorderType, Borders},
4};
5
6/// Render information for a single node
7#[derive(Debug)]
8pub struct NodeLayout<'a> {
9	// minimum size of contents (TODO: doc: including borders?)
10	pub size: (u16, u16),
11	border_type: BorderType,
12	title: &'a str,
13	border_style: Style,
14	//	in_ports: Vec<PortLayout>,
15	//	out_ports: Vec<PortLayout>,
16}
17
18impl<'a> NodeLayout<'a> {
19	pub fn new(size: (u16, u16)) -> Self {
20		Self {
21			size,
22			border_type: BorderType::Plain,
23			title: "",
24			border_style: Style::default(),
25		}
26	}
27
28	pub fn with_title(mut self, title: &'a str) -> Self {
29		self.title = title;
30		self
31	}
32
33	pub fn title(&self) -> &str {
34		self.title
35	}
36
37	pub fn with_border_type(mut self, border: BorderType) -> Self {
38		self.border_type = border;
39		self
40	}
41
42	pub fn border_type(&self) -> BorderType {
43		self.border_type
44	}
45
46	pub fn with_border_style(mut self, style: Style) -> Self {
47		self.border_style = style;
48		self
49	}
50
51	pub fn block(&self) -> Block {
52		Block::default()
53			.borders(Borders::ALL)
54			.border_type(self.border_type)
55			.border_style(self.border_style)
56			.title(self.title)
57	}
58}