use cotis_defaults::element_configs::text_config::{TextConfig, TextStyle};
use std::ops::Range;
use std::sync::Arc;
#[derive(Clone, Debug)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct TextDrawPayload {
#[cfg(not(feature = "serialization"))]
source: Arc<str>,
#[cfg(feature = "serialization")]
source: String,
range: Range<usize>,
pub config: TextConfig,
pub style: TextStyle,
}
#[cfg(not(feature = "serialization"))]
impl TextDrawPayload {
pub fn new_from_arc(
source: &Arc<str>,
range: Range<usize>,
config: TextConfig,
style: TextStyle,
) -> Self {
Self {
source: source.clone(),
range,
config,
style,
}
}
pub fn get_str(&self) -> &str {
&self.source[self.range.clone()]
}
}
#[cfg(feature = "serialization")]
impl TextDrawPayload {
pub fn new_from_arc(
source: &Arc<str>,
range: Range<usize>,
config: TextConfig,
style: TextStyle,
) -> Self {
Self {
source: source.to_string(),
range,
config,
style,
}
}
pub fn get_str(&self) -> &str {
&self.source[self.range.clone()]
}
}