diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/application.rs | 33 | ||||
-rw-r--r-- | src/lib.rs | 6 | ||||
-rw-r--r-- | src/sandbox.rs | 24 | ||||
-rw-r--r-- | src/window.rs | 2 | ||||
-rw-r--r-- | src/window/position.rs | 33 | ||||
-rw-r--r-- | src/window/settings.rs | 7 |
6 files changed, 78 insertions, 27 deletions
diff --git a/src/application.rs b/src/application.rs index 14bed2cb..78280e98 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,6 +1,6 @@ use crate::window; use crate::{ - Clipboard, Color, Command, Element, Executor, Settings, Subscription, + Clipboard, Color, Command, Element, Executor, Menu, Settings, Subscription, }; /// An interactive cross-platform application. @@ -39,15 +39,15 @@ use crate::{ /// 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/ @@ -99,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; @@ -191,6 +191,13 @@ pub trait Application: Sized { 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 @@ -297,6 +304,10 @@ where fn should_exit(&self) -> bool { self.0.should_exit() } + + fn menu(&self) -> Menu<Self::Message> { + self.0.menu() + } } #[cfg(target_arch = "wasm32")] @@ -245,7 +245,7 @@ pub use sandbox::Sandbox; pub use settings::Settings; pub use runtime::{ - futures, Align, Background, Clipboard, 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 9dd17b7e..cb3cf624 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -36,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 +/// [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 /// @@ -88,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`]. /// 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/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, |