wayver's git archive


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

sable-canvas/src/node/text.rs@2b84405277e54ab809e328cf0237374d4b4dbd0c

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

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