Allow configuration of default font
This commit is contained in:
parent
e1062a02d1
commit
d96ced8e2d
8 changed files with 39 additions and 14 deletions
|
|
@ -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::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -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>>(
|
||||
|
|
|
|||
4
wgpu/src/settings.rs
Normal file
4
wgpu/src/settings.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct Settings {
|
||||
pub default_font: Option<&'static [u8]>,
|
||||
}
|
||||
|
|
@ -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 =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue