diff options
Diffstat (limited to '')
| -rw-r--r-- | wgpu/src/lib.rs | 2 | ||||
| -rw-r--r-- | wgpu/src/renderer.rs | 13 | ||||
| -rw-r--r-- | wgpu/src/settings.rs | 4 | ||||
| -rw-r--r-- | wgpu/src/text.rs | 11 | 
4 files changed, 21 insertions, 9 deletions
diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 786b6872..80ebc2a7 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -31,12 +31,14 @@ mod image;  mod primitive;  mod quad;  mod renderer; +mod settings;  mod text;  mod transformation;  pub use defaults::Defaults;  pub use primitive::Primitive;  pub use renderer::{Renderer, Target}; +pub use settings::Settings;  #[doc(no_inline)]  pub use widget::*; diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index efda046b..7f0f0b89 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -1,5 +1,6 @@  use crate::{ -    image, quad, text, Defaults, Image, Primitive, Quad, Transformation, +    image, quad, text, Defaults, Image, Primitive, Quad, Settings, +    Transformation,  };  use iced_native::{      renderer::{Debugger, Windowed}, @@ -49,7 +50,7 @@ impl<'a> Layer<'a> {  }  impl Renderer { -    fn new() -> Self { +    fn new(settings: Settings) -> Self {          let adapter = Adapter::request(&RequestAdapterOptions {              power_preference: PowerPreference::Default,              backends: BackendBit::all(), @@ -63,7 +64,8 @@ impl Renderer {              limits: Limits { max_bind_groups: 2 },          }); -        let text_pipeline = text::Pipeline::new(&mut device); +        let text_pipeline = +            text::Pipeline::new(&mut device, settings.default_font);          let quad_pipeline = quad::Pipeline::new(&mut device);          let image_pipeline = image::Pipeline::new(&mut device); @@ -432,10 +434,11 @@ impl iced_native::Renderer for Renderer {  }  impl Windowed for Renderer { +    type Settings = Settings;      type Target = Target; -    fn new() -> Self { -        Self::new() +    fn new(settings: Settings) -> Self { +        Self::new(settings)      }      fn draw<T: AsRef<str>>( diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs new file mode 100644 index 00000000..c6d8369b --- /dev/null +++ b/wgpu/src/settings.rs @@ -0,0 +1,4 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct Settings { +    pub default_font: Option<&'static [u8]>, +} diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 880ad1a6..ab9a2f71 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -22,13 +22,16 @@ pub struct Pipeline {  }  impl Pipeline { -    pub fn new(device: &mut wgpu::Device) -> Self { +    pub fn new(device: &mut wgpu::Device, default_font: Option<&[u8]>) -> Self {          // TODO: Font customization          let font_source = font::Source::new(); -        let default_font = font_source -            .load(&[font::Family::SansSerif, font::Family::Serif]) -            .unwrap_or_else(|_| FALLBACK_FONT.to_vec()); +        let default_font = +            default_font.map(|slice| slice.to_vec()).unwrap_or_else(|| { +                font_source +                    .load(&[font::Family::SansSerif, font::Family::Serif]) +                    .unwrap_or_else(|_| FALLBACK_FONT.to_vec()) +            });          let load_glyph_brush = |font: Vec<u8>| {              let builder =  | 
