#![recursion_limit = "256"]
use std::{any::Any, fmt};
pub mod prelude;
pub use orbtk_utils::prelude as utils;
mod common;
pub use tinyskia::*;
pub mod tinyskia;
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>")
}
}