diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | examples/scrollable/Cargo.toml | 2 | ||||
-rw-r--r-- | examples/scrollable/src/main.rs | 41 | ||||
-rw-r--r-- | graphics/src/widget/scrollable.rs | 10 | ||||
-rw-r--r-- | graphics/src/window/compositor.rs | 5 | ||||
-rw-r--r-- | rustfmt.toml | 1 | ||||
-rw-r--r-- | src/application.rs | 1 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/window/mode.rs | 3 | ||||
-rw-r--r-- | wgpu/src/image/vector.rs | 22 | ||||
-rw-r--r-- | wgpu/src/window/compositor.rs | 23 | ||||
-rw-r--r-- | winit/src/application.rs | 4 | ||||
-rw-r--r-- | winit/src/application/state.rs | 2 | ||||
-rw-r--r-- | winit/src/conversion.rs | 10 | ||||
-rw-r--r-- | winit/src/mode.rs | 3 | ||||
-rw-r--r-- | winit/src/settings.rs | 3 |
16 files changed, 90 insertions, 44 deletions
@@ -102,4 +102,4 @@ iced_web = { version = "0.4", path = "web" } [package.metadata.docs.rs] rustdoc-args = ["--cfg", "docsrs"] -features = ["image", "svg", "canvas"] +features = ["image", "svg", "canvas", "qr_code"] diff --git a/examples/scrollable/Cargo.toml b/examples/scrollable/Cargo.toml index 12753fb6..08502458 100644 --- a/examples/scrollable/Cargo.toml +++ b/examples/scrollable/Cargo.toml @@ -6,4 +6,4 @@ edition = "2018" publish = false [dependencies] -iced = { path = "../.." } +iced = { path = "../..", features = ["debug"] } diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 8dd2e20c..a570f0f6 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -1,8 +1,8 @@ mod style; use iced::{ - scrollable, Column, Container, Element, Length, Radio, Row, Rule, Sandbox, - Scrollable, Settings, Space, Text, + button, scrollable, Button, Column, Container, Element, Length, Radio, Row, + Rule, Sandbox, Scrollable, Settings, Space, Text, }; pub fn main() -> iced::Result { @@ -63,12 +63,14 @@ impl Sandbox for ScrollableDemo { variants .iter_mut() .map(|variant| { - let mut scrollable = Scrollable::new(&mut variant.state) - .padding(10) - .width(Length::Fill) - .height(Length::Fill) - .style(*theme) - .push(Text::new(variant.title)); + let mut scrollable = + Scrollable::new(&mut variant.scrollable) + .padding(10) + .spacing(10) + .width(Length::Fill) + .height(Length::Fill) + .style(*theme) + .push(Text::new(variant.title)); if let Some(scrollbar_width) = variant.scrollbar_width { scrollable = scrollable @@ -108,6 +110,14 @@ impl Sandbox for ScrollableDemo { .push(Space::with_height(Length::Units(1200))) .push(Text::new("Middle")) .push(Space::with_height(Length::Units(1200))) + .push( + Button::new( + &mut variant.button, + Text::new("I am a button"), + ) + .width(Length::Fill) + .padding(10), + ) .push(Text::new("The End.")); Container::new(scrollable) @@ -142,7 +152,8 @@ impl Sandbox for ScrollableDemo { /// A version of a scrollable struct Variant { title: &'static str, - state: scrollable::State, + scrollable: scrollable::State, + button: button::State, scrollbar_width: Option<u16>, scrollbar_margin: Option<u16>, scroller_width: Option<u16>, @@ -153,28 +164,32 @@ impl Variant { vec![ Self { title: "Default Scrollbar", - state: scrollable::State::new(), + scrollable: scrollable::State::new(), + button: button::State::new(), scrollbar_width: None, scrollbar_margin: None, scroller_width: None, }, Self { title: "Slimmed & Margin", - state: scrollable::State::new(), + scrollable: scrollable::State::new(), + button: button::State::new(), scrollbar_width: Some(4), scrollbar_margin: Some(3), scroller_width: Some(4), }, Self { title: "Wide Scroller", - state: scrollable::State::new(), + scrollable: scrollable::State::new(), + button: button::State::new(), scrollbar_width: Some(4), scrollbar_margin: None, scroller_width: Some(10), }, Self { title: "Narrow Scroller", - state: scrollable::State::new(), + scrollable: scrollable::State::new(), + button: button::State::new(), scrollbar_width: Some(10), scrollbar_margin: None, scroller_width: Some(4), diff --git a/graphics/src/widget/scrollable.rs b/graphics/src/widget/scrollable.rs index 57065ba2..2220e4b8 100644 --- a/graphics/src/widget/scrollable.rs +++ b/graphics/src/widget/scrollable.rs @@ -134,8 +134,16 @@ where Primitive::None }; + let scroll = Primitive::Clip { + bounds, + offset: Vector::new(0, 0), + content: Box::new(Primitive::Group { + primitives: vec![scrollbar, scroller], + }), + }; + Primitive::Group { - primitives: vec![clip, scrollbar, scroller], + primitives: vec![clip, scroll], } } else { content diff --git a/graphics/src/window/compositor.rs b/graphics/src/window/compositor.rs index 0bc8cbc8..7d5d789b 100644 --- a/graphics/src/window/compositor.rs +++ b/graphics/src/window/compositor.rs @@ -17,7 +17,10 @@ pub trait Compositor: Sized { type SwapChain; /// Creates a new [`Compositor`]. - fn new(settings: Self::Settings) -> Result<(Self, Self::Renderer), Error>; + fn new<W: HasRawWindowHandle>( + settings: Self::Settings, + compatible_window: Option<&W>, + ) -> Result<(Self, Self::Renderer), Error>; /// Crates a new [`Surface`] for the given window. /// diff --git a/rustfmt.toml b/rustfmt.toml index d979d317..fa50ab92 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,2 @@ max_width=80 +edition="2018" diff --git a/src/application.rs b/src/application.rs index 7b7de6d4..ee532e0b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -277,6 +277,7 @@ where match self.0.mode() { window::Mode::Windowed => iced_winit::Mode::Windowed, window::Mode::Fullscreen => iced_winit::Mode::Fullscreen, + window::Mode::Hidden => iced_winit::Mode::Hidden, } } @@ -30,7 +30,7 @@ //! [windowing shell]: https://github.com/hecrj/iced/tree/master/winit //! [`dodrio`]: https://github.com/fitzgen/dodrio //! [web runtime]: https://github.com/hecrj/iced/tree/master/web -//! [examples]: https://github.com/hecrj/iced/tree/0.2/examples +//! [examples]: https://github.com/hecrj/iced/tree/0.3/examples //! [repository]: https://github.com/hecrj/iced //! //! # Overview diff --git a/src/window/mode.rs b/src/window/mode.rs index 37464711..fdce8e23 100644 --- a/src/window/mode.rs +++ b/src/window/mode.rs @@ -6,4 +6,7 @@ pub enum Mode { /// The application takes the whole screen of its current monitor. Fullscreen, + + /// The application is hidden + Hidden, } diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index ab0f67d0..8c7de617 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -1,7 +1,8 @@ -use crate::image::atlas::{self, Atlas}; use iced_native::svg; use std::collections::{HashMap, HashSet}; +use crate::image::atlas::{self, Atlas}; + pub enum Svg { Loaded(usvg::Tree), NotFound, @@ -111,26 +112,13 @@ impl Cache { let width = img.width(); let height = img.height(); - let mut rgba = img.take().into_iter(); - - // TODO: Perform conversion in the GPU - let bgra: Vec<u8> = std::iter::from_fn(move || { - use std::iter::once; - - let r = rgba.next()?; - let g = rgba.next()?; - let b = rgba.next()?; - let a = rgba.next()?; - - Some(once(b).chain(once(g)).chain(once(r)).chain(once(a))) - }) - .flatten() - .collect(); + let mut rgba = img.take(); + rgba.chunks_exact_mut(4).for_each(|rgba| rgba.swap(0, 2)); let allocation = texture_atlas.upload( width, height, - bytemuck::cast_slice(bgra.as_slice()), + bytemuck::cast_slice(rgba.as_slice()), device, encoder, )?; diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index fdd648e8..aa873df8 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -21,9 +21,16 @@ impl Compositor { /// Requests a new [`Compositor`] with the given [`Settings`]. /// /// Returns `None` if no compatible graphics adapter could be found. - pub async fn request(settings: Settings) -> Option<Self> { + pub async fn request<W: HasRawWindowHandle>( + settings: Settings, + compatible_window: Option<&W>, + ) -> Option<Self> { let instance = wgpu::Instance::new(settings.internal_backend); + #[allow(unsafe_code)] + let compatible_surface = compatible_window + .map(|window| unsafe { instance.create_surface(window) }); + let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: if settings.antialiasing.is_none() { @@ -31,7 +38,7 @@ impl Compositor { } else { wgpu::PowerPreference::HighPerformance }, - compatible_surface: None, + compatible_surface: compatible_surface.as_ref(), }) .await?; @@ -77,9 +84,15 @@ impl iced_graphics::window::Compositor for Compositor { type Surface = wgpu::Surface; type SwapChain = wgpu::SwapChain; - fn new(settings: Self::Settings) -> Result<(Self, Renderer), Error> { - let compositor = futures::executor::block_on(Self::request(settings)) - .ok_or(Error::AdapterNotFound)?; + fn new<W: HasRawWindowHandle>( + settings: Self::Settings, + compatible_window: Option<&W>, + ) -> Result<(Self, Renderer), Error> { + let compositor = futures::executor::block_on(Self::request( + settings, + compatible_window, + )) + .ok_or(Error::AdapterNotFound)?; let backend = compositor.create_backend(); diff --git a/winit/src/application.rs b/winit/src/application.rs index 106d5218..b1d5f418 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -118,8 +118,6 @@ where let mut debug = Debug::new(); debug.startup_started(); - let (compositor, renderer) = C::new(compositor_settings)?; - let event_loop = EventLoop::with_user_event(); let mut runtime = { @@ -150,6 +148,8 @@ where .build(&event_loop) .map_err(Error::WindowCreationFailed)?; + let (compositor, renderer) = C::new(compositor_settings, Some(&window))?; + let (mut sender, receiver) = mpsc::unbounded(); let mut instance = Box::pin(run_instance::<A, E, C>( diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index 46297370..b54d3aed 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -182,6 +182,8 @@ impl<A: Application> State<A> { new_mode, )); + window.set_visible(conversion::visible(new_mode)); + self.mode = new_mode; } diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 0fa27413..b850a805 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -141,13 +141,21 @@ pub fn fullscreen( mode: Mode, ) -> Option<winit::window::Fullscreen> { match mode { - Mode::Windowed => None, + Mode::Windowed | Mode::Hidden => None, Mode::Fullscreen => { Some(winit::window::Fullscreen::Borderless(monitor)) } } } +/// Converts a [`Mode`] to a visibility flag. +pub fn visible(mode: Mode) -> bool { + match mode { + Mode::Windowed | Mode::Fullscreen => true, + Mode::Hidden => false, + } +} + /// Converts a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon. /// /// [`winit`]: https://github.com/rust-windowing/winit diff --git a/winit/src/mode.rs b/winit/src/mode.rs index 37464711..fdce8e23 100644 --- a/winit/src/mode.rs +++ b/winit/src/mode.rs @@ -6,4 +6,7 @@ pub enum Mode { /// The application takes the whole screen of its current monitor. Fullscreen, + + /// The application is hidden + Hidden, } diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 9ce5cfc5..663fa07a 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -80,7 +80,8 @@ impl Window { .with_transparent(self.transparent) .with_window_icon(self.icon) .with_always_on_top(self.always_on_top) - .with_fullscreen(conversion::fullscreen(primary_monitor, mode)); + .with_fullscreen(conversion::fullscreen(primary_monitor, mode)) + .with_visible(conversion::visible(mode)); if let Some((width, height)) = self.min_size { window_builder = window_builder |