summaryrefslogtreecommitdiffstats
path: root/native/src/window
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--core/src/window/event.rs (renamed from native/src/window/event.rs)0
-rw-r--r--core/src/window/id.rs (renamed from native/src/window/id.rs)0
-rw-r--r--core/src/window/mode.rs (renamed from native/src/window/mode.rs)0
-rw-r--r--core/src/window/redraw_request.rs (renamed from native/src/window/redraw_request.rs)0
-rw-r--r--core/src/window/settings.rs (renamed from native/src/window/settings.rs)32
-rw-r--r--core/src/window/user_attention.rs (renamed from native/src/window/user_attention.rs)0
-rw-r--r--native/src/window.rs38
-rw-r--r--native/src/window/icon.rs12
-rw-r--r--native/src/window/position.rs22
-rw-r--r--runtime/src/window/action.rs (renamed from native/src/window/action.rs)73
10 files changed, 74 insertions, 103 deletions
diff --git a/native/src/window/event.rs b/core/src/window/event.rs
index e2fb5e66..e2fb5e66 100644
--- a/native/src/window/event.rs
+++ b/core/src/window/event.rs
diff --git a/native/src/window/id.rs b/core/src/window/id.rs
index 0a11b1aa..0a11b1aa 100644
--- a/native/src/window/id.rs
+++ b/core/src/window/id.rs
diff --git a/native/src/window/mode.rs b/core/src/window/mode.rs
index fdce8e23..fdce8e23 100644
--- a/native/src/window/mode.rs
+++ b/core/src/window/mode.rs
diff --git a/native/src/window/redraw_request.rs b/core/src/window/redraw_request.rs
index 3b4f0fd3..3b4f0fd3 100644
--- a/native/src/window/redraw_request.rs
+++ b/core/src/window/redraw_request.rs
diff --git a/native/src/window/settings.rs b/core/src/window/settings.rs
index 67798fbe..458b9232 100644
--- a/native/src/window/settings.rs
+++ b/core/src/window/settings.rs
@@ -1,4 +1,6 @@
-use crate::window::{Icon, Position};
+use crate::window::{Icon, Level, Position};
+
+pub use iced_winit::settings::PlatformSpecific;
/// The window settings of an application.
#[derive(Debug, Clone)]
@@ -27,11 +29,14 @@ pub struct Settings {
/// Whether the window should be transparent.
pub transparent: bool,
- /// Whether the window will always be on top of other windows.
- pub always_on_top: bool,
+ /// The window [`Level`].
+ pub level: Level,
/// The icon of the window.
pub icon: Option<Icon>,
+
+ /// Platform specific settings.
+ pub platform_specific: PlatformSpecific,
}
impl Default for Settings {
@@ -45,8 +50,27 @@ impl Default for Settings {
resizable: true,
decorations: true,
transparent: false,
- always_on_top: false,
+ level: Level::default(),
icon: None,
+ platform_specific: Default::default(),
+ }
+ }
+}
+
+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,
+ visible: settings.visible,
+ resizable: settings.resizable,
+ decorations: settings.decorations,
+ transparent: settings.transparent,
+ level: settings.level,
+ icon: settings.icon.map(Icon::into),
+ platform_specific: settings.platform_specific,
}
}
}
diff --git a/native/src/window/user_attention.rs b/core/src/window/user_attention.rs
index b03dfeef..b03dfeef 100644
--- a/native/src/window/user_attention.rs
+++ b/core/src/window/user_attention.rs
diff --git a/native/src/window.rs b/native/src/window.rs
index 660cd54f..e69de29b 100644
--- a/native/src/window.rs
+++ b/native/src/window.rs
@@ -1,38 +0,0 @@
-//! Build window-based GUI applications.
-mod action;
-mod event;
-mod icon;
-mod id;
-mod mode;
-mod position;
-mod redraw_request;
-mod settings;
-mod user_attention;
-
-pub use action::Action;
-pub use event::Event;
-pub use icon::Icon;
-pub use id::Id;
-pub use mode::Mode;
-pub use position::Position;
-pub use redraw_request::RedrawRequest;
-pub use settings::Settings;
-pub use user_attention::UserAttention;
-
-use crate::subscription::{self, Subscription};
-use crate::time::Instant;
-
-/// Subscribes to the frames of the window of the running application.
-///
-/// The resulting [`Subscription`] will produce items at a rate equal to the
-/// refresh rate of the window. Note that this rate may be variable, as it is
-/// normally managed by the graphics driver and/or the OS.
-///
-/// In any case, this [`Subscription`] is useful to smoothly draw application-driven
-/// animations without missing any frames.
-pub fn frames() -> Subscription<Instant> {
- subscription::raw_events(|event, _status| match event {
- crate::Event::Window(_, Event::RedrawRequested(at)) => Some(at),
- _ => None,
- })
-}
diff --git a/native/src/window/icon.rs b/native/src/window/icon.rs
deleted file mode 100644
index 08a6acfd..00000000
--- a/native/src/window/icon.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-//! Attach an icon to the window of your application.
-
-/// The icon of a window.
-#[derive(Debug, Clone)]
-pub struct Icon {
- /// The __rgba__ color data of the window [`Icon`].
- pub rgba: Vec<u8>,
- /// The width of the window [`Icon`].
- pub width: u32,
- /// The height of the window [`Icon`].
- pub height: u32,
-}
diff --git a/native/src/window/position.rs b/native/src/window/position.rs
deleted file mode 100644
index c260c29e..00000000
--- a/native/src/window/position.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-/// 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
- }
-}
diff --git a/native/src/window/action.rs b/runtime/src/window/action.rs
index 5751bf97..cebec4ae 100644
--- a/native/src/window/action.rs
+++ b/runtime/src/window/action.rs
@@ -1,13 +1,15 @@
-use crate::window::{Mode, UserAttention, Settings};
+use crate::core::window::{Icon, Level, Mode, UserAttention, Settings};
+use crate::core::Size;
+use crate::futures::MaybeSend;
+use crate::window::Screenshot;
-use iced_futures::MaybeSend;
use std::fmt;
/// An operation to be performed on some window.
pub enum Action<T> {
- /// Closes the current window and exits the application.
+ /// Close the current window and exits the application.
Close,
- /// Moves the window with the left mouse button until the button is
+ /// Move the window with the left mouse button until the button is
/// released.
///
/// There’s no guarantee that this will work unless the left mouse
@@ -19,13 +21,10 @@ pub enum Action<T> {
settings: Settings,
},
/// Resize the window.
- Resize {
- /// The new logical width of the window
- width: u32,
- /// The new logical height of the window
- height: u32,
- },
- /// Sets the window to maximized or back
+ Resize(Size<u32>),
+ /// Fetch the current size of the window.
+ FetchSize(Box<dyn FnOnce(Size<u32>) -> T + 'static>),
+ /// Set the window to maximized or back
Maximize(bool),
/// Set the window to minimized or back
Minimize(bool),
@@ -75,14 +74,27 @@ pub enum Action<T> {
///
/// - **Web / Wayland:** Unsupported.
GainFocus,
- /// Change whether or not the window will always be on top of other windows.
+ /// Change the window [`Level`].
+ ChangeLevel(Level),
+ /// Fetch an identifier unique to the window.
+ FetchId(Box<dyn FnOnce(u64) -> T + 'static>),
+ /// Change the window [`Icon`].
+ ///
+ /// On Windows and X11, this is typically the small icon in the top-left
+ /// corner of the titlebar.
///
/// ## Platform-specific
///
- /// - **Web / Wayland:** Unsupported.
- ChangeAlwaysOnTop(bool),
- /// Fetch an identifier unique to the window.
- FetchId(Box<dyn FnOnce(u64) -> T + 'static>),
+ /// - **Web / Wayland / macOS:** Unsupported.
+ ///
+ /// - **Windows:** Sets `ICON_SMALL`. The base size for a window icon is 16x16, but it's
+ /// recommended to account for screen scaling and pick a multiple of that, i.e. 32x32.
+ ///
+ /// - **X11:** Has no universal guidelines for icon sizes, so you're at the whims of the WM. That
+ /// said, it's usually in the same ballpark as on Windows.
+ ChangeIcon(Icon),
+ /// Screenshot the viewport of the window.
+ Screenshot(Box<dyn FnOnce(Screenshot) -> T + 'static>),
}
impl<T> Action<T> {
@@ -95,10 +107,11 @@ impl<T> Action<T> {
T: 'static,
{
match self {
- Self::Spawn { settings } => Action::Spawn { settings },
Self::Close => Action::Close,
Self::Drag => Action::Drag,
- Self::Resize { width, height } => Action::Resize { width, height },
+ Self::Spawn { settings } => Action::Spawn { settings },
+ Self::Resize(size) => Action::Resize(size),
+ Self::FetchSize(o) => Action::FetchSize(Box::new(move |s| f(o(s)))),
Self::Maximize(maximized) => Action::Maximize(maximized),
Self::Minimize(minimized) => Action::Minimize(minimized),
Self::Move { x, y } => Action::Move { x, y },
@@ -110,10 +123,14 @@ impl<T> Action<T> {
Action::RequestUserAttention(attention_type)
}
Self::GainFocus => Action::GainFocus,
- Self::ChangeAlwaysOnTop(on_top) => {
- Action::ChangeAlwaysOnTop(on_top)
- }
+ Self::ChangeLevel(level) => Action::ChangeLevel(level),
Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))),
+ Self::ChangeIcon(icon) => Action::ChangeIcon(icon),
+ Self::Screenshot(tag) => {
+ Action::Screenshot(Box::new(move |screenshot| {
+ f(tag(screenshot))
+ }))
+ }
}
}
}
@@ -126,10 +143,8 @@ impl<T> fmt::Debug for Action<T> {
Self::Spawn { settings } => {
write!(f, "Action::Spawn {{ settings: {:?} }}", settings)
}
- Self::Resize { width, height } => write!(
- f,
- "Action::Resize {{ widget: {width}, height: {height} }}"
- ),
+ Self::Resize(size) => write!(f, "Action::Resize({size:?})"),
+ Self::FetchSize(_) => write!(f, "Action::FetchSize"),
Self::Maximize(maximized) => {
write!(f, "Action::Maximize({maximized})")
}
@@ -147,10 +162,14 @@ impl<T> fmt::Debug for Action<T> {
write!(f, "Action::RequestUserAttention")
}
Self::GainFocus => write!(f, "Action::GainFocus"),
- Self::ChangeAlwaysOnTop(on_top) => {
- write!(f, "Action::AlwaysOnTop({on_top})")
+ Self::ChangeLevel(level) => {
+ write!(f, "Action::ChangeLevel({level:?})")
}
Self::FetchId(_) => write!(f, "Action::FetchId"),
+ Self::ChangeIcon(_icon) => {
+ write!(f, "Action::ChangeIcon(icon)")
+ }
+ Self::Screenshot(_) => write!(f, "Action::Screenshot"),
}
}
}