diff --git a/Cargo.toml b/Cargo.toml index 1136758..f56320d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,9 @@ categories = ["gui"] debug = ["iced_runtime/debug"] # Enable the wgu renderer wgpu = ["iced_renderer/wgpu"] +image = ["iced_widget/image"] +svg = ["iced_widget/svg"] +canvas = ["iced_widget/canvas"] [dependencies] baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "fdb43ea" } diff --git a/examples/custom_styles.rs b/examples/custom_styles.rs index f709b80..6445236 100644 --- a/examples/custom_styles.rs +++ b/examples/custom_styles.rs @@ -24,6 +24,7 @@ fn main() { always_redraw: true, }, flags: (), + fonts: Default::default(), }; open_blocking::(settings); diff --git a/examples/hello_world.rs b/examples/hello_world.rs index ba1256e..b3aafa5 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -23,6 +23,7 @@ fn main() { always_redraw: true, }, flags: (), + fonts: Default::default(), }; open_blocking::(settings); diff --git a/examples/window_subs.rs b/examples/window_subs.rs index e4b86db..c482bd0 100644 --- a/examples/window_subs.rs +++ b/examples/window_subs.rs @@ -12,7 +12,7 @@ use iced_baseview::{ Application, Settings, }; use iced_runtime::window::Action; -use std::time::{Duration, Instant}; +use std::{sync::Arc, time::{Duration, Instant}}; static COUNT_INTERVAL: Duration = Duration::from_millis(1000); @@ -28,6 +28,7 @@ fn main() { always_redraw: true, }, flags: (), + fonts: Default::default(), }; open_blocking::(settings); @@ -62,8 +63,8 @@ impl Application for MyProgram { } fn subscription(&self, window_subs: &mut WindowSubs) -> Subscription { - window_subs.on_frame = Some(|| Message::OnFrame); - window_subs.on_window_will_close = Some(|| Message::WillClose); + window_subs.on_frame = Some(Arc::new(|| Some(Message::OnFrame))); + window_subs.on_window_will_close = Some(Arc::new(|| Some(Message::WillClose))); Subscription::none() } diff --git a/src/application.rs b/src/application.rs index 5a3969a..415d8b2 100644 --- a/src/application.rs +++ b/src/application.rs @@ -167,13 +167,19 @@ where }; let compositor_settings = A::renderer_settings(); - let (mut compositor, renderer) = C::new(compositor_settings, Some(window))?; + let (mut compositor, mut renderer) = C::new(compositor_settings, Some(window))?; let surface = compositor.create_surface( window, viewport.physical_width(), viewport.physical_height(), ); + for font in settings.fonts { + use crate::core::text::Renderer; + + renderer.load_font(font); + } + let (window_queue, window_queue_rx) = WindowQueue::new(); let event_status = Rc::new(RefCell::new(baseview::EventStatus::Ignored)); @@ -281,7 +287,9 @@ async fn run_instance( match event { RuntimeEvent::MainEventsCleared => { if let Some(message) = &window_subs.on_frame { - messages.push(message()); + if let Some(message) = message() { + messages.push(message); + } } if !did_process_event @@ -518,7 +526,9 @@ async fn run_instance( if let Some(message) = &window_subs.on_window_will_close { // Send message to user before exiting the loop. - messages.push(message()); + if let Some(message) = message() { + messages.push(message); + } let mut cache = ManuallyDrop::into_inner(user_interface).into_cache(); update( diff --git a/src/settings.rs b/src/settings.rs index 8c108f0..9dae989 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,5 +1,5 @@ //! Configure your application. -use std::fmt::Debug; +use std::{borrow::Cow, fmt::Debug}; use baseview::WindowOpenOptions; @@ -20,6 +20,9 @@ pub struct Settings { /// iced_baseview settings pub iced_baseview: IcedBaseviewSettings, + + /// The fonts to load on boot. + pub fonts: Vec>, } /// Any settings specific to `iced_baseview`. diff --git a/src/window.rs b/src/window.rs index 7dcaf2b..5edb489 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, pin::Pin, rc::Rc}; +use std::{cell::RefCell, pin::Pin, rc::Rc, sync::Arc}; use baseview::{Event, EventStatus, Window, WindowHandler, WindowOpenOptions}; use iced_runtime::futures::futures::{ @@ -284,9 +284,9 @@ impl WindowQueue { #[allow(missing_debug_implementations)] pub struct WindowSubs { /// The message to send right before each rendering frame. - pub on_frame: Option Message>, + pub on_frame: Option Option>>, /// The message to send when the window is about to close. - pub on_window_will_close: Option Message>, + pub on_window_will_close: Option Option>>, } impl Default for WindowSubs {