use std::sync::Arc;
use std::time::Duration;
use canvist_headless::canvist_core::Platform;
use canvist_layout::Theme;
use crate::FontSource;
const CARET_BLINK: Duration = Duration::from_millis(530);
#[derive(Clone, Debug)]
pub struct EditorOptions {
pub theme: Arc<Theme>,
pub fonts: FontSource,
pub platform: Platform,
pub client: u32,
pub padding: f32,
pub max_width: Option<f32>,
pub overscan: f32,
pub caret_blink: Duration,
pub label: String,
}
impl Default for EditorOptions {
fn default() -> Self {
Self {
theme: Arc::new(Theme::starter_kit()),
fonts: FontSource::System,
platform: current_platform(),
client: 1,
padding: 24.0,
max_width: None,
overscan: 600.0,
caret_blink: CARET_BLINK,
label: "Document".to_owned(),
}
}
}
impl EditorOptions {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn theme(mut self, theme: Arc<Theme>) -> Self {
self.theme = theme;
self
}
#[must_use]
pub fn fonts(mut self, source: FontSource) -> Self {
self.fonts = source;
self
}
#[must_use]
pub fn platform(mut self, platform: Platform) -> Self {
self.platform = platform;
self
}
#[must_use]
pub fn client(mut self, client: u32) -> Self {
self.client = client;
self
}
#[must_use]
pub fn padding(mut self, padding: f32) -> Self {
self.padding = padding;
self
}
#[must_use]
pub fn max_width(mut self, width: f32) -> Self {
self.max_width = Some(width);
self
}
#[must_use]
pub fn caret_blink(mut self, period: Duration) -> Self {
self.caret_blink = period;
self
}
#[must_use]
pub fn label(mut self, label: &str) -> Self {
label.clone_into(&mut self.label);
self
}
}
#[must_use]
pub fn current_platform() -> Platform {
if cfg!(target_vendor = "apple") {
Platform::Apple
} else {
Platform::Other
}
}