easyofd_core/model/
text_object.rs1#[derive(Debug, Clone)]
5pub struct TextObject {
6 pub x: f64,
8 pub y: f64,
10 pub font: String,
12 pub size: f64,
14 pub weight: u32,
16 pub italic: bool,
18 pub color: u32,
20 pub text: String,
22 pub width: Option<f64>,
25 pub height: Option<f64>,
28}
29
30impl TextObject {
31 #[must_use]
33 pub fn new(x: f64, y: f64, text: impl Into<String>) -> Self {
34 Self {
35 x,
36 y,
37 font: "SimSun".to_string(),
38 size: 12.0,
39 weight: 400,
40 italic: false,
41 color: 0x000_000,
42 text: text.into(),
43 width: None,
44 height: None,
45 }
46 }
47
48 #[must_use]
50 pub fn font(mut self, font: impl Into<String>) -> Self {
51 self.font = font.into();
52 self
53 }
54
55 #[must_use]
57 pub fn size(mut self, size: f64) -> Self {
58 self.size = size;
59 self
60 }
61
62 #[must_use]
64 pub fn bold(mut self) -> Self {
65 self.weight = 700;
66 self
67 }
68
69 #[must_use]
71 pub fn italic(mut self) -> Self {
72 self.italic = true;
73 self
74 }
75
76 #[must_use]
78 pub fn color(mut self, color: u32) -> Self {
79 self.color = color;
80 self
81 }
82}