From d4743183d40c6044ce6fa39e2a52919a32912cda Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 May 2020 14:23:28 +0200 Subject: Draft first working version of `iced_glow` :tada: --- winit/src/application.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index f6bc8fcc..4bc36586 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -78,7 +78,11 @@ pub trait Application: Sized { /// [`update`](#tymethod.update). /// /// A `Subscription` will be kept alive as long as you keep returning it! - fn subscription(&self) -> Subscription; + /// + /// By default, it returns an empty subscription. + fn subscription(&self) -> Subscription { + Subscription::none() + } /// Returns the widgets to display in the [`Application`]. /// @@ -177,9 +181,10 @@ pub trait Application: Sized { let mut resized = false; let clipboard = Clipboard::new(&window); - let (mut backend, mut renderer) = Self::Backend::new(backend_settings); + let mut backend = Self::Backend::new(backend_settings.clone()); let surface = backend.create_surface(&window); + let mut renderer = backend.create_renderer(backend_settings); let mut swap_chain = { let physical_size = size.physical(); -- cgit From 4aed0fa4b6d63b739b5557ef16f6077988cd2758 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 May 2020 20:01:55 +0200 Subject: Rename `window::Backend` to `Compositor` --- winit/src/application.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 4bc36586..83b53de2 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -19,7 +19,7 @@ pub trait Application: Sized { /// The graphics backend to use to draw the [`Application`]. /// /// [`Application`]: trait.Application.html - type Backend: window::Backend; + type Compositor: window::Compositor; /// The [`Executor`] that will run commands and subscriptions. /// @@ -91,7 +91,11 @@ pub trait Application: Sized { /// [`Application`]: trait.Application.html fn view( &mut self, - ) -> Element<'_, Self::Message, ::Renderer>; + ) -> Element< + '_, + Self::Message, + ::Renderer, + >; /// Returns the current [`Application`] mode. /// @@ -116,11 +120,11 @@ pub trait Application: Sized { /// [`Settings`]: struct.Settings.html fn run( settings: Settings, - backend_settings: ::Settings, + backend_settings: ::Settings, ) where Self: 'static, { - use window::Backend as _; + use window::Compositor as _; use winit::{ event::{self, WindowEvent}, event_loop::{ControlFlow, EventLoop}, @@ -181,15 +185,15 @@ pub trait Application: Sized { let mut resized = false; let clipboard = Clipboard::new(&window); - let mut backend = Self::Backend::new(backend_settings.clone()); + let mut compositor = Self::Compositor::new(backend_settings.clone()); - let surface = backend.create_surface(&window); - let mut renderer = backend.create_renderer(backend_settings); + let surface = compositor.create_surface(&window); + let mut renderer = compositor.create_renderer(backend_settings); let mut swap_chain = { let physical_size = size.physical(); - backend.create_swap_chain( + compositor.create_swap_chain( &surface, physical_size.width, physical_size.height, @@ -324,7 +328,7 @@ pub trait Application: Sized { if resized { let physical_size = size.physical(); - swap_chain = backend.create_swap_chain( + swap_chain = compositor.create_swap_chain( &surface, physical_size.width, physical_size.height, @@ -333,7 +337,7 @@ pub trait Application: Sized { resized = false; } - let new_mouse_interaction = backend.draw( + let new_mouse_interaction = compositor.draw( &mut renderer, &mut swap_chain, &primitive, @@ -414,10 +418,14 @@ pub trait Application: Sized { fn build_user_interface<'a, A: Application>( application: &'a mut A, cache: Cache, - renderer: &mut ::Renderer, + renderer: &mut ::Renderer, size: winit::dpi::LogicalSize, debug: &mut Debug, -) -> UserInterface<'a, A::Message, ::Renderer> { +) -> UserInterface< + 'a, + A::Message, + ::Renderer, +> { debug.view_started(); let view = application.view(); debug.view_finished(); -- cgit From a1a5fcfd46622d5b18d1716aa2adb4659835ccf3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 May 2020 20:28:35 +0200 Subject: Refactor `Viewport` and `Compositor` --- winit/src/application.rs | 65 +++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 36 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 83b53de2..9196709b 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -1,8 +1,9 @@ use crate::{ - conversion, mouse, size::Size, window, Cache, Clipboard, Command, Debug, - Element, Executor, Mode, Proxy, Runtime, Settings, Subscription, - UserInterface, + conversion, mouse, Cache, Clipboard, Command, Debug, Element, Executor, + Mode, Proxy, Runtime, Settings, Size, Subscription, UserInterface, }; +use iced_graphics::window; +use iced_graphics::Viewport; /// An interactive, native cross-platform application. /// @@ -124,7 +125,7 @@ pub trait Application: Sized { ) where Self: 'static, { - use window::Compositor as _; + use iced_graphics::window::Compositor as _; use winit::{ event::{self, WindowEvent}, event_loop::{ControlFlow, EventLoop}, @@ -181,7 +182,11 @@ pub trait Application: Sized { window_builder.build(&event_loop).expect("Open window") }; - let mut size = Size::new(window.inner_size(), window.scale_factor()); + let physical_size = window.inner_size(); + let mut viewport = Viewport::with_physical_size( + Size::new(physical_size.width, physical_size.height), + window.scale_factor(), + ); let mut resized = false; let clipboard = Clipboard::new(&window); @@ -190,21 +195,17 @@ pub trait Application: Sized { let surface = compositor.create_surface(&window); let mut renderer = compositor.create_renderer(backend_settings); - let mut swap_chain = { - let physical_size = size.physical(); - - compositor.create_swap_chain( - &surface, - physical_size.width, - physical_size.height, - ) - }; + let mut swap_chain = compositor.create_swap_chain( + &surface, + physical_size.width, + physical_size.height, + ); let user_interface = build_user_interface( &mut application, Cache::default(), &mut renderer, - size.logical(), + viewport.logical_size(), &mut debug, ); @@ -226,16 +227,11 @@ pub trait Application: Sized { return; } - // TODO: We should be able to keep a user interface alive - // between events once we remove state references. - // - // This will allow us to rebuild it only when a message is - // handled. let mut user_interface = build_user_interface( &mut application, cache.take().unwrap(), &mut renderer, - size.logical(), + viewport.logical_size(), &mut debug, ); @@ -306,7 +302,7 @@ pub trait Application: Sized { &mut application, temp_cache, &mut renderer, - size.logical(), + viewport.logical_size(), &mut debug, ); @@ -326,7 +322,7 @@ pub trait Application: Sized { debug.render_started(); if resized { - let physical_size = size.physical(); + let physical_size = viewport.physical_size(); swap_chain = compositor.create_swap_chain( &surface, @@ -340,8 +336,8 @@ pub trait Application: Sized { let new_mouse_interaction = compositor.draw( &mut renderer, &mut swap_chain, + &viewport, &primitive, - size.scale_factor(), &debug.overlay(), ); @@ -364,7 +360,12 @@ pub trait Application: Sized { } => { match window_event { WindowEvent::Resized(new_size) => { - size = Size::new(new_size, window.scale_factor()); + let size = Size::new(new_size.width, new_size.height); + + viewport = Viewport::with_physical_size( + size, + window.scale_factor(), + ); resized = true; } WindowEvent::CloseRequested => { @@ -402,7 +403,7 @@ pub trait Application: Sized { if let Some(event) = conversion::window_event( &window_event, - size.scale_factor(), + viewport.scale_factor(), modifiers, ) { events.push(event); @@ -419,7 +420,7 @@ fn build_user_interface<'a, A: Application>( application: &'a mut A, cache: Cache, renderer: &mut ::Renderer, - size: winit::dpi::LogicalSize, + size: Size, debug: &mut Debug, ) -> UserInterface< 'a, @@ -431,15 +432,7 @@ fn build_user_interface<'a, A: Application>( debug.view_finished(); debug.layout_started(); - let user_interface = UserInterface::build( - view, - iced_native::Size::new( - size.width.round() as f32, - size.height.round() as f32, - ), - cache, - renderer, - ); + let user_interface = UserInterface::build(view, size, cache, renderer); debug.layout_finished(); user_interface -- cgit From e0e4ee73feead3f05730625c7e1917b63f0b384e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 May 2020 00:37:47 +0200 Subject: Implement `iced_glutin` :tada: --- winit/src/application.rs | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 9196709b..ccab19f1 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -129,7 +129,6 @@ pub trait Application: Sized { use winit::{ event::{self, WindowEvent}, event_loop::{ControlFlow, EventLoop}, - window::WindowBuilder, }; let mut debug = Debug::new(); @@ -155,32 +154,11 @@ pub trait Application: Sized { let mut title = application.title(); let mut mode = application.mode(); - let window = { - let mut window_builder = WindowBuilder::new(); - - let (width, height) = settings.window.size; - - window_builder = window_builder - .with_title(&title) - .with_inner_size(winit::dpi::LogicalSize { width, height }) - .with_resizable(settings.window.resizable) - .with_decorations(settings.window.decorations) - .with_fullscreen(conversion::fullscreen( - event_loop.primary_monitor(), - mode, - )); - - #[cfg(target_os = "windows")] - { - use winit::platform::windows::WindowBuilderExtWindows; - - if let Some(parent) = settings.window.platform_specific.parent { - window_builder = window_builder.with_parent_window(parent); - } - } - - window_builder.build(&event_loop).expect("Open window") - }; + let window = settings + .window + .into_builder(&title, mode, event_loop.primary_monitor()) + .build(&event_loop) + .expect("Open window"); let physical_size = window.inner_size(); let mut viewport = Viewport::with_physical_size( -- cgit From ae5e2c6c734894d71b2034a498a858b7997c5d3d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 May 2020 04:27:31 +0200 Subject: Introduce `Program` and `State` --- winit/src/application.rs | 535 +++++++++++++++++++---------------------------- 1 file changed, 212 insertions(+), 323 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index ccab19f1..fcba47b3 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -1,9 +1,10 @@ use crate::{ - conversion, mouse, Cache, Clipboard, Command, Debug, Element, Executor, - Mode, Proxy, Runtime, Settings, Size, Subscription, UserInterface, + conversion, mouse, Clipboard, Command, Debug, Executor, Mode, Proxy, + Runtime, Settings, Size, Subscription, }; use iced_graphics::window; use iced_graphics::Viewport; +use iced_native::program::{self, Program}; /// An interactive, native cross-platform application. /// @@ -16,22 +17,7 @@ use iced_graphics::Viewport; /// /// When using an [`Application`] with the `debug` feature enabled, a debug view /// can be toggled by pressing `F12`. -pub trait Application: Sized { - /// The graphics backend to use to draw the [`Application`]. - /// - /// [`Application`]: trait.Application.html - type Compositor: window::Compositor; - - /// The [`Executor`] that will run commands and subscriptions. - /// - /// [`Executor`]: trait.Executor.html - type Executor: Executor; - - /// The type of __messages__ your [`Application`] will produce. - /// - /// [`Application`]: trait.Application.html - type Message: std::fmt::Debug + Send; - +pub trait Application: Program { /// The data needed to initialize your [`Application`]. /// /// [`Application`]: trait.Application.html @@ -60,18 +46,6 @@ pub trait Application: Sized { /// [`Application`]: trait.Application.html fn title(&self) -> String; - /// Handles a __message__ and updates the state of the [`Application`]. - /// - /// This is where you define your __update logic__. All the __messages__, - /// produced by either user interactions or commands, will be handled by - /// this method. - /// - /// Any [`Command`] returned will be executed immediately in the background. - /// - /// [`Application`]: trait.Application.html - /// [`Command`]: struct.Command.html - fn update(&mut self, message: Self::Message) -> Command; - /// Returns the event `Subscription` for the current state of the /// application. /// @@ -85,19 +59,6 @@ pub trait Application: Sized { Subscription::none() } - /// Returns the widgets to display in the [`Application`]. - /// - /// These widgets can produce __messages__ based on user interaction. - /// - /// [`Application`]: trait.Application.html - fn view( - &mut self, - ) -> Element< - '_, - Self::Message, - ::Renderer, - >; - /// Returns the current [`Application`] mode. /// /// The runtime will automatically transition your application if a new mode @@ -109,309 +70,237 @@ pub trait Application: Sized { fn mode(&self) -> Mode { Mode::Windowed } +} - /// Runs the [`Application`] with the provided [`Settings`]. - /// - /// On native platforms, this method will take control of the current thread - /// and __will NOT return__. - /// - /// It should probably be that last thing you call in your `main` function. - /// - /// [`Application`]: trait.Application.html - /// [`Settings`]: struct.Settings.html - fn run( - settings: Settings, - backend_settings: ::Settings, - ) where - Self: 'static, - { - use iced_graphics::window::Compositor as _; - use winit::{ - event::{self, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - }; - - let mut debug = Debug::new(); - - debug.startup_started(); - let event_loop = EventLoop::with_user_event(); - let mut external_messages = Vec::new(); - - let mut runtime = { - let executor = Self::Executor::new().expect("Create executor"); - - Runtime::new(executor, Proxy::new(event_loop.create_proxy())) - }; - - let flags = settings.flags; - let (mut application, init_command) = - runtime.enter(|| Self::new(flags)); - runtime.spawn(init_command); - - let subscription = application.subscription(); - runtime.track(subscription); - - let mut title = application.title(); - let mut mode = application.mode(); - - let window = settings - .window - .into_builder(&title, mode, event_loop.primary_monitor()) - .build(&event_loop) - .expect("Open window"); - - let physical_size = window.inner_size(); - let mut viewport = Viewport::with_physical_size( - Size::new(physical_size.width, physical_size.height), - window.scale_factor(), - ); - let mut resized = false; - - let clipboard = Clipboard::new(&window); - let mut compositor = Self::Compositor::new(backend_settings.clone()); - - let surface = compositor.create_surface(&window); - let mut renderer = compositor.create_renderer(backend_settings); - - let mut swap_chain = compositor.create_swap_chain( - &surface, - physical_size.width, - physical_size.height, - ); - - let user_interface = build_user_interface( - &mut application, - Cache::default(), - &mut renderer, - viewport.logical_size(), - &mut debug, - ); - - debug.draw_started(); - let mut primitive = user_interface.draw(&mut renderer); - debug.draw_finished(); - - let mut cache = Some(user_interface.into_cache()); - let mut events = Vec::new(); - let mut mouse_interaction = mouse::Interaction::default(); - let mut modifiers = winit::event::ModifiersState::default(); - debug.startup_finished(); - - window.request_redraw(); - - event_loop.run(move |event, _, control_flow| match event { - event::Event::MainEventsCleared => { - if events.is_empty() && external_messages.is_empty() { - return; - } - - let mut user_interface = build_user_interface( - &mut application, - cache.take().unwrap(), - &mut renderer, +pub fn run( + settings: Settings, + compositor_settings: C::Settings, +) where + A: Application + 'static, + E: Executor + 'static, + C: window::Compositor + 'static, +{ + use winit::{ + event, + event_loop::{ControlFlow, EventLoop}, + }; + + let mut debug = Debug::new(); + debug.startup_started(); + + let event_loop = EventLoop::with_user_event(); + let mut runtime = { + let executor = E::new().expect("Create executor"); + let proxy = Proxy::new(event_loop.create_proxy()); + + Runtime::new(executor, proxy) + }; + + let flags = settings.flags; + let (application, init_command) = runtime.enter(|| A::new(flags)); + runtime.spawn(init_command); + + let subscription = application.subscription(); + runtime.track(subscription); + + let mut title = application.title(); + let mut mode = application.mode(); + + let window = settings + .window + .into_builder(&title, mode, event_loop.primary_monitor()) + .build(&event_loop) + .expect("Open window"); + + let clipboard = Clipboard::new(&window); + let mut mouse_interaction = mouse::Interaction::default(); + let mut modifiers = winit::event::ModifiersState::default(); + + let physical_size = window.inner_size(); + let mut viewport = Viewport::with_physical_size( + Size::new(physical_size.width, physical_size.height), + window.scale_factor(), + ); + let mut resized = false; + + let (mut compositor, mut renderer) = C::new(compositor_settings); + + let surface = compositor.create_surface(&window); + + let mut swap_chain = compositor.create_swap_chain( + &surface, + physical_size.width, + physical_size.height, + ); + + let mut state = program::State::new( + application, + viewport.logical_size(), + &mut renderer, + &mut debug, + ); + debug.startup_finished(); + + event_loop.run(move |event, _, control_flow| match event { + event::Event::MainEventsCleared => { + let command = runtime.enter(|| { + state.update( + clipboard.as_ref().map(|c| c as _), viewport.logical_size(), + &mut renderer, &mut debug, - ); - - debug.event_processing_started(); - events - .iter() - .cloned() - .for_each(|event| runtime.broadcast(event)); - - let mut messages = user_interface.update( - events.drain(..), - clipboard - .as_ref() - .map(|c| c as &dyn iced_native::Clipboard), - &renderer, - ); - messages.extend(external_messages.drain(..)); - debug.event_processing_finished(); - - if messages.is_empty() { - debug.draw_started(); - primitive = user_interface.draw(&mut renderer); - debug.draw_finished(); - - cache = Some(user_interface.into_cache()); - } else { - // When there are messages, we are forced to rebuild twice - // for now :^) - let temp_cache = user_interface.into_cache(); - - for message in messages { - log::debug!("Updating"); - - debug.log_message(&message); + ) + }); - debug.update_started(); - let command = - runtime.enter(|| application.update(message)); - runtime.spawn(command); - debug.update_finished(); - } + // If the application was updated + if let Some(command) = command { + runtime.spawn(command); - let subscription = application.subscription(); - runtime.track(subscription); + let program = state.program(); - // Update window title - let new_title = application.title(); + // Update subscriptions + let subscription = program.subscription(); + runtime.track(subscription); - if title != new_title { - window.set_title(&new_title); + // Update window title + let new_title = program.title(); - title = new_title; - } + if title != new_title { + window.set_title(&new_title); - // Update window mode - let new_mode = application.mode(); - - if mode != new_mode { - window.set_fullscreen(conversion::fullscreen( - window.current_monitor(), - new_mode, - )); - - mode = new_mode; - } - - let user_interface = build_user_interface( - &mut application, - temp_cache, - &mut renderer, - viewport.logical_size(), - &mut debug, - ); - - debug.draw_started(); - primitive = user_interface.draw(&mut renderer); - debug.draw_finished(); - - cache = Some(user_interface.into_cache()); + title = new_title; } - window.request_redraw(); - } - event::Event::UserEvent(message) => { - external_messages.push(message); - } - event::Event::RedrawRequested(_) => { - debug.render_started(); + // Update window mode + let new_mode = program.mode(); - if resized { - let physical_size = viewport.physical_size(); - - swap_chain = compositor.create_swap_chain( - &surface, - physical_size.width, - physical_size.height, - ); + if mode != new_mode { + window.set_fullscreen(conversion::fullscreen( + window.current_monitor(), + new_mode, + )); - resized = false; + mode = new_mode; } + } - let new_mouse_interaction = compositor.draw( - &mut renderer, - &mut swap_chain, - &viewport, - &primitive, - &debug.overlay(), + window.request_redraw(); + } + event::Event::UserEvent(message) => { + state.queue_message(message); + } + event::Event::RedrawRequested(_) => { + debug.render_started(); + + if resized { + let physical_size = viewport.physical_size(); + + swap_chain = compositor.create_swap_chain( + &surface, + physical_size.width, + physical_size.height, ); - debug.render_finished(); + resized = false; + } - if new_mouse_interaction != mouse_interaction { - window.set_cursor_icon(conversion::mouse_interaction( - new_mouse_interaction, - )); + let new_mouse_interaction = compositor.draw( + &mut renderer, + &mut swap_chain, + &viewport, + state.primitive(), + &debug.overlay(), + ); - mouse_interaction = new_mouse_interaction; - } + debug.render_finished(); - // TODO: Handle animations! - // Maybe we can use `ControlFlow::WaitUntil` for this. - } - event::Event::WindowEvent { - event: window_event, - .. - } => { - match window_event { - WindowEvent::Resized(new_size) => { - let size = Size::new(new_size.width, new_size.height); - - viewport = Viewport::with_physical_size( - size, - window.scale_factor(), - ); - resized = true; - } - WindowEvent::CloseRequested => { - *control_flow = ControlFlow::Exit; - } - WindowEvent::ModifiersChanged(new_modifiers) => { - modifiers = new_modifiers; - } - #[cfg(target_os = "macos")] - WindowEvent::KeyboardInput { - input: - winit::event::KeyboardInput { - virtual_keycode: - Some(winit::event::VirtualKeyCode::Q), - state: winit::event::ElementState::Pressed, - .. - }, - .. - } if modifiers.logo() => { - *control_flow = ControlFlow::Exit; - } - #[cfg(feature = "debug")] - WindowEvent::KeyboardInput { - input: - winit::event::KeyboardInput { - virtual_keycode: - Some(winit::event::VirtualKeyCode::F12), - state: winit::event::ElementState::Pressed, - .. - }, - .. - } => debug.toggle(), - _ => {} - } + if new_mouse_interaction != mouse_interaction { + window.set_cursor_icon(conversion::mouse_interaction( + new_mouse_interaction, + )); - if let Some(event) = conversion::window_event( - &window_event, - viewport.scale_factor(), - modifiers, - ) { - events.push(event); - } + mouse_interaction = new_mouse_interaction; } - _ => { - *control_flow = ControlFlow::Wait; + + // TODO: Handle animations! + // Maybe we can use `ControlFlow::WaitUntil` for this. + } + event::Event::WindowEvent { + event: window_event, + .. + } => { + handle_window_event( + &window_event, + &window, + control_flow, + &mut modifiers, + &mut viewport, + &mut resized, + &mut debug, + ); + + if let Some(event) = conversion::window_event( + &window_event, + viewport.scale_factor(), + modifiers, + ) { + state.queue_event(event.clone()); + runtime.broadcast(event); } - }) - } + } + _ => { + *control_flow = ControlFlow::Wait; + } + }) } -fn build_user_interface<'a, A: Application>( - application: &'a mut A, - cache: Cache, - renderer: &mut ::Renderer, - size: Size, - debug: &mut Debug, -) -> UserInterface< - 'a, - A::Message, - ::Renderer, -> { - debug.view_started(); - let view = application.view(); - debug.view_finished(); - - debug.layout_started(); - let user_interface = UserInterface::build(view, size, cache, renderer); - debug.layout_finished(); - - user_interface +pub fn handle_window_event( + event: &winit::event::WindowEvent<'_>, + window: &winit::window::Window, + control_flow: &mut winit::event_loop::ControlFlow, + modifiers: &mut winit::event::ModifiersState, + viewport: &mut Viewport, + resized: &mut bool, + _debug: &mut Debug, +) { + use winit::{event::WindowEvent, event_loop::ControlFlow}; + + match event { + WindowEvent::Resized(new_size) => { + let size = Size::new(new_size.width, new_size.height); + + *viewport = + Viewport::with_physical_size(size, window.scale_factor()); + *resized = true; + } + WindowEvent::CloseRequested => { + *control_flow = ControlFlow::Exit; + } + WindowEvent::ModifiersChanged(new_modifiers) => { + *modifiers = *new_modifiers; + } + #[cfg(target_os = "macos")] + WindowEvent::KeyboardInput { + input: + winit::event::KeyboardInput { + virtual_keycode: Some(winit::event::VirtualKeyCode::Q), + state: winit::event::ElementState::Pressed, + .. + }, + .. + } if modifiers.logo() => { + *control_flow = ControlFlow::Exit; + } + #[cfg(feature = "debug")] + WindowEvent::KeyboardInput { + input: + winit::event::KeyboardInput { + virtual_keycode: Some(winit::event::VirtualKeyCode::F12), + state: winit::event::ElementState::Pressed, + .. + }, + .. + } => _debug.toggle(), + _ => {} + } } -- cgit From ef28347f1c816d8ad9e772303467de489efb802b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 28 May 2020 02:49:32 +0200 Subject: Write documentation for new `iced_winit` API --- winit/src/application.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index fcba47b3..df6e4eec 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -1,3 +1,4 @@ +//! Create interactive, native cross-platform applications. use crate::{ conversion, mouse, Clipboard, Command, Debug, Executor, Mode, Proxy, Runtime, Settings, Size, Subscription, @@ -72,6 +73,10 @@ pub trait Application: Program { } } +/// Runs an [`Application`] with an executor, compositor, and the provided +/// settings. +/// +/// [`Application`]: trait.Application.html pub fn run( settings: Settings, compositor_settings: C::Settings, @@ -254,6 +259,8 @@ pub fn run( }) } +/// Handles a `WindowEvent` and mutates the provided control flow, keyboard +/// modifiers, viewport, and resized flag accordingly. pub fn handle_window_event( event: &winit::event::WindowEvent<'_>, window: &winit::window::Window, -- cgit From 4aa0d7a13a6fbf04e3fa24c444d562c2f1085b5b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 28 May 2020 02:57:03 +0200 Subject: Write documentation for `iced_glutin` --- winit/src/application.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index df6e4eec..73ac72b2 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -18,6 +18,8 @@ use iced_native::program::{self, Program}; /// /// When using an [`Application`] with the `debug` feature enabled, a debug view /// can be toggled by pressing `F12`. +/// +/// [`Application`]: trait.Application.html pub trait Application: Program { /// The data needed to initialize your [`Application`]. /// @@ -36,7 +38,7 @@ pub trait Application: Program { /// /// [`Application`]: trait.Application.html /// [`run`]: #method.run.html - /// [`Settings`]: struct.Settings.html + /// [`Settings`]: ../settings/struct.Settings.html fn new(flags: Self::Flags) -> (Self, Command); /// Returns the current title of the [`Application`]. -- cgit