diff options
author | 2023-03-04 05:37:11 +0100 | |
---|---|---|
committer | 2023-03-04 05:37:11 +0100 | |
commit | 3a0d34c0240f4421737a6a08761f99d6f8140d02 (patch) | |
tree | c9a4a6b8e9c1db1b8fcd05bc98e3f131d5ef4bd5 /winit | |
parent | c54409d1711e1f615c7ea4b02c082954e340632a (diff) | |
download | iced-3a0d34c0240f4421737a6a08761f99d6f8140d02.tar.gz iced-3a0d34c0240f4421737a6a08761f99d6f8140d02.tar.bz2 iced-3a0d34c0240f4421737a6a08761f99d6f8140d02.zip |
Create `iced_widget` subcrate and re-organize the whole codebase
Diffstat (limited to 'winit')
-rw-r--r-- | winit/Cargo.toml | 6 | ||||
-rw-r--r-- | winit/src/application.rs | 77 | ||||
-rw-r--r-- | winit/src/application/state.rs | 14 | ||||
-rw-r--r-- | winit/src/clipboard.rs | 7 | ||||
-rw-r--r-- | winit/src/conversion.rs | 11 | ||||
-rw-r--r-- | winit/src/error.rs | 7 | ||||
-rw-r--r-- | winit/src/lib.rs | 8 | ||||
-rw-r--r-- | winit/src/proxy.rs | 2 | ||||
-rw-r--r-- | winit/src/system.rs | 7 | ||||
-rw-r--r-- | winit/src/window.rs | 52 |
10 files changed, 90 insertions, 101 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml index 60e464c6..21c14f68 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -35,9 +35,9 @@ path = "../native" version = "0.7" path = "../graphics" -[dependencies.iced_futures] -version = "0.6" -path = "../futures" +[dependencies.iced_style] +version = "0.7" +path = "../style" [dependencies.tracing] version = "0.1.37" diff --git a/winit/src/application.rs b/winit/src/application.rs index b52f0197..c8162c9b 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -5,25 +5,25 @@ mod state; pub use state::State; -use crate::clipboard::{self, Clipboard}; use crate::conversion; -use crate::mouse; -use crate::renderer; -use crate::widget::operation; -use crate::{ - Command, Debug, Error, Event, Executor, Proxy, Runtime, Settings, Size, - Subscription, -}; - -use iced_futures::futures; -use iced_futures::futures::channel::mpsc; -use iced_graphics::window; -use iced_graphics::window::compositor; -use iced_native::program::Program; -use iced_native::time::Instant; -use iced_native::user_interface::{self, UserInterface}; - -pub use iced_native::application::{Appearance, StyleSheet}; +use crate::core; +use crate::core::mouse; +use crate::core::renderer; +use crate::core::time::Instant; +use crate::core::widget::operation; +use crate::core::window; +use crate::core::{Event, Size}; +use crate::futures::futures; +use crate::futures::Executor; +use crate::graphics::compositor::{self, Compositor}; +use crate::native::clipboard; +use crate::native::program::Program; +use crate::native::user_interface::{self, UserInterface}; +use crate::native::{Command, Debug, Runtime, Subscription}; +use crate::style::application::{Appearance, StyleSheet}; +use crate::{Clipboard, Error, Proxy, Settings}; + +use futures::channel::mpsc; use std::mem::ManuallyDrop; @@ -45,7 +45,7 @@ use tracing::{info_span, instrument::Instrument}; /// can be toggled by pressing `F12`. pub trait Application: Program where - <Self::Renderer as crate::Renderer>::Theme: StyleSheet, + <Self::Renderer as core::Renderer>::Theme: StyleSheet, { /// The data needed to initialize your [`Application`]. type Flags; @@ -67,12 +67,12 @@ where fn title(&self) -> String; /// Returns the current `Theme` of the [`Application`]. - fn theme(&self) -> <Self::Renderer as crate::Renderer>::Theme; + fn theme(&self) -> <Self::Renderer as core::Renderer>::Theme; /// Returns the `Style` variation of the `Theme`. fn style( &self, - ) -> <<Self::Renderer as crate::Renderer>::Theme as StyleSheet>::Style { + ) -> <<Self::Renderer as core::Renderer>::Theme as StyleSheet>::Style { Default::default() } @@ -112,8 +112,8 @@ pub fn run<A, E, C>( where A: Application + 'static, E: Executor + 'static, - C: window::Compositor<Renderer = A::Renderer> + 'static, - <A::Renderer as crate::Renderer>::Theme: StyleSheet, + C: Compositor<Renderer = A::Renderer> + 'static, + <A::Renderer as core::Renderer>::Theme: StyleSheet, { use futures::task; use futures::Future; @@ -278,10 +278,10 @@ async fn run_instance<A, E, C>( ) where A: Application + 'static, E: Executor + 'static, - C: window::Compositor<Renderer = A::Renderer> + 'static, - <A::Renderer as crate::Renderer>::Theme: StyleSheet, + C: Compositor<Renderer = A::Renderer> + 'static, + <A::Renderer as core::Renderer>::Theme: StyleSheet, { - use iced_futures::futures::stream::StreamExt; + use futures::stream::StreamExt; use winit::event; use winit::event_loop::ControlFlow; @@ -411,7 +411,7 @@ async fn run_instance<A, E, C>( // Then, we can use the `interface_state` here to decide if a redraw // is needed right away, or simply wait until a specific time. let redraw_event = Event::Window( - crate::window::Event::RedrawRequested(Instant::now()), + window::Event::RedrawRequested(Instant::now()), ); let (interface_state, _) = user_interface.update( @@ -442,17 +442,14 @@ async fn run_instance<A, E, C>( } window.request_redraw(); - runtime - .broadcast((redraw_event, crate::event::Status::Ignored)); + runtime.broadcast((redraw_event, core::event::Status::Ignored)); let _ = control_sender.start_send(match interface_state { user_interface::State::Updated { redraw_request: Some(redraw_request), } => match redraw_request { - crate::window::RedrawRequest::NextFrame => { - ControlFlow::Poll - } - crate::window::RedrawRequest::At(at) => { + window::RedrawRequest::NextFrame => ControlFlow::Poll, + window::RedrawRequest::At(at) => { ControlFlow::WaitUntil(at) } }, @@ -464,9 +461,9 @@ async fn run_instance<A, E, C>( event::Event::PlatformSpecific(event::PlatformSpecific::MacOS( event::MacOS::ReceivedUrl(url), )) => { - use iced_native::event; + use crate::core::event; - events.push(iced_native::Event::PlatformSpecific( + events.push(Event::PlatformSpecific( event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl( url, )), @@ -615,7 +612,7 @@ pub fn build_user_interface<'a, A: Application>( debug: &mut Debug, ) -> UserInterface<'a, A::Message, A::Renderer> where - <A::Renderer as crate::Renderer>::Theme: StyleSheet, + <A::Renderer as core::Renderer>::Theme: StyleSheet, { #[cfg(feature = "trace")] let view_span = info_span!("Application", "VIEW").entered(); @@ -656,7 +653,7 @@ pub fn update<A: Application, E: Executor>( window: &winit::window::Window, graphics_info: impl FnOnce() -> compositor::Information + Copy, ) where - <A::Renderer as crate::Renderer>::Theme: StyleSheet, + <A::Renderer as core::Renderer>::Theme: StyleSheet, { for message in messages.drain(..) { #[cfg(feature = "trace")] @@ -708,7 +705,7 @@ pub fn run_command<A, E>( ) where A: Application, E: Executor, - <A::Renderer as crate::Renderer>::Theme: StyleSheet, + <A::Renderer as core::Renderer>::Theme: StyleSheet, { use iced_native::command; use iced_native::system; @@ -767,7 +764,7 @@ pub fn run_command<A, E>( let mode = if window.is_visible().unwrap_or(true) { conversion::mode(window.fullscreen()) } else { - window::Mode::Hidden + core::window::Mode::Hidden }; proxy @@ -849,7 +846,7 @@ pub fn run_command<A, E>( *cache = current_cache; } command::Action::LoadFont { bytes, tagger } => { - use crate::text::Renderer; + use crate::core::text::Renderer; // TODO: Error handling (?) renderer.load_font(bytes); diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs index 8d6a1df1..b727e03c 100644 --- a/winit/src/application/state.rs +++ b/winit/src/application/state.rs @@ -1,6 +1,10 @@ use crate::application::{self, StyleSheet as _}; use crate::conversion; -use crate::{Application, Color, Debug, Point, Size, Viewport}; +use crate::core; +use crate::core::{Color, Point, Size}; +use crate::graphics::Viewport; +use crate::native::Debug; +use crate::Application; use std::marker::PhantomData; use winit::event::{Touch, WindowEvent}; @@ -10,7 +14,7 @@ use winit::window::Window; #[allow(missing_debug_implementations)] pub struct State<A: Application> where - <A::Renderer as crate::Renderer>::Theme: application::StyleSheet, + <A::Renderer as core::Renderer>::Theme: application::StyleSheet, { title: String, scale_factor: f64, @@ -18,14 +22,14 @@ where viewport_version: usize, cursor_position: winit::dpi::PhysicalPosition<f64>, modifiers: winit::event::ModifiersState, - theme: <A::Renderer as crate::Renderer>::Theme, + theme: <A::Renderer as core::Renderer>::Theme, appearance: application::Appearance, application: PhantomData<A>, } impl<A: Application> State<A> where - <A::Renderer as crate::Renderer>::Theme: application::StyleSheet, + <A::Renderer as core::Renderer>::Theme: application::StyleSheet, { /// Creates a new [`State`] for the provided [`Application`] and window. pub fn new(application: &A, window: &Window) -> Self { @@ -98,7 +102,7 @@ where } /// Returns the current theme of the [`State`]. - pub fn theme(&self) -> &<A::Renderer as crate::Renderer>::Theme { + pub fn theme(&self) -> &<A::Renderer as core::Renderer>::Theme { &self.theme } diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index c1fd8813..22509130 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -1,7 +1,6 @@ //! Access the clipboard. -pub use iced_native::clipboard::Action; - -use crate::command::{self, Command}; +use crate::native::clipboard::Action; +use crate::native::command::{self, Command}; /// A buffer for short-term storage and transfer within and between /// applications. @@ -56,7 +55,7 @@ impl Clipboard { } } -impl iced_native::Clipboard for Clipboard { +impl crate::core::Clipboard for Clipboard { fn read(&self) -> Option<String> { self.read() } diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 1b2ead36..0759ad9d 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -2,11 +2,12 @@ //! //! [`winit`]: https://github.com/rust-windowing/winit //! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.8/native -use crate::keyboard; -use crate::mouse; -use crate::touch; -use crate::window; -use crate::{Event, Point, Position}; +use crate::core::keyboard; +use crate::core::mouse; +use crate::core::touch; +use crate::core::window; +use crate::core::{Event, Point}; +use crate::Position; /// Converts a winit window event into an iced event. pub fn window_event( diff --git a/winit/src/error.rs b/winit/src/error.rs index eaeafd51..7687fb17 100644 --- a/winit/src/error.rs +++ b/winit/src/error.rs @@ -1,4 +1,5 @@ -use iced_futures::futures; +use crate::futures::futures; +use crate::graphics; /// An error that occurred while running an application. #[derive(Debug, thiserror::Error)] @@ -13,10 +14,10 @@ pub enum Error { /// The application graphics context could not be created. #[error("the application graphics context could not be created")] - GraphicsCreationFailed(iced_graphics::Error), + GraphicsCreationFailed(graphics::Error), } -impl From<iced_graphics::Error> for Error { +impl From<graphics::Error> for Error { fn from(error: iced_graphics::Error) -> Error { Error::GraphicsCreationFailed(error) } diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 3a33e174..0d8c04d3 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -30,9 +30,11 @@ #![forbid(rust_2018_idioms, unsafe_code)] #![allow(clippy::inherent_to_string, clippy::type_complexity)] #![cfg_attr(docsrs, feature(doc_cfg))] - -#[doc(no_inline)] -pub use iced_native::*; +pub use iced_graphics as graphics; +pub use iced_native as native; +pub use iced_native::core; +pub use iced_native::futures; +pub use iced_style as style; pub use winit; #[cfg(feature = "application")] diff --git a/winit/src/proxy.rs b/winit/src/proxy.rs index 7b9074d7..1d6c48bb 100644 --- a/winit/src/proxy.rs +++ b/winit/src/proxy.rs @@ -1,4 +1,4 @@ -use iced_native::futures::{ +use crate::futures::futures::{ channel::mpsc, task::{Context, Poll}, Sink, diff --git a/winit/src/system.rs b/winit/src/system.rs index 8a7b2a11..3a6a8a8e 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -1,8 +1,7 @@ //! Access the native system. -use crate::command::{self, Command}; -pub use iced_native::system::*; - -use iced_graphics::window::compositor; +use crate::graphics::compositor; +use crate::native::command::{self, Command}; +use crate::native::system::{Action, Information}; /// Query for available system information. pub fn fetch_information<Message>( diff --git a/winit/src/window.rs b/winit/src/window.rs index 961562bd..6ac58e20 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -1,68 +1,58 @@ //! Interact with the window of your application. -use crate::command::{self, Command}; -use iced_native::window; - -pub use window::{frames, Event, Mode, RedrawRequest, UserAttention}; +use crate::core::window::{Mode, UserAttention}; +use crate::native::command::{self, Command}; +use crate::native::window::Action; /// Closes the current window and exits the application. pub fn close<Message>() -> Command<Message> { - Command::single(command::Action::Window(window::Action::Close)) + Command::single(command::Action::Window(Action::Close)) } /// Begins dragging the window while the left mouse button is held. pub fn drag<Message>() -> Command<Message> { - Command::single(command::Action::Window(window::Action::Drag)) + Command::single(command::Action::Window(Action::Drag)) } /// Resizes the window to the given logical dimensions. pub fn resize<Message>(width: u32, height: u32) -> Command<Message> { - Command::single(command::Action::Window(window::Action::Resize { - width, - height, - })) + Command::single(command::Action::Window(Action::Resize { width, height })) } /// Maximizes the window. pub fn maximize<Message>(maximized: bool) -> Command<Message> { - Command::single(command::Action::Window(window::Action::Maximize( - maximized, - ))) + Command::single(command::Action::Window(Action::Maximize(maximized))) } /// Minimes the window. pub fn minimize<Message>(minimized: bool) -> Command<Message> { - Command::single(command::Action::Window(window::Action::Minimize( - minimized, - ))) + Command::single(command::Action::Window(Action::Minimize(minimized))) } /// Moves a window to the given logical coordinates. pub fn move_to<Message>(x: i32, y: i32) -> Command<Message> { - Command::single(command::Action::Window(window::Action::Move { x, y })) + Command::single(command::Action::Window(Action::Move { x, y })) } /// Sets the [`Mode`] of the window. pub fn change_mode<Message>(mode: Mode) -> Command<Message> { - Command::single(command::Action::Window(window::Action::ChangeMode(mode))) + Command::single(command::Action::Window(Action::ChangeMode(mode))) } /// Fetches the current [`Mode`] of the window. pub fn fetch_mode<Message>( f: impl FnOnce(Mode) -> Message + 'static, ) -> Command<Message> { - Command::single(command::Action::Window(window::Action::FetchMode( - Box::new(f), - ))) + Command::single(command::Action::Window(Action::FetchMode(Box::new(f)))) } /// Toggles the window to maximized or back. pub fn toggle_maximize<Message>() -> Command<Message> { - Command::single(command::Action::Window(window::Action::ToggleMaximize)) + Command::single(command::Action::Window(Action::ToggleMaximize)) } /// Toggles the window decorations. pub fn toggle_decorations<Message>() -> Command<Message> { - Command::single(command::Action::Window(window::Action::ToggleDecorations)) + Command::single(command::Action::Window(Action::ToggleDecorations)) } /// Request user attention to the window, this has no effect if the application @@ -74,9 +64,9 @@ pub fn toggle_decorations<Message>() -> Command<Message> { pub fn request_user_attention<Message>( user_attention: Option<UserAttention>, ) -> Command<Message> { - Command::single(command::Action::Window( - window::Action::RequestUserAttention(user_attention), - )) + Command::single(command::Action::Window(Action::RequestUserAttention( + user_attention, + ))) } /// Brings the window to the front and sets input focus. Has no effect if the window is @@ -86,21 +76,17 @@ pub fn request_user_attention<Message>( /// you are certain that's what the user wants. Focus stealing can cause an extremely disruptive /// user experience. pub fn gain_focus<Message>() -> Command<Message> { - Command::single(command::Action::Window(window::Action::GainFocus)) + Command::single(command::Action::Window(Action::GainFocus)) } /// Changes whether or not the window will always be on top of other windows. pub fn change_always_on_top<Message>(on_top: bool) -> Command<Message> { - Command::single(command::Action::Window(window::Action::ChangeAlwaysOnTop( - on_top, - ))) + Command::single(command::Action::Window(Action::ChangeAlwaysOnTop(on_top))) } /// Fetches an identifier unique to the window. pub fn fetch_id<Message>( f: impl FnOnce(u64) -> Message + 'static, ) -> Command<Message> { - Command::single(command::Action::Window(window::Action::FetchId(Box::new( - f, - )))) + Command::single(command::Action::Window(Action::FetchId(Box::new(f)))) } |