use dpi::{Position, Size};
use std::path::{Path, PathBuf};
use versoview_messages::{ConfigFromController, ProfilerSettings, UserScript};
use crate::VersoviewController;
#[derive(Debug, Clone)]
pub struct VersoBuilder(ConfigFromController);
impl VersoBuilder {
pub fn new() -> Self {
Self(ConfigFromController::default())
}
pub fn with_panel(mut self, with_panel: bool) -> Self {
self.0.with_panel = with_panel;
self
}
pub fn inner_size(mut self, size: impl Into<Size>) -> Self {
self.0.inner_size = Some(size.into());
self
}
pub fn position(mut self, position: impl Into<Position>) -> Self {
self.0.position = Some(position.into());
self
}
pub fn maximized(mut self, maximized: bool) -> Self {
self.0.maximized = maximized;
self
}
pub fn visible(mut self, visible: bool) -> Self {
self.0.visible = visible;
self
}
pub fn fullscreen(mut self, fullscreen: bool) -> Self {
self.0.fullscreen = fullscreen;
self
}
pub fn focused(mut self, focused: bool) -> Self {
self.0.focused = focused;
self
}
pub fn decorated(mut self, decorated: bool) -> Self {
self.0.decorated = decorated;
self
}
pub fn transparent(mut self, transparent: bool) -> Self {
self.0.transparent = transparent;
self
}
pub fn title(mut self, title: impl Into<String>) -> Self {
self.0.title = Some(title.into());
self
}
pub fn devtools_port(mut self, port: u16) -> Self {
self.0.devtools_port = Some(port);
self
}
pub fn profiler_settings(mut self, settings: ProfilerSettings) -> Self {
self.0.profiler_settings = Some(settings);
self
}
pub fn user_agent(mut self, user_agent: impl Into<String>) -> Self {
self.0.user_agent = Some(user_agent.into());
self
}
pub fn user_script(mut self, script: impl Into<UserScript>) -> Self {
self.0.user_scripts.push(script.into());
self
}
pub fn user_scripts<I, S>(mut self, scripts: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<UserScript>,
{
for script in scripts {
self = self.user_script(script)
}
self
}
pub fn zoom_level(mut self, zoom: f32) -> Self {
self.0.zoom_level = Some(zoom);
self
}
pub fn resources_directory(mut self, path: impl Into<PathBuf>) -> Self {
self.0.resources_directory = Some(path.into());
self
}
pub fn build(
self,
versoview_path: impl AsRef<Path>,
initial_url: url::Url,
) -> VersoviewController {
VersoviewController::create(versoview_path, initial_url, self.0)
}
}