diff options
| -rw-r--r-- | core/src/keyboard/modifiers.rs | 12 | ||||
| -rw-r--r-- | examples/integration/src/main.rs | 35 | ||||
| -rw-r--r-- | glutin/src/application.rs | 12 | ||||
| -rw-r--r-- | native/src/widget/pane_grid.rs | 37 | ||||
| -rw-r--r-- | native/src/widget/pane_grid/content.rs | 21 | ||||
| -rw-r--r-- | native/src/widget/pick_list.rs | 15 | ||||
| -rw-r--r-- | native/src/window/event.rs | 8 | ||||
| -rw-r--r-- | wgpu/src/backend.rs | 19 | ||||
| -rw-r--r-- | wgpu/src/settings.rs | 6 | ||||
| -rw-r--r-- | wgpu/src/window/compositor.rs | 10 | ||||
| -rw-r--r-- | winit/src/conversion.rs | 6 | 
11 files changed, 119 insertions, 62 deletions
diff --git a/core/src/keyboard/modifiers.rs b/core/src/keyboard/modifiers.rs index 383b9370..e61f145a 100644 --- a/core/src/keyboard/modifiers.rs +++ b/core/src/keyboard/modifiers.rs @@ -28,6 +28,18 @@ bitflags! {  }  impl Modifiers { +    /// The "command" key. +    /// +    /// This is normally the main modifier to be used for hotkeys. +    /// +    /// On macOS, this is equivalent to `Self::LOGO`. +    /// Ohterwise, this is equivalent to `Self::CTRL`. +    pub const COMMAND: Self = if cfg!(target_os = "macos") { +        Self::LOGO +    } else { +        Self::CTRL +    }; +      /// Returns true if the [`SHIFT`] key is pressed in the [`Modifiers`].      pub fn shift(self) -> bool {          self.contains(Self::SHIFT) diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 9ef31203..6f319466 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -34,7 +34,7 @@ pub fn main() {      let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);      let surface = unsafe { instance.create_surface(&window) }; -    let (mut device, queue) = futures::executor::block_on(async { +    let (format, (mut device, queue)) = futures::executor::block_on(async {          let adapter = instance              .request_adapter(&wgpu::RequestAdapterOptions {                  power_preference: wgpu::PowerPreference::HighPerformance, @@ -43,21 +43,24 @@ pub fn main() {              .await              .expect("Request adapter"); -        adapter -            .request_device( -                &wgpu::DeviceDescriptor { -                    label: None, -                    features: wgpu::Features::empty(), -                    limits: wgpu::Limits::default(), -                }, -                None, -            ) -            .await -            .expect("Request device") +        ( +            adapter +                .get_swap_chain_preferred_format(&surface) +                .expect("Get preferred format"), +            adapter +                .request_device( +                    &wgpu::DeviceDescriptor { +                        label: None, +                        features: wgpu::Features::empty(), +                        limits: wgpu::Limits::default(), +                    }, +                    None, +                ) +                .await +                .expect("Request device"), +        )      }); -    let format = wgpu::TextureFormat::Bgra8UnormSrgb; -      let mut swap_chain = {          let size = window.inner_size(); @@ -65,7 +68,7 @@ pub fn main() {              &surface,              &wgpu::SwapChainDescriptor {                  usage: wgpu::TextureUsage::RENDER_ATTACHMENT, -                format: format, +                format,                  width: size.width,                  height: size.height,                  present_mode: wgpu::PresentMode::Mailbox, @@ -85,7 +88,7 @@ pub fn main() {      // Initialize iced      let mut debug = Debug::new();      let mut renderer = -        Renderer::new(Backend::new(&mut device, Settings::default())); +        Renderer::new(Backend::new(&mut device, Settings::default(), format));      let mut state = program::State::new(          controls, diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 991c8705..7ed6315d 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -146,7 +146,7 @@ async fn run_instance<A, E, C>(      mut runtime: Runtime<E, Proxy<A::Message>, A::Message>,      mut debug: Debug,      mut receiver: mpsc::UnboundedReceiver<glutin::event::Event<'_, A::Message>>, -    context: glutin::ContextWrapper<glutin::PossiblyCurrent, Window>, +    mut context: glutin::ContextWrapper<glutin::PossiblyCurrent, Window>,      exit_on_close_request: bool,  ) where      A: Application + 'static, @@ -255,6 +255,16 @@ async fn run_instance<A, E, C>(              }              event::Event::RedrawRequested(_) => {                  debug.render_started(); + +                #[allow(unsafe_code)] +                unsafe { +                    if !context.is_current() { +                        context = context +                            .make_current() +                            .expect("Make OpenGL context current"); +                    } +                } +                  let current_viewport_version = state.viewport_version();                  if viewport_version != current_viewport_version { diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index b72172cc..26a72409 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -452,24 +452,25 @@ where              _ => {}          } -        if self.state.picked_pane().is_none() { -            self.elements -                .iter_mut() -                .zip(layout.children()) -                .map(|((_, pane), layout)| { -                    pane.on_event( -                        event.clone(), -                        layout, -                        cursor_position, -                        renderer, -                        clipboard, -                        messages, -                    ) -                }) -                .fold(event_status, event::Status::merge) -        } else { -            event::Status::Captured -        } +        let picked_pane = self.state.picked_pane().map(|(pane, _)| pane); + +        self.elements +            .iter_mut() +            .zip(layout.children()) +            .map(|((pane, content), layout)| { +                let is_picked = picked_pane == Some(*pane); + +                content.on_event( +                    event.clone(), +                    layout, +                    cursor_position, +                    renderer, +                    clipboard, +                    messages, +                    is_picked, +                ) +            }) +            .fold(event_status, event::Status::merge)      }      fn draw( diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index b0110393..bac9fdd4 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -149,6 +149,7 @@ where          renderer: &Renderer,          clipboard: &mut dyn Clipboard,          messages: &mut Vec<Message>, +        is_picked: bool,      ) -> event::Status {          let mut event_status = event::Status::Ignored; @@ -169,14 +170,18 @@ where              layout          }; -        let body_status = self.body.on_event( -            event, -            body_layout, -            cursor_position, -            renderer, -            clipboard, -            messages, -        ); +        let body_status = if is_picked { +            event::Status::Ignored +        } else { +            self.body.on_event( +                event, +                body_layout, +                cursor_position, +                renderer, +                clipboard, +                messages, +            ) +        };          event_status.merge(body_status)      } diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index f4b60fc4..d7792000 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -1,5 +1,6 @@  //! Display a dropdown list of selectable values.  use crate::event::{self, Event}; +use crate::keyboard;  use crate::layout;  use crate::mouse;  use crate::overlay; @@ -20,6 +21,7 @@ where      [T]: ToOwned<Owned = Vec<T>>,  {      menu: &'a mut menu::State, +    keyboard_modifiers: &'a mut keyboard::Modifiers,      is_open: &'a mut bool,      hovered_option: &'a mut Option<usize>,      last_selection: &'a mut Option<T>, @@ -38,6 +40,7 @@ where  #[derive(Debug, Clone)]  pub struct State<T> {      menu: menu::State, +    keyboard_modifiers: keyboard::Modifiers,      is_open: bool,      hovered_option: Option<usize>,      last_selection: Option<T>, @@ -47,6 +50,7 @@ impl<T> Default for State<T> {      fn default() -> Self {          Self {              menu: menu::State::default(), +            keyboard_modifiers: keyboard::Modifiers::default(),              is_open: bool::default(),              hovered_option: Option::default(),              last_selection: Option::default(), @@ -71,6 +75,7 @@ where      ) -> Self {          let State {              menu, +            keyboard_modifiers,              is_open,              hovered_option,              last_selection, @@ -78,6 +83,7 @@ where          Self {              menu, +            keyboard_modifiers,              is_open,              hovered_option,              last_selection, @@ -270,7 +276,8 @@ where              }              Event::Mouse(mouse::Event::WheelScrolled {                  delta: mouse::ScrollDelta::Lines { y, .. }, -            }) if layout.bounds().contains(cursor_position) +            }) if self.keyboard_modifiers.command() +                && layout.bounds().contains(cursor_position)                  && !*self.is_open =>              {                  fn find_next<'a, T: PartialEq>( @@ -302,9 +309,13 @@ where                      messages.push((self.on_selected)(next_option.clone()));                  } -                return event::Status::Captured; +                event::Status::Captured              } +            Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) => { +                *self.keyboard_modifiers = modifiers; +                event::Status::Ignored +            }              _ => event::Status::Ignored,          }      } diff --git a/native/src/window/event.rs b/native/src/window/event.rs index 3aa1ab0b..64f2b8d8 100644 --- a/native/src/window/event.rs +++ b/native/src/window/event.rs @@ -3,6 +3,14 @@ use std::path::PathBuf;  /// A window-related event.  #[derive(PartialEq, Clone, Debug)]  pub enum Event { +    /// A window was moved. +    Moved { +        /// The new logical x location of the window +        x: i32, +        /// The new logical y location of the window +        y: i32, +    }, +      /// A window was resized.      Resized {          /// The new width of the window (in units) diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 783079f3..4f34045b 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -30,23 +30,24 @@ pub struct Backend {  impl Backend {      /// Creates a new [`Backend`]. -    pub fn new(device: &wgpu::Device, settings: Settings) -> Self { +    pub fn new( +        device: &wgpu::Device, +        settings: Settings, +        format: wgpu::TextureFormat, +    ) -> Self {          let text_pipeline = text::Pipeline::new(              device, -            settings.format, +            format,              settings.default_font,              settings.text_multithreading,          ); -        let quad_pipeline = quad::Pipeline::new(device, settings.format); -        let triangle_pipeline = triangle::Pipeline::new( -            device, -            settings.format, -            settings.antialiasing, -        ); +        let quad_pipeline = quad::Pipeline::new(device, format); +        let triangle_pipeline = +            triangle::Pipeline::new(device, format, settings.antialiasing);          #[cfg(any(feature = "image_rs", feature = "svg"))] -        let image_pipeline = image::Pipeline::new(device, settings.format); +        let image_pipeline = image::Pipeline::new(device, format);          Self {              quad_pipeline, diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 9a7eed34..dc06b82d 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -6,11 +6,6 @@ pub use crate::Antialiasing;  /// [`Backend`]: crate::Backend  #[derive(Debug, Clone, Copy, PartialEq, Eq)]  pub struct Settings { -    /// The output format of the [`Backend`]. -    /// -    /// [`Backend`]: crate::Backend -    pub format: wgpu::TextureFormat, -      /// The present mode of the [`Backend`].      ///      /// [`Backend`]: crate::Backend @@ -68,7 +63,6 @@ impl Settings {  impl Default for Settings {      fn default() -> Settings {          Settings { -            format: wgpu::TextureFormat::Bgra8UnormSrgb,              present_mode: wgpu::PresentMode::Mailbox,              internal_backend: wgpu::BackendBit::PRIMARY,              default_font: None, diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index fb25fca4..b60efd25 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -13,6 +13,7 @@ pub struct Compositor {      queue: wgpu::Queue,      staging_belt: wgpu::util::StagingBelt,      local_pool: futures::executor::LocalPool, +    format: wgpu::TextureFormat,  }  impl Compositor { @@ -42,6 +43,10 @@ impl Compositor {              })              .await?; +        let format = compatible_surface +            .as_ref() +            .and_then(|surf| adapter.get_swap_chain_preferred_format(surf))?; +          let (device, queue) = adapter              .request_device(                  &wgpu::DeviceDescriptor { @@ -69,12 +74,13 @@ impl Compositor {              queue,              staging_belt,              local_pool, +            format,          })      }      /// Creates a new rendering [`Backend`] for this [`Compositor`].      pub fn create_backend(&self) -> Backend { -        Backend::new(&self.device, self.settings) +        Backend::new(&self.device, self.settings, self.format)      }  } @@ -119,7 +125,7 @@ impl iced_graphics::window::Compositor for Compositor {              surface,              &wgpu::SwapChainDescriptor {                  usage: wgpu::TextureUsage::RENDER_ATTACHMENT, -                format: self.settings.format, +                format: self.format,                  present_mode: self.settings.present_mode,                  width,                  height, diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index b3d05857..e0934f43 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -130,6 +130,12 @@ pub fn window_event(          WindowEvent::Touch(touch) => {              Some(Event::Touch(touch_event(*touch, scale_factor)))          } +        WindowEvent::Moved(position) => { +            let winit::dpi::LogicalPosition { x, y } = +                position.to_logical(scale_factor); + +            Some(Event::Window(window::Event::Moved { x, y })) +        }          _ => None,      }  }  | 
