-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.rs
69 lines (58 loc) · 1.63 KB
/
node.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use std::sync::atomic::{AtomicU32, Ordering};
use anyhow::Result;
use rusvid_core::pixel::Pixel;
use rusvid_core::plane::Plane;
use crate::bitmap::BitmapChar;
use crate::coordinate::Coordinate;
use crate::input_output_value::InputOutputValue;
use crate::utils::render_square;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SpaceInfo {
pub position: (i64, i64),
pub size: (u32, u32),
pub color: Pixel,
pub name: String,
pub z_index: usize,
}
impl Default for SpaceInfo {
fn default() -> Self {
static COUNTER: AtomicU32 = AtomicU32::new(0);
Self {
position: (100, 100),
size: (100, 100),
color: Pixel::new(255, 100, 0, 255),
name: format!("node_{}", COUNTER.fetch_add(1, Ordering::Relaxed)),
z_index: 0,
}
}
}
pub trait Node: std::fmt::Debug {
fn generate(
&self,
position: &Coordinate,
size: &(u32, u32),
input: InputOutputValue,
) -> Result<InputOutputValue>;
fn is_output(&self) -> bool {
false
}
fn render(&self, plane: &mut Plane) -> Result<()> {
let space_info = self.space_info();
render_square(
plane,
space_info.position,
space_info.size,
space_info.color,
)?;
BitmapChar::render_multiple_with_scale(
plane,
(space_info.position.0, space_info.position.1 + 5),
&space_info.name,
Pixel::new(0, 0, 0, 255),
2,
)?;
Ok(())
}
fn space_info(&self) -> &SpaceInfo;
fn space_info_mut(&mut self) -> &mut SpaceInfo;
}