cotis_layout/layout_struct/
text_draw_payload.rs1use cotis_defaults::element_configs::text_config::{TextConfig, TextStyle};
2use std::ops::Range;
3use std::sync::Arc;
4
5#[derive(Clone, Debug)]
13#[cfg_attr(
14 feature = "serialization",
15 derive(serde::Serialize, serde::Deserialize)
16)]
17pub struct TextDrawPayload {
18 #[cfg(not(feature = "serialization"))]
19 source: Arc<str>,
20 #[cfg(feature = "serialization")]
21 source: String,
22 range: Range<usize>,
23 pub config: TextConfig,
25 pub style: TextStyle,
27}
28
29#[cfg(not(feature = "serialization"))]
30impl TextDrawPayload {
31 pub fn new_from_arc(
33 source: &Arc<str>,
34 range: Range<usize>,
35 config: TextConfig,
36 style: TextStyle,
37 ) -> Self {
38 Self {
39 source: source.clone(),
40 range,
41 config,
42 style,
43 }
44 }
45
46 pub fn get_str(&self) -> &str {
48 &self.source[self.range.clone()]
49 }
50}
51
52#[cfg(feature = "serialization")]
53impl TextDrawPayload {
54 pub fn new_from_arc(
56 source: &Arc<str>,
57 range: Range<usize>,
58 config: TextConfig,
59 style: TextStyle,
60 ) -> Self {
61 Self {
62 source: source.to_string(),
63 range,
64 config,
65 style,
66 }
67 }
68
69 pub fn get_str(&self) -> &str {
71 &self.source[self.range.clone()]
72 }
73}