#![recursion_limit = "256"]
use std::{any::Any, fmt};
pub mod prelude;
pub use orbtk_utils::prelude as utils;
#[cfg(all(not(target_arch = "wasm32"), feature = "pfinder"))]
#[path = "pathfinder/mod.rs"]
pub mod platform;
#[cfg(any(target_arch = "wasm32", feature = "pfinder"))]
pub use self::platform::*;
#[cfg(all(
not(target_arch = "wasm32"),
feature = "default",
not(feature = "pfinder")
))]
#[path = "raqote/mod.rs"]
pub mod platform;
#[cfg(all(
not(target_arch = "wasm32"),
feature = "default",
not(feature = "pfinder")
))]
pub mod concurrent;
#[cfg(all(
not(target_arch = "wasm32"),
feature = "default",
not(feature = "pfinder")
))]
pub use self::concurrent::*;
#[cfg(target_arch = "wasm32")]
#[path = "web/mod.rs"]
pub mod platform;
#[cfg(target_arch = "wasm32")]
pub use platform::RenderContext2D;
pub use self::render_target::*;
mod render_target;
#[derive(Debug, Clone)]
pub struct RenderConfig {
pub fill_style: utils::Brush,
pub stroke_style: utils::Brush,
pub line_width: f64,
pub font_config: FontConfig,
pub alpha: f32,
}
impl Default for RenderConfig {
fn default() -> Self {
RenderConfig {
fill_style: utils::Brush::default(),
stroke_style: utils::Brush::default(),
line_width: 1.,
font_config: FontConfig::default(),
alpha: 1.,
}
}
}
#[derive(Clone, Copy, Default, Debug)]
pub struct TextMetrics {
pub width: f64,
pub height: f64,
}
#[derive(Default, Clone, PartialEq, Debug)]
pub struct FontConfig {
pub family: String,
pub font_size: f64,
}
impl ToString for FontConfig {
fn to_string(&self) -> String {
format!("{}px {}", self.font_size, self.family)
}
}
pub trait RenderPipeline {
fn draw(&self, image: &mut RenderTarget);
}
pub trait PipelineTrait: RenderPipeline + Any + Send {
fn box_eq(&self, other: &dyn Any) -> bool;
fn as_any(&self) -> &dyn Any;
fn clone_box(&self) -> Box<dyn PipelineTrait>;
fn draw_pipeline(&self, image: &mut RenderTarget) {
self.draw(image);
}
}
impl PartialEq for Box<dyn PipelineTrait> {
fn eq(&self, other: &Box<dyn PipelineTrait>) -> bool {
self.box_eq(other.as_any())
}
}
impl Clone for Box<dyn PipelineTrait> {
fn clone(&self) -> Self {
self.clone_box()
}
}
impl fmt::Debug for Box<dyn PipelineTrait> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Box<dyn PipelineTrait>")
}
}