wayver's git archive


an obsidian renderer
git clone https://git.wayver.dev/sable

sable-canvas/src/node/file.rs@main

raw
Date Commit Message Author Files + -
2026-02-23 01:55 initial mvp wayverd 139 17808 0
...

1use std::path::PathBuf;
2
3use crate::{
4    NodeId, PixelCoordinate, PixelDimension,
5    color::Color,
6    node::{GenericNode, GenericNodeInfo},
7};
8
9/// A file node.
10#[derive(
11    Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
12)]
13pub struct FileNode {
14    #[serde(flatten)]
15    generic: GenericNode,
16    file: PathBuf,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    subpath: Option<String>,
19}
20
21impl FileNode {
22    /// Creates a new [`FileNode`].
23    #[allow(clippy::too_many_arguments)]
24    #[must_use]
25    pub const fn new(
26        id: NodeId,
27        x: PixelCoordinate,
28        y: PixelCoordinate,
29        width: PixelDimension,
30        height: PixelDimension,
31        color: Option<Color>,
32        file: PathBuf,
33        subpath: Option<String>,
34    ) -> Self {
35        Self {
36            generic: GenericNode::new(id, x, y, width, height, color),
37            file,
38            subpath,
39        }
40    }
41
42    /// Returns a reference to the file of this [`FileNode`].
43    #[must_use]
44    pub const fn file(&self) -> &PathBuf {
45        &self.file
46    }
47
48    /// Returns the subpath of this [`FileNode`].
49    #[must_use]
50    pub const fn subpath(&self) -> Option<&String> {
51        self.subpath.as_ref()
52    }
53}
54
55impl GenericNodeInfo for FileNode {
56    fn id(&self) -> &NodeId {
57        self.generic.id()
58    }
59
60    fn x(&self) -> PixelCoordinate {
61        self.generic.x()
62    }
63
64    fn y(&self) -> PixelCoordinate {
65        self.generic.y()
66    }
67
68    fn width(&self) -> PixelDimension {
69        self.generic.width()
70    }
71
72    fn height(&self) -> PixelDimension {
73        self.generic.height()
74    }
75
76    fn color(&self) -> &Option<Color> {
77        self.generic.color()
78    }
79}
80