summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--winit/Cargo.toml8
-rw-r--r--winit/src/application.rs36
-rw-r--r--winit/src/application/state.rs4
-rw-r--r--winit/src/conversion.rs12
-rw-r--r--winit/src/lib.rs2
-rw-r--r--winit/src/settings.rs12
-rw-r--r--winit/src/settings/macos.rs1
-rw-r--r--winit/src/settings/wasm.rs11
-rw-r--r--winit/src/settings/windows.rs1
-rw-r--r--winit/src/window.rs20
10 files changed, 85 insertions, 22 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index d3ed949f..ebbadb12 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "iced_winit"
-version = "0.4.0"
+version = "0.6.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2021"
description = "A winit runtime for Iced"
@@ -26,15 +26,15 @@ git = "https://github.com/iced-rs/winit.git"
rev = "940457522e9fb9f5dac228b0ecfafe0138b4048c"
[dependencies.iced_native]
-version = "0.5"
+version = "0.7"
path = "../native"
[dependencies.iced_graphics]
-version = "0.3"
+version = "0.5"
path = "../graphics"
[dependencies.iced_futures]
-version = "0.4"
+version = "0.5"
path = "../futures"
[target.'cfg(target_os = "windows")'.dependencies.winapi]
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 0496aea9..1706d2e9 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -58,10 +58,10 @@ where
/// title of your application when necessary.
fn title(&self) -> String;
- /// Returns the current [`Theme`] of the [`Application`].
+ /// Returns the current `Theme` of the [`Application`].
fn theme(&self) -> <Self::Renderer as crate::Renderer>::Theme;
- /// Returns the [`Style`] variation of the [`Theme`].
+ /// Returns the `Style` variation of the `Theme`.
fn style(
&self,
) -> <<Self::Renderer as crate::Renderer>::Theme as StyleSheet>::Style {
@@ -137,6 +137,9 @@ where
runtime.enter(|| A::new(flags))
};
+ #[cfg(target_arch = "wasm32")]
+ let target = settings.window.platform_specific.target.clone();
+
let builder = settings.window.into_builder(
&application.title(),
event_loop.primary_monitor(),
@@ -159,9 +162,20 @@ where
let document = window.document().unwrap();
let body = document.body().unwrap();
- let _ = body
- .append_child(&canvas)
- .expect("Append canvas to HTML body");
+ let target = target.and_then(|target| {
+ body.query_selector(&format!("#{}", target))
+ .ok()
+ .unwrap_or(None)
+ });
+
+ let _ = match target {
+ Some(node) => node
+ .replace_child(&canvas, &node)
+ .expect(&format!("Could not replace #{}", node.id())),
+ None => body
+ .append_child(&canvas)
+ .expect("Append canvas to HTML body"),
+ };
}
let (compositor, renderer) = C::new(compositor_settings, Some(&window))?;
@@ -615,12 +629,21 @@ pub fn run_command<A, E>(
}
},
command::Action::Window(action) => match action {
+ window::Action::Drag => {
+ let _res = window.drag_window();
+ }
window::Action::Resize { width, height } => {
window.set_inner_size(winit::dpi::LogicalSize {
width,
height,
});
}
+ window::Action::Maximize(value) => {
+ window.set_maximized(value);
+ }
+ window::Action::Minimize(value) => {
+ window.set_minimized(value);
+ }
window::Action::Move { x, y } => {
window.set_outer_position(winit::dpi::LogicalPosition {
x,
@@ -634,6 +657,9 @@ pub fn run_command<A, E>(
mode,
));
}
+ window::Action::ToggleMaximize => {
+ window.set_maximized(!window.is_maximized())
+ }
window::Action::FetchMode(tag) => {
let mode = if window.is_visible().unwrap_or(true) {
conversion::mode(window.fullscreen())
diff --git a/winit/src/application/state.rs b/winit/src/application/state.rs
index 9c539548..8d6a1df1 100644
--- a/winit/src/application/state.rs
+++ b/winit/src/application/state.rs
@@ -32,7 +32,7 @@ where
let title = application.title();
let scale_factor = application.scale_factor();
let theme = application.theme();
- let appearance = theme.appearance(application.style());
+ let appearance = theme.appearance(&application.style());
let viewport = {
let physical_size = window.inner_size();
@@ -210,6 +210,6 @@ where
// Update theme and appearance
self.theme = application.theme();
- self.appearance = self.theme.appearance(application.style());
+ self.appearance = self.theme.appearance(&application.style());
}
}
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs
index ba5b0002..b1076afe 100644
--- a/winit/src/conversion.rs
+++ b/winit/src/conversion.rs
@@ -1,7 +1,7 @@
//! Convert [`winit`] types into [`iced_native`] types, and viceversa.
//!
//! [`winit`]: https://github.com/rust-windowing/winit
-//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native
+//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
use crate::keyboard;
use crate::mouse;
use crate::touch;
@@ -218,7 +218,7 @@ pub fn mode(mode: Option<winit::window::Fullscreen>) -> window::Mode {
/// Converts a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn mouse_interaction(
interaction: mouse::Interaction,
) -> winit::window::CursorIcon {
@@ -242,7 +242,7 @@ pub fn mouse_interaction(
/// Converts a `MouseButton` from [`winit`] to an [`iced_native`] mouse button.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
match mouse_button {
winit::event::MouseButton::Left => mouse::Button::Left,
@@ -258,7 +258,7 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
/// modifiers state.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn modifiers(
modifiers: winit::event::ModifiersState,
) -> keyboard::Modifiers {
@@ -285,7 +285,7 @@ pub fn cursor_position(
/// Converts a `Touch` from [`winit`] to an [`iced_native`] touch event.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn touch_event(
touch: winit::event::Touch,
scale_factor: f64,
@@ -316,7 +316,7 @@ pub fn touch_event(
/// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn key_code(
virtual_keycode: winit::event::VirtualKeyCode,
) -> keyboard::KeyCode {
diff --git a/winit/src/lib.rs b/winit/src/lib.rs
index edba887b..b8ed492d 100644
--- a/winit/src/lib.rs
+++ b/winit/src/lib.rs
@@ -11,7 +11,7 @@
//! Additionally, a [`conversion`] module is available for users that decide to
//! implement a custom event loop.
//!
-//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.4/native
+//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
//! [`winit`]: https://github.com/rust-windowing/winit
//! [`conversion`]: crate::conversion
#![doc(
diff --git a/winit/src/settings.rs b/winit/src/settings.rs
index 6387454b..9bbdef5c 100644
--- a/winit/src/settings.rs
+++ b/winit/src/settings.rs
@@ -7,7 +7,15 @@ mod platform;
#[path = "settings/macos.rs"]
mod platform;
-#[cfg(not(any(target_os = "windows", target_os = "macos")))]
+#[cfg(target_arch = "wasm32")]
+#[path = "settings/wasm.rs"]
+mod platform;
+
+#[cfg(not(any(
+ target_os = "windows",
+ target_os = "macos",
+ target_arch = "wasm32"
+)))]
#[path = "settings/other.rs"]
mod platform;
@@ -27,7 +35,7 @@ pub struct Settings<Flags> {
/// communicate with it through the windowing system.
pub id: Option<String>,
- /// The [`Window`] settings
+ /// The [`Window`] settings.
pub window: Window,
/// The data needed to initialize an [`Application`].
diff --git a/winit/src/settings/macos.rs b/winit/src/settings/macos.rs
index ad4c8cae..f86e63ad 100644
--- a/winit/src/settings/macos.rs
+++ b/winit/src/settings/macos.rs
@@ -1,4 +1,3 @@
-#![cfg(target_os = "macos")]
//! Platform specific settings for macOS.
/// The platform specific window settings of an application.
diff --git a/winit/src/settings/wasm.rs b/winit/src/settings/wasm.rs
new file mode 100644
index 00000000..8e0f1bbc
--- /dev/null
+++ b/winit/src/settings/wasm.rs
@@ -0,0 +1,11 @@
+//! Platform specific settings for WebAssembly.
+
+/// The platform specific window settings of an application.
+#[derive(Debug, Clone, PartialEq, Eq, Default)]
+pub struct PlatformSpecific {
+ /// The identifier of a DOM element that will be replaced with the
+ /// application.
+ ///
+ /// If set to `None`, the application will be appended to the HTML body.
+ pub target: Option<String>,
+}
diff --git a/winit/src/settings/windows.rs b/winit/src/settings/windows.rs
index 9bef1eaf..ff03a9c5 100644
--- a/winit/src/settings/windows.rs
+++ b/winit/src/settings/windows.rs
@@ -1,4 +1,3 @@
-#![cfg(target_os = "windows")]
//! Platform specific settings for Windows.
/// The platform specific window settings of an application.
diff --git a/winit/src/window.rs b/winit/src/window.rs
index 265139f7..1e704c5b 100644
--- a/winit/src/window.rs
+++ b/winit/src/window.rs
@@ -4,6 +4,11 @@ use iced_native::window;
pub use window::{Event, Mode};
+/// 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))
+}
+
/// 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 {
@@ -12,6 +17,16 @@ pub fn resize<Message>(width: u32, height: u32) -> Command<Message> {
}))
}
+/// Sets the window to maximized or back.
+pub fn maximize<Message>(value: bool) -> Command<Message> {
+ Command::single(command::Action::Window(window::Action::Maximize(value)))
+}
+
+/// Set the window to minimized or back.
+pub fn minimize<Message>(value: bool) -> Command<Message> {
+ Command::single(command::Action::Window(window::Action::Minimize(value)))
+}
+
/// 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 }))
@@ -22,6 +37,11 @@ pub fn set_mode<Message>(mode: Mode) -> Command<Message> {
Command::single(command::Action::Window(window::Action::SetMode(mode)))
}
+/// Sets the window to maximized or back.
+pub fn toggle_maximize<Message>() -> Command<Message> {
+ Command::single(command::Action::Window(window::Action::ToggleMaximize))
+}
+
/// Fetches the current [`Mode`] of the window.
pub fn fetch_mode<Message>(
f: impl FnOnce(Mode) -> Message + 'static,