sable-canvas/src/node/text.rs@main
raw
1use crate::{
2 NodeId, PixelCoordinate, PixelDimension,
3 color::Color,
4 node::{GenericNode, GenericNodeInfo},
5};
6
7#[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 #[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 #[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