This commit is contained in:
Ashley Wulber 2024-10-16 15:20:36 -04:00
parent 8fb1e21873
commit 757d0753ad
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
14 changed files with 146 additions and 2521 deletions

View file

@ -28,7 +28,7 @@ wgpu-bare = ["iced_renderer/wgpu-bare", "iced_widget/wgpu"]
# Enables the `tiny-skia` software renderer # Enables the `tiny-skia` software renderer
default = ["tiny-skia", "x11", "wayland", "tokio"] default = ["tiny-skia", "tokio"]
# Enable the `tiny-skia` software renderer backend # Enable the `tiny-skia` software renderer backend
tiny-skia = ["iced_renderer/tiny-skia"] tiny-skia = ["iced_renderer/tiny-skia"]
# Enables the `image` widget # Enables the `image` widget
@ -116,7 +116,11 @@ a11y = [
"iced_winit?/a11y", "iced_winit?/a11y",
] ]
# Enables the winit shell. Conflicts with `wayland` and `glutin`. # Enables the winit shell. Conflicts with `wayland` and `glutin`.
winit = ["iced_winit", "iced_accessibility?/accesskit_winit"] winit = [
"iced_winit",
"iced_accessibility?/accesskit_winit",
"iced_program/winit",
]
# Enables the sctk shell. # Enables the sctk shell.
wayland = ["iced_widget/wayland", "iced_core/wayland", "iced_winit/wayland"] wayland = ["iced_widget/wayland", "iced_core/wayland", "iced_winit/wayland"]
[dependencies] [dependencies]

View file

@ -10,7 +10,6 @@ pub use nested::Nested;
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
use crate::renderer; use crate::renderer;
use crate::widget::Operation;
use crate::widget::Tree; use crate::widget::Tree;
use crate::{Clipboard, Event, Layout, Rectangle, Shell, Size, Vector}; use crate::{Clipboard, Event, Layout, Rectangle, Shell, Size, Vector};

View file

@ -15,6 +15,7 @@ rust-version.workspace = true
workspace = true workspace = true
[features] [features]
winit = []
debug = [] debug = []
time-travel = [] time-travel = []

View file

@ -1,6 +1,7 @@
//! The definition of an iced program. //! The definition of an iced program.
pub use iced_graphics as graphics; pub use iced_graphics as graphics;
pub use iced_runtime as runtime; pub use iced_runtime as runtime;
pub use iced_runtime::Task;
pub use iced_runtime::core; pub use iced_runtime::core;
pub use iced_runtime::futures; pub use iced_runtime::futures;
@ -17,14 +18,6 @@ use crate::core::window;
use crate::core::{Element, Font, Settings}; use crate::core::{Element, Font, Settings};
use crate::futures::{Executor, Subscription}; use crate::futures::{Executor, Subscription};
use crate::graphics::compositor; use crate::graphics::compositor;
use crate::runtime::task::Task;
#[cfg(any(feature = "winit", feature = "wayland"))]
use crate::shell;
#[cfg(any(feature = "winit", feature = "wayland"))]
pub use crate::shell::program::{Appearance, DefaultStyle};
#[cfg(not(any(feature = "winit", feature = "wayland")))]
pub use crate::runtime::{Appearance, DefaultStyle};
/// The internal definition of a [`Program`]. /// The internal definition of a [`Program`].
/// ///
@ -124,138 +117,138 @@ pub trait Program: Sized {
&[] &[]
} }
#[cfg(any(feature = "winit", feature = "wayland"))] // #[cfg(feature = "winit")]
/// Runs the [`Program`]. // /// Runs the [`Program`].
/// // ///
/// The state of the [`Program`] must implement [`Default`]. // /// The state of the [`Program`] must implement [`Default`].
/// If your state does not implement [`Default`], use [`run_with`] // /// If your state does not implement [`Default`], use [`run_with`]
/// instead. // /// instead.
/// // ///
/// [`run_with`]: Self::run_with // /// [`run_with`]: Self::run_with
fn run( // fn run(
self, // self,
settings: Settings, // settings: crate::Settings,
window_settings: Option<window::Settings>, // window_settings: Option<window::Settings>,
) -> Result // ) -> crate::Result
where // where
Self: 'static, // Self: 'static,
Self::State: Default, // Self::State: Default,
{ // {
self.run_with(settings, window_settings, || { // self.run_with(settings, window_settings, || {
(Self::State::default(), Task::none()) // (Self::State::default(), Task::none())
}) // })
} // }
#[cfg(any(feature = "winit", feature = "wayland"))] // #[cfg(feature = "winit")]
/// Runs the [`Program`] with the given [`Settings`] and a closure that creates the initial state. // /// Runs the [`Program`] with the given [`Settings`] and a closure that creates the initial state.
fn run_with<I>( // fn run_with<I>(
self, // self,
settings: Settings, // settings: crate::Settings,
window_settings: Option<window::Settings>, // window_settings: Option<window::Settings>,
initialize: I, // initialize: I,
) -> Result // ) -> crate::Result
where // where
Self: 'static, // Self: 'static,
I: FnOnce() -> (Self::State, Task<Self::Message>) + 'static, // I: FnOnce() -> (Self::State, Task<Self::Message>) + 'static,
{ // {
use std::marker::PhantomData; // use std::marker::PhantomData;
struct Instance<P: Program, I> { // struct Instance<P: Program, I> {
program: P, // program: P,
state: P::State, // state: P::State,
_initialize: PhantomData<I>, // _initialize: PhantomData<I>,
} // }
impl<P: Program, I: FnOnce() -> (P::State, Task<P::Message>)> // impl<P: Program, I: FnOnce() -> (P::State, Task<P::Message>)>
shell::Program for Instance<P, I> // shell::Program for Instance<P, I>
{ // {
type Message = P::Message; // type Message = P::Message;
type Theme = P::Theme; // type Theme = P::Theme;
type Renderer = P::Renderer; // type Renderer = P::Renderer;
type Flags = (P, I); // type Flags = (P, I);
type Executor = P::Executor; // type Executor = P::Executor;
fn new( // fn new(
(program, initialize): Self::Flags, // (program, initialize): Self::Flags,
) -> (Self, Task<Self::Message>) { // ) -> (Self, Task<Self::Message>) {
let (state, task) = initialize(); // let (state, task) = initialize();
( // (
Self { // Self {
program, // program,
state, // state,
_initialize: PhantomData, // _initialize: PhantomData,
}, // },
task, // task,
) // )
} // }
fn title(&self, window: window::Id) -> String { // fn title(&self, window: window::Id) -> String {
self.program.title(&self.state, window) // self.program.title(&self.state, window)
} // }
fn update( // fn update(
&mut self, // &mut self,
message: Self::Message, // message: Self::Message,
) -> Task<Self::Message> { // ) -> Task<Self::Message> {
self.program.update(&mut self.state, message) // self.program.update(&mut self.state, message)
} // }
fn view( // fn view(
&self, // &self,
window: window::Id, // window: window::Id,
) -> crate::Element<'_, Self::Message, Self::Theme, Self::Renderer> // ) -> crate::Element<'_, Self::Message, Self::Theme, Self::Renderer>
{ // {
self.program.view(&self.state, window) // self.program.view(&self.state, window)
} // }
fn subscription(&self) -> Subscription<Self::Message> { // fn subscription(&self) -> Subscription<Self::Message> {
self.program.subscription(&self.state) // self.program.subscription(&self.state)
} // }
fn theme(&self, window: window::Id) -> Self::Theme { // fn theme(&self, window: window::Id) -> Self::Theme {
self.program.theme(&self.state, window) // self.program.theme(&self.state, window)
} // }
fn style(&self, theme: &Self::Theme) -> Appearance { // fn style(&self, theme: &Self::Theme) -> Appearance {
self.program.style(&self.state, theme) // self.program.style(&self.state, theme)
} // }
fn scale_factor(&self, window: window::Id) -> f64 { // fn scale_factor(&self, window: window::Id) -> f64 {
self.program.scale_factor(&self.state, window) // self.program.scale_factor(&self.state, window)
} // }
} // }
#[allow(clippy::needless_update)] // #[allow(clippy::needless_update)]
let renderer_settings = crate::graphics::Settings { // let renderer_settings = crate::graphics::Settings {
default_font: settings.default_font, // default_font: settings.default_font,
default_text_size: settings.default_text_size, // default_text_size: settings.default_text_size,
antialiasing: if settings.antialiasing { // antialiasing: if settings.antialiasing {
Some(crate::graphics::Antialiasing::MSAAx4) // Some(crate::graphics::Antialiasing::MSAAx4)
} else { // } else {
None // None
}, // },
..crate::graphics::Settings::default() // ..crate::graphics::Settings::default()
}; // };
Ok(shell::program::run::< // Ok(shell::program::run::<
Instance<Self, I>, // Instance<Self, I>,
<Self::Renderer as compositor::Default>::Compositor, // <Self::Renderer as compositor::Default>::Compositor,
>( // >(
Settings { // crate::Settings {
id: settings.id, // id: settings.id,
fonts: settings.fonts, // fonts: settings.fonts,
default_font: settings.default_font, // default_font: settings.default_font,
default_text_size: settings.default_text_size, // default_text_size: settings.default_text_size,
antialiasing: settings.antialiasing, // antialiasing: settings.antialiasing,
exit_on_close_request: settings.exit_on_close_request, // exit_on_close_request: settings.exit_on_close_request,
} // }
.into(), // .into(),
renderer_settings, // renderer_settings,
window_settings, // window_settings,
(self, initialize), // (self, initialize),
)?) // )?)
} // }
} }
/// Decorates a [`Program`] with the given title function. /// Decorates a [`Program`] with the given title function.

View file

@ -2,10 +2,8 @@
use std::any::Any; use std::any::Any;
use bytes::buf::Take;
use dnd::{DndDestinationRectangle, DndSurface}; use dnd::{DndDestinationRectangle, DndSurface};
use iced_core::{clipboard::DndSource, Vector}; use iced_core::clipboard::DndSource;
use iced_futures::MaybeSend;
use window_clipboard::mime::{AllowedMimeTypes, AsMimeTypes}; use window_clipboard::mime::{AllowedMimeTypes, AsMimeTypes};
use crate::{oneshot, task, Action, Task}; use crate::{oneshot, task, Action, Task};

View file

@ -29,7 +29,6 @@ pub use user_interface::UserInterface;
pub use window::Window; pub use window::Window;
use crate::futures::futures::channel::oneshot; use crate::futures::futures::channel::oneshot;
use dnd::DndAction;
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt; use std::fmt;
@ -70,6 +69,7 @@ pub enum Action<T> {
/// This will normally close any application windows and /// This will normally close any application windows and
/// terminate the runtime loop. /// terminate the runtime loop.
Exit, Exit,
/// Run a Dnd action. /// Run a Dnd action.
Dnd(crate::dnd::DndAction), Dnd(crate::dnd::DndAction),
@ -126,7 +126,7 @@ where
Action::PlatformSpecific(action) => { Action::PlatformSpecific(action) => {
write!(f, "Action::PlatformSpecific({:?})", action) write!(f, "Action::PlatformSpecific({:?})", action)
} }
Action::Dnd(action) => write!(f, "Action::Dnd({:?})", action), Action::Dnd(_) => write!(f, "Action::Dnd"),
} }
} }
} }

View file

@ -1,8 +1,6 @@
//! Platform specific actions defined for wayland //! Platform specific actions defined for wayland
use std::{fmt, marker::PhantomData}; use std::fmt;
use iced_futures::MaybeSend;
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
/// Platform specific actions defined for wayland /// Platform specific actions defined for wayland
@ -20,6 +18,7 @@ impl fmt::Debug for Action {
match self { match self {
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
Action::Wayland(action) => action.fmt(_f), Action::Wayland(action) => action.fmt(_f),
#[cfg(not(feature = "wayland"))]
_ => Ok(()), _ => Ok(()),
} }
} }

View file

@ -1,5 +1,3 @@
use iced_core::widget::operation::Outcome;
use crate::core::event::{self, Event}; use crate::core::event::{self, Event};
use crate::core::mouse; use crate::core::mouse;
use crate::core::renderer; use crate::core::renderer;
@ -211,7 +209,6 @@ where
operation::Outcome::Chain(next) => { operation::Outcome::Chain(next) => {
current_operation = Some(next); current_operation = Some(next);
} }
_ => {}
}; };
} }
} }

View file

@ -1,7 +1,6 @@
//! Implement your own event loop to drive a user interface. //! Implement your own event loop to drive a user interface.
use iced_core::clipboard::DndDestinationRectangles; use iced_core::clipboard::DndDestinationRectangles;
use iced_core::widget::Operation;
use iced_core::widget::tree::NAMED; use iced_core::widget::tree::NAMED;
use crate::core::event::{self, Event}; use crate::core::event::{self, Event};

View file

@ -30,8 +30,6 @@
//! ] //! ]
//! } //! }
//! ``` //! ```
use crate::message;
use crate::program::{self, Appearance, DefaultStyle, Program};
use crate::theme; use crate::theme;
@ -40,7 +38,9 @@ use crate::shell;
use crate::window; use crate::window;
use crate::{ use crate::{
Element, Executor, Font, Never, Preset, Result, Settings, Size, Element, Executor, Font, Never, Preset, Result, Settings, Size,
Subscription, Theme, task::Task, Subscription, Theme, message,
program::{self, Program},
task::Task,
}; };
use iced_debug as debug; use iced_debug as debug;

View file

@ -13,7 +13,7 @@ use crate::{
use iced_debug as debug; use iced_debug as debug;
#[cfg(not(any(feature = "winit", feature = "wayland")))] #[cfg(not(feature = "winit"))]
use crate::runtime::{Appearance, DefaultStyle}; use crate::runtime::{Appearance, DefaultStyle};
use std::borrow::Cow; use std::borrow::Cow;

View file

@ -34,10 +34,6 @@ impl From<shell::Error> for Error {
shell::Error::WindowCreationFailed(error) => { shell::Error::WindowCreationFailed(error) => {
Error::WindowCreationFailed(Box::new(error)) Error::WindowCreationFailed(Box::new(error))
} }
#[cfg(feature = "wayland")]
shell::Error::WindowCreationFailed(error) => {
Error::WindowCreationFailed(Box::new(error))
}
shell::Error::GraphicsCreationFailed(error) => { shell::Error::GraphicsCreationFailed(error) => {
Error::GraphicsCreationFailed(error) Error::GraphicsCreationFailed(error)
} }

View file

@ -504,17 +504,17 @@ compile_error!(
Available options: thread-pool, tokio, or smol." Available options: thread-pool, tokio, or smol."
); );
#[cfg(all( // #[cfg(all(
target_family = "unix", // target_family = "unix",
not(target_os = "macos"), // not(target_os = "macos"),
not(feature = "wayland"), // not(feature = "wayland"),
not(feature = "x11"), // not(feature = "x11"),
))] // ))]
compile_error!( // compile_error!(
"No Unix display server backend has been enabled. You must enable a \ // "No Unix display server backend has been enabled. You must enable a \
display server feature.\n\ // display server feature.\n\
Available options: x11, wayland." // Available options: x11, wayland."
); // );
#[cfg(feature = "highlighter")] #[cfg(feature = "highlighter")]
pub use iced_highlighter as highlighter; pub use iced_highlighter as highlighter;
@ -544,19 +544,6 @@ pub use application::Application;
#[cfg(feature = "winit")] #[cfg(feature = "winit")]
pub use program::Program; pub use program::Program;
// wayland application
// #[cfg(feature = "wayland")]
// pub mod wayland;
// #[cfg(feature = "wayland")]
// pub use wayland::application;
// #[cfg(feature = "wayland")]
// pub use wayland::application::Application;
// #[cfg(feature = "wayland")]
// pub use wayland::program;
// #[doc(inline)]
// #[cfg(feature = "wayland")]
// pub use wayland::program::Program;
#[cfg(feature = "advanced")] #[cfg(feature = "advanced")]
pub mod advanced; pub mod advanced;

File diff suppressed because it is too large Load diff