summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Billy Messenger <BillyDM@tutamail.com>2021-07-22 12:37:39 -0500
committerLibravatar Billy Messenger <BillyDM@tutamail.com>2021-07-22 12:37:39 -0500
commite822f654e44d2d7375b7fda966bb772055f377d4 (patch)
tree8707561f1bb09c9e58cc9d9884bfb16d956f9f65 /src
parent1c06920158e1a47977b2762bf8b34e56fd1a935a (diff)
parentdc0b96ce407283f2ffd9add5ad339f89097555d3 (diff)
downloadiced-e822f654e44d2d7375b7fda966bb772055f377d4.tar.gz
iced-e822f654e44d2d7375b7fda966bb772055f377d4.tar.bz2
iced-e822f654e44d2d7375b7fda966bb772055f377d4.zip
Merge branch 'master' of https://github.com/hecrj/iced into wgpu_outdatedframe
Diffstat (limited to 'src')
-rw-r--r--src/application.rs79
-rw-r--r--src/error.rs13
-rw-r--r--src/executor.rs17
-rw-r--r--src/lib.rs15
-rw-r--r--src/sandbox.rs39
-rw-r--r--src/settings.rs25
-rw-r--r--src/widget.rs8
-rw-r--r--src/window.rs2
-rw-r--r--src/window/icon.rs18
-rw-r--r--src/window/mode.rs3
-rw-r--r--src/window/position.rs33
-rw-r--r--src/window/settings.rs7
12 files changed, 198 insertions, 61 deletions
diff --git a/src/application.rs b/src/application.rs
index 3b690a7c..78280e98 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -1,5 +1,7 @@
use crate::window;
-use crate::{Color, Command, Element, Executor, Settings, Subscription};
+use crate::{
+ Clipboard, Color, Command, Element, Executor, Menu, Settings, Subscription,
+};
/// An interactive cross-platform application.
///
@@ -37,15 +39,15 @@ use crate::{Color, Command, Element, Executor, Settings, Subscription};
/// to listen to time.
/// - [`todos`], a todos tracker inspired by [TodoMVC].
///
-/// [The repository has a bunch of examples]: https://github.com/hecrj/iced/tree/0.2/examples
-/// [`clock`]: https://github.com/hecrj/iced/tree/0.2/examples/clock
-/// [`download_progress`]: https://github.com/hecrj/iced/tree/0.2/examples/download_progress
-/// [`events`]: https://github.com/hecrj/iced/tree/0.2/examples/events
-/// [`game_of_life`]: https://github.com/hecrj/iced/tree/0.2/examples/game_of_life
-/// [`pokedex`]: https://github.com/hecrj/iced/tree/0.2/examples/pokedex
-/// [`solar_system`]: https://github.com/hecrj/iced/tree/0.2/examples/solar_system
-/// [`stopwatch`]: https://github.com/hecrj/iced/tree/0.2/examples/stopwatch
-/// [`todos`]: https://github.com/hecrj/iced/tree/0.2/examples/todos
+/// [The repository has a bunch of examples]: https://github.com/hecrj/iced/tree/0.3/examples
+/// [`clock`]: https://github.com/hecrj/iced/tree/0.3/examples/clock
+/// [`download_progress`]: https://github.com/hecrj/iced/tree/0.3/examples/download_progress
+/// [`events`]: https://github.com/hecrj/iced/tree/0.3/examples/events
+/// [`game_of_life`]: https://github.com/hecrj/iced/tree/0.3/examples/game_of_life
+/// [`pokedex`]: https://github.com/hecrj/iced/tree/0.3/examples/pokedex
+/// [`solar_system`]: https://github.com/hecrj/iced/tree/0.3/examples/solar_system
+/// [`stopwatch`]: https://github.com/hecrj/iced/tree/0.3/examples/stopwatch
+/// [`todos`]: https://github.com/hecrj/iced/tree/0.3/examples/todos
/// [`Sandbox`]: crate::Sandbox
/// [`Canvas`]: crate::widget::Canvas
/// [PokéAPI]: https://pokeapi.co/
@@ -57,7 +59,7 @@ use crate::{Color, Command, Element, Executor, Settings, Subscription};
/// says "Hello, world!":
///
/// ```no_run
-/// use iced::{executor, Application, Command, Element, Settings, Text};
+/// use iced::{executor, Application, Clipboard, Command, Element, Settings, Text};
///
/// pub fn main() -> iced::Result {
/// Hello::run(Settings::default())
@@ -78,7 +80,7 @@ use crate::{Color, Command, Element, Executor, Settings, Subscription};
/// String::from("A cool application")
/// }
///
-/// fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
+/// fn update(&mut self, _message: Self::Message, _clipboard: &mut Clipboard) -> Command<Self::Message> {
/// Command::none()
/// }
///
@@ -97,7 +99,7 @@ pub trait Application: Sized {
type Executor: Executor;
/// The type of __messages__ your [`Application`] will produce.
- type Message: std::fmt::Debug + Send;
+ type Message: std::fmt::Debug + Clone + Send;
/// The data needed to initialize your [`Application`].
type Flags;
@@ -127,7 +129,11 @@ pub trait Application: Sized {
/// this method.
///
/// Any [`Command`] returned will be executed immediately in the background.
- fn update(&mut self, message: Self::Message) -> Command<Self::Message>;
+ fn update(
+ &mut self,
+ message: Self::Message,
+ clipboard: &mut Clipboard,
+ ) -> Command<Self::Message>;
/// Returns the event [`Subscription`] for the current state of the
/// application.
@@ -178,6 +184,20 @@ pub trait Application: Sized {
1.0
}
+ /// Returns whether the [`Application`] should be terminated.
+ ///
+ /// By default, it returns `false`.
+ fn should_exit(&self) -> bool {
+ false
+ }
+
+ /// Returns the current system [`Menu`] of the [`Application`].
+ ///
+ /// By default, it returns an empty [`Menu`].
+ fn menu(&self) -> Menu<Self::Message> {
+ Menu::new()
+ }
+
/// Runs the [`Application`].
///
/// On native platforms, this method will take control of the current thread
@@ -195,12 +215,13 @@ pub trait Application: Sized {
let renderer_settings = crate::renderer::Settings {
default_font: settings.default_font,
default_text_size: settings.default_text_size,
+ text_multithreading: settings.text_multithreading,
antialiasing: if settings.antialiasing {
Some(crate::renderer::settings::Antialiasing::MSAAx4)
} else {
None
},
- ..crate::renderer::Settings::default()
+ ..crate::renderer::Settings::from_env()
};
Ok(crate::runtime::application::run::<
@@ -228,9 +249,14 @@ where
{
type Renderer = crate::renderer::Renderer;
type Message = A::Message;
-
- fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
- self.0.update(message)
+ type Clipboard = iced_winit::Clipboard;
+
+ fn update(
+ &mut self,
+ message: Self::Message,
+ clipboard: &mut iced_winit::Clipboard,
+ ) -> Command<Self::Message> {
+ self.0.update(message, clipboard)
}
fn view(&mut self) -> Element<'_, Self::Message> {
@@ -259,6 +285,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,
}
}
@@ -273,6 +300,14 @@ where
fn scale_factor(&self) -> f64 {
self.0.scale_factor()
}
+
+ fn should_exit(&self) -> bool {
+ self.0.should_exit()
+ }
+
+ fn menu(&self) -> Menu<Self::Message> {
+ self.0.menu()
+ }
}
#[cfg(target_arch = "wasm32")]
@@ -294,8 +329,12 @@ where
self.0.title()
}
- fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
- self.0.update(message)
+ fn update(
+ &mut self,
+ message: Self::Message,
+ clipboard: &mut Clipboard,
+ ) -> Command<Self::Message> {
+ self.0.update(message, clipboard)
}
fn subscription(&self) -> Subscription<Self::Message> {
diff --git a/src/error.rs b/src/error.rs
index 31b87d17..c8fa6636 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -9,7 +9,7 @@ pub enum Error {
/// The application window could not be created.
#[error("the application window could not be created")]
- WindowCreationFailed(Box<dyn std::error::Error>),
+ WindowCreationFailed(Box<dyn std::error::Error + Send + Sync>),
/// A suitable graphics adapter or device could not be found.
#[error("a suitable graphics adapter or device could not be found")]
@@ -32,3 +32,14 @@ impl From<iced_winit::Error> for Error {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn assert_send_sync() {
+ fn _assert<T: Send + Sync>() {}
+ _assert::<Error>();
+ }
+}
diff --git a/src/executor.rs b/src/executor.rs
index 0333bc1d..9f3656b1 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -10,19 +10,30 @@ mod platform {
#[cfg(feature = "tokio_old")]
type Executor = executor::TokioOld;
- #[cfg(all(not(feature = "tokio_old"), feature = "tokio"))]
+ #[cfg(all(feature = "tokio", not(feature = "tokio_old")))]
type Executor = executor::Tokio;
#[cfg(all(
+ feature = "async-std",
not(any(feature = "tokio_old", feature = "tokio")),
- feature = "async-std"
))]
type Executor = executor::AsyncStd;
+ #[cfg(all(
+ feature = "smol",
+ not(any(
+ feature = "tokio_old",
+ feature = "tokio",
+ feature = "async-std"
+ )),
+ ))]
+ type Executor = executor::Smol;
+
#[cfg(not(any(
feature = "tokio_old",
feature = "tokio",
- feature = "async-std"
+ feature = "async-std",
+ feature = "smol",
)))]
type Executor = executor::ThreadPool;
diff --git a/src/lib.rs b/src/lib.rs
index 3578ea82..8cd6aa70 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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
@@ -191,7 +191,12 @@ pub mod widget;
pub mod window;
#[cfg(all(
- any(feature = "tokio", feature = "tokio_old", feature = "async-std"),
+ any(
+ feature = "tokio",
+ feature = "tokio_old",
+ feature = "async-std",
+ feature = "smol"
+ ),
not(target_arch = "wasm32")
))]
#[cfg_attr(
@@ -200,6 +205,7 @@ pub mod window;
feature = "tokio",
feature = "tokio_old",
feature = "async-std"
+ feature = "smol"
)))
)]
pub mod time;
@@ -239,6 +245,7 @@ pub use sandbox::Sandbox;
pub use settings::Settings;
pub use runtime::{
- futures, Align, Background, Color, Command, Font, HorizontalAlignment,
- Length, Point, Rectangle, Size, Subscription, Vector, VerticalAlignment,
+ futures, menu, Align, Background, Clipboard, Color, Command, Font,
+ HorizontalAlignment, Length, Menu, Point, Rectangle, Size, Subscription,
+ Vector, VerticalAlignment,
};
diff --git a/src/sandbox.rs b/src/sandbox.rs
index dbaa02f1..cb3cf624 100644
--- a/src/sandbox.rs
+++ b/src/sandbox.rs
@@ -1,5 +1,6 @@
use crate::{
- Application, Color, Command, Element, Error, Settings, Subscription,
+ Application, Clipboard, Color, Command, Element, Error, Settings,
+ Subscription,
};
/// A sandboxed [`Application`].
@@ -17,8 +18,8 @@ use crate::{
/// # Examples
/// [The repository has a bunch of examples] that use the [`Sandbox`] trait:
///
-/// - [`bezier_tool`], a Paint-like tool for drawing Bézier curves using
-/// [`lyon`].
+/// - [`bezier_tool`], a Paint-like tool for drawing Bézier curves using the
+/// [`Canvas widget`].
/// - [`counter`], the classic counter example explained in [the overview].
/// - [`custom_widget`], a demonstration of how to build a custom widget that
/// draws a circle.
@@ -35,19 +36,19 @@ use crate::{
/// - [`tour`], a simple UI tour that can run both on native platforms and the
/// web!
///
-/// [The repository has a bunch of examples]: https://github.com/hecrj/iced/tree/0.2/examples
-/// [`bezier_tool`]: https://github.com/hecrj/iced/tree/0.2/examples/bezier_tool
-/// [`counter`]: https://github.com/hecrj/iced/tree/0.2/examples/counter
-/// [`custom_widget`]: https://github.com/hecrj/iced/tree/0.2/examples/custom_widget
-/// [`geometry`]: https://github.com/hecrj/iced/tree/0.2/examples/geometry
-/// [`pane_grid`]: https://github.com/hecrj/iced/tree/0.2/examples/pane_grid
-/// [`progress_bar`]: https://github.com/hecrj/iced/tree/0.2/examples/progress_bar
-/// [`styling`]: https://github.com/hecrj/iced/tree/0.2/examples/styling
-/// [`svg`]: https://github.com/hecrj/iced/tree/0.2/examples/svg
-/// [`tour`]: https://github.com/hecrj/iced/tree/0.2/examples/tour
-/// [`lyon`]: https://github.com/nical/lyon
+/// [The repository has a bunch of examples]: https://github.com/hecrj/iced/tree/0.3/examples
+/// [`bezier_tool`]: https://github.com/hecrj/iced/tree/0.3/examples/bezier_tool
+/// [`counter`]: https://github.com/hecrj/iced/tree/0.3/examples/counter
+/// [`custom_widget`]: https://github.com/hecrj/iced/tree/0.3/examples/custom_widget
+/// [`geometry`]: https://github.com/hecrj/iced/tree/0.3/examples/geometry
+/// [`pane_grid`]: https://github.com/hecrj/iced/tree/0.3/examples/pane_grid
+/// [`progress_bar`]: https://github.com/hecrj/iced/tree/0.3/examples/progress_bar
+/// [`styling`]: https://github.com/hecrj/iced/tree/0.3/examples/styling
+/// [`svg`]: https://github.com/hecrj/iced/tree/0.3/examples/svg
+/// [`tour`]: https://github.com/hecrj/iced/tree/0.3/examples/tour
+/// [`Canvas widget`]: crate::widget::Canvas
/// [the overview]: index.html#overview
-/// [`iced_wgpu`]: https://github.com/hecrj/iced/tree/0.2/wgpu
+/// [`iced_wgpu`]: https://github.com/hecrj/iced/tree/0.3/wgpu
/// [`Svg` widget]: crate::widget::Svg
/// [Ghostscript Tiger]: https://commons.wikimedia.org/wiki/File:Ghostscript_Tiger.svg
///
@@ -87,7 +88,7 @@ use crate::{
/// ```
pub trait Sandbox {
/// The type of __messages__ your [`Sandbox`] will produce.
- type Message: std::fmt::Debug + Send;
+ type Message: std::fmt::Debug + Clone + Send;
/// Initializes the [`Sandbox`].
///
@@ -161,7 +162,11 @@ where
T::title(self)
}
- fn update(&mut self, message: T::Message) -> Command<T::Message> {
+ fn update(
+ &mut self,
+ message: T::Message,
+ _clipboard: &mut Clipboard,
+ ) -> Command<T::Message> {
T::update(self, message);
Command::none()
diff --git a/src/settings.rs b/src/settings.rs
index c82a1354..480bf813 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -25,6 +25,12 @@ pub struct Settings<Flags> {
/// The default value is 20.
pub default_text_size: u16,
+ /// If enabled, spread text workload in multiple threads when multiple cores
+ /// are available.
+ ///
+ /// By default, it is disabled.
+ pub text_multithreading: bool,
+
/// If set to true, the renderer will try to perform antialiasing for some
/// primitives.
///
@@ -35,6 +41,12 @@ pub struct Settings<Flags> {
///
/// [`Canvas`]: crate::widget::Canvas
pub antialiasing: bool,
+
+ /// Whether the [`Application`] should exit when the user requests the
+ /// window to close (e.g. the user presses the close button).
+ ///
+ /// By default, it is enabled.
+ pub exit_on_close_request: bool,
}
impl<Flags> Settings<Flags> {
@@ -46,10 +58,12 @@ impl<Flags> Settings<Flags> {
Self {
flags,
- antialiasing: default_settings.antialiasing,
+ window: default_settings.window,
default_font: default_settings.default_font,
default_text_size: default_settings.default_text_size,
- window: default_settings.window,
+ text_multithreading: default_settings.text_multithreading,
+ antialiasing: default_settings.antialiasing,
+ exit_on_close_request: default_settings.exit_on_close_request,
}
}
}
@@ -61,10 +75,12 @@ where
fn default() -> Self {
Self {
flags: Default::default(),
- antialiasing: Default::default(),
+ window: Default::default(),
default_font: Default::default(),
default_text_size: 20,
- window: Default::default(),
+ text_multithreading: false,
+ antialiasing: false,
+ exit_on_close_request: true,
}
}
}
@@ -75,6 +91,7 @@ impl<Flags> From<Settings<Flags>> for iced_winit::Settings<Flags> {
iced_winit::Settings {
window: settings.window.into(),
flags: settings.flags,
+ exit_on_close_request: settings.exit_on_close_request,
}
}
}
diff --git a/src/widget.rs b/src/widget.rs
index b9b65499..db052106 100644
--- a/src/widget.rs
+++ b/src/widget.rs
@@ -17,7 +17,8 @@
mod platform {
pub use crate::renderer::widget::{
button, checkbox, container, pane_grid, pick_list, progress_bar, radio,
- rule, scrollable, slider, text_input, Column, Row, Space, Text,
+ rule, scrollable, slider, text_input, toggler, tooltip, Column, Row,
+ Space, Text,
};
#[cfg(any(feature = "canvas", feature = "glow_canvas"))]
@@ -37,7 +38,8 @@ mod platform {
#[cfg_attr(docsrs, doc(cfg(feature = "image")))]
pub mod image {
//! Display images in your user interface.
- pub use crate::runtime::image::{Handle, Image};
+ pub use crate::runtime::image::viewer;
+ pub use crate::runtime::image::{Handle, Image, Viewer};
}
#[cfg_attr(docsrs, doc(cfg(feature = "svg")))]
@@ -51,7 +53,7 @@ mod platform {
button::Button, checkbox::Checkbox, container::Container, image::Image,
pane_grid::PaneGrid, pick_list::PickList, progress_bar::ProgressBar,
radio::Radio, rule::Rule, scrollable::Scrollable, slider::Slider,
- svg::Svg, text_input::TextInput,
+ svg::Svg, text_input::TextInput, toggler::Toggler, tooltip::Tooltip,
};
#[cfg(any(feature = "canvas", feature = "glow_canvas"))]
diff --git a/src/window.rs b/src/window.rs
index a2883b62..7d441062 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -1,9 +1,11 @@
//! Configure the window of your application in native platforms.
mod mode;
+mod position;
mod settings;
pub mod icon;
pub use icon::Icon;
pub use mode::Mode;
+pub use position::Position;
pub use settings::Settings;
diff --git a/src/window/icon.rs b/src/window/icon.rs
index 0d27b00e..287538b1 100644
--- a/src/window/icon.rs
+++ b/src/window/icon.rs
@@ -97,23 +97,25 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::InvalidData { byte_count } => {
- write!(f,
- "The provided RGBA data (with length {:?}) isn't divisble by \
+ write!(
+ f,
+ "The provided RGBA data (with length {:?}) isn't divisble by \
4. Therefore, it cannot be safely interpreted as 32bpp RGBA \
pixels.",
- byte_count,
- )
+ byte_count,
+ )
}
Error::DimensionsMismatch {
width,
height,
pixel_count,
} => {
- write!(f,
- "The number of RGBA pixels ({:?}) does not match the provided \
+ write!(
+ f,
+ "The number of RGBA pixels ({:?}) does not match the provided \
dimensions ({:?}x{:?}).",
- pixel_count, width, height,
- )
+ pixel_count, width, height,
+ )
}
Error::OsError(e) => write!(
f,
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/src/window/position.rs b/src/window/position.rs
new file mode 100644
index 00000000..8535ef6a
--- /dev/null
+++ b/src/window/position.rs
@@ -0,0 +1,33 @@
+/// The position of a window in a given screen.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Position {
+ /// The platform-specific default position for a new window.
+ Default,
+ /// The window is completely centered on the screen.
+ Centered,
+ /// The window is positioned with specific coordinates: `(X, Y)`.
+ ///
+ /// When the decorations of the window are enabled, Windows 10 will add some
+ /// invisible padding to the window. This padding gets included in the
+ /// position. So if you have decorations enabled and want the window to be
+ /// at (0, 0) you would have to set the position to
+ /// `(PADDING_X, PADDING_Y)`.
+ Specific(i32, i32),
+}
+
+impl Default for Position {
+ fn default() -> Self {
+ Self::Default
+ }
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+impl From<Position> for iced_winit::Position {
+ fn from(position: Position) -> Self {
+ match position {
+ Position::Default => Self::Default,
+ Position::Centered => Self::Centered,
+ Position::Specific(x, y) => Self::Specific(x, y),
+ }
+ }
+}
diff --git a/src/window/settings.rs b/src/window/settings.rs
index 6b5d2985..ec6c3071 100644
--- a/src/window/settings.rs
+++ b/src/window/settings.rs
@@ -1,4 +1,4 @@
-use crate::window::Icon;
+use crate::window::{Icon, Position};
/// The window settings of an application.
#[derive(Debug, Clone)]
@@ -6,6 +6,9 @@ pub struct Settings {
/// The initial size of the window.
pub size: (u32, u32),
+ /// The initial position of the window.
+ pub position: Position,
+
/// The minimum size of the window.
pub min_size: Option<(u32, u32)>,
@@ -32,6 +35,7 @@ impl Default for Settings {
fn default() -> Settings {
Settings {
size: (1024, 768),
+ position: Position::default(),
min_size: None,
max_size: None,
resizable: true,
@@ -48,6 +52,7 @@ impl From<Settings> for iced_winit::settings::Window {
fn from(settings: Settings) -> Self {
Self {
size: settings.size,
+ position: iced_winit::Position::from(settings.position),
min_size: settings.min_size,
max_size: settings.max_size,
resizable: settings.resizable,