summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-01 17:49:48 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-01 17:49:48 +0100
commitd96ced8e2da703117a43399110ef2b8fa21a7546 (patch)
tree2398eab8edb23b6cfa8145d84ab788cb44cddeb4
parente1062a02d17f5748e4809b76ddcc132f1c912886 (diff)
downloadiced-d96ced8e2da703117a43399110ef2b8fa21a7546.tar.gz
iced-d96ced8e2da703117a43399110ef2b8fa21a7546.tar.bz2
iced-d96ced8e2da703117a43399110ef2b8fa21a7546.zip
Allow configuration of default font
-rw-r--r--native/src/renderer/windowed.rs4
-rw-r--r--src/application.rs7
-rw-r--r--src/settings.rs4
-rw-r--r--wgpu/src/lib.rs2
-rw-r--r--wgpu/src/renderer.rs13
-rw-r--r--wgpu/src/settings.rs4
-rw-r--r--wgpu/src/text.rs11
-rw-r--r--winit/src/application.rs8
8 files changed, 39 insertions, 14 deletions
diff --git a/native/src/renderer/windowed.rs b/native/src/renderer/windowed.rs
index 89f80bbe..30e08cb8 100644
--- a/native/src/renderer/windowed.rs
+++ b/native/src/renderer/windowed.rs
@@ -4,13 +4,15 @@ use raw_window_handle::HasRawWindowHandle;
/// A renderer that can target windows.
pub trait Windowed: super::Renderer + Sized {
+ type Settings: Default;
+
/// The type of target.
type Target: Target<Renderer = Self>;
/// Creates a new [`Windowed`] renderer.
///
/// [`Windowed`]: trait.Windowed.html
- fn new() -> Self;
+ fn new(settings: Self::Settings) -> Self;
/// Performs the drawing operations described in the output on the given
/// target.
diff --git a/src/application.rs b/src/application.rs
index a7e826fb..7dd76774 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -151,7 +151,12 @@ pub trait Application: Sized {
Self: 'static,
{
#[cfg(not(target_arch = "wasm32"))]
- <Instance<Self> as iced_winit::Application>::run(_settings.into());
+ <Instance<Self> as iced_winit::Application>::run(
+ _settings.into(),
+ iced_wgpu::Settings {
+ default_font: _settings.default_font,
+ },
+ );
#[cfg(target_arch = "wasm32")]
<Instance<Self> as iced_web::Application>::run();
diff --git a/src/settings.rs b/src/settings.rs
index 4ae18a14..b01e6fc8 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -15,6 +15,9 @@ pub struct Settings {
///
/// [`Color`]: ../struct.Color.html
pub background: Color,
+
+ // TODO: Add `name` for web compatibility
+ pub default_font: Option<&'static [u8]>,
}
impl Default for Settings {
@@ -22,6 +25,7 @@ impl Default for Settings {
Settings {
window: Window::default(),
background: Color::WHITE,
+ default_font: None,
}
}
}
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 =
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 02fa3780..d16c209c 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -81,8 +81,10 @@ pub trait Application: Sized {
/// It should probably be that last thing you call in your `main` function.
///
/// [`Application`]: trait.Application.html
- fn run(settings: Settings)
- where
+ fn run(
+ settings: Settings,
+ renderer_settings: <Self::Renderer as Windowed>::Settings,
+ ) where
Self: 'static,
{
use winit::{
@@ -140,7 +142,7 @@ pub trait Application: Sized {
let mut resized = false;
let clipboard = Clipboard::new(&window);
- let mut renderer = Self::Renderer::new();
+ let mut renderer = Self::Renderer::new(renderer_settings);
let mut target = {
let (width, height) = to_physical(size, dpi);