#![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub mod draw;
mod draw_shaded;
pub mod options;
mod shaded_theme;
mod surface;
use crate::draw::{CustomPipeBuilder, DrawPipe};
use kas::runner;
use kas::theme::{FlatTheme, Theme};
use wgpu::rwh;
pub use draw_shaded::{DrawShaded, DrawShadedImpl};
pub use options::Options;
pub use shaded_theme::ShadedTheme;
pub extern crate wgpu;
pub struct Builder<CB: CustomPipeBuilder> {
custom: CB,
options: Options,
read_env_vars: bool,
}
impl<CB: CustomPipeBuilder> runner::GraphicsBuilder for Builder<CB> {
type DefaultTheme = FlatTheme;
type Shared = DrawPipe<CB::Pipe>;
type Surface<'a> = surface::Surface<'a, CB::Pipe>;
fn build(self) -> runner::Result<Self::Shared> {
let mut options = self.options;
if self.read_env_vars {
options.load_from_env();
}
DrawPipe::new(self.custom, &options)
}
fn new_surface<'window, W>(
shared: &mut Self::Shared,
window: W,
transparent: bool,
) -> runner::Result<Self::Surface<'window>>
where
W: rwh::HasWindowHandle + rwh::HasDisplayHandle + Send + Sync + 'window,
Self: Sized,
{
surface::Surface::new(shared, window, transparent)
}
}
impl Default for Builder<()> {
fn default() -> Self {
Builder::new(())
}
}
impl<CB: CustomPipeBuilder> Builder<CB> {
#[inline]
pub fn new(cb: CB) -> Self {
Builder {
custom: cb,
options: Options::default(),
read_env_vars: true,
}
}
#[inline]
pub fn with_wgpu_options(mut self, options: Options) -> Self {
self.options = options;
self
}
#[inline]
pub fn read_env_vars(mut self, read_env_vars: bool) -> Self {
self.read_env_vars = read_env_vars;
self
}
#[inline]
pub fn with_default_theme(self) -> runner::Builder<Self, FlatTheme> {
runner::Builder::new(self, FlatTheme::new())
}
#[inline]
pub fn with_theme<T: Theme<DrawPipe<CB::Pipe>>>(self, theme: T) -> runner::Builder<Self, T> {
runner::Builder::new(self, theme)
}
}