introduce window::spawn and window::close
This commit is contained in:
parent
1bc0c480f9
commit
f93fa02543
5 changed files with 123 additions and 71 deletions
|
|
@ -682,41 +682,52 @@ pub fn run_command<A, E>(
|
||||||
clipboard.write(contents);
|
clipboard.write(contents);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
command::Action::Window(id, action) => {
|
command::Action::Window(id, action) => match action {
|
||||||
let window = windows.get(&id).expect("No window found");
|
window::Action::Spawn { settings } => {
|
||||||
|
proxy
|
||||||
match action {
|
.send_event(Event::NewWindow(id, settings.into()))
|
||||||
window::Action::Resize { width, height } => {
|
.expect("Send message to event loop");
|
||||||
window.set_inner_size(glutin::dpi::LogicalSize {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
window::Action::Move { x, y } => {
|
|
||||||
window.set_outer_position(
|
|
||||||
glutin::dpi::LogicalPosition { x, y },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
window::Action::SetMode(mode) => {
|
|
||||||
window.set_visible(conversion::visible(mode));
|
|
||||||
window.set_fullscreen(conversion::fullscreen(
|
|
||||||
window.primary_monitor(),
|
|
||||||
mode,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
window::Action::FetchMode(tag) => {
|
|
||||||
let mode = if window.is_visible().unwrap_or(true) {
|
|
||||||
conversion::mode(window.fullscreen())
|
|
||||||
} else {
|
|
||||||
window::Mode::Hidden
|
|
||||||
};
|
|
||||||
|
|
||||||
proxy
|
|
||||||
.send_event(Event::Application(tag(mode)))
|
|
||||||
.expect("Send message to event loop");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
window::Action::Close => {
|
||||||
|
proxy
|
||||||
|
.send_event(Event::CloseWindow(id))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
|
window::Action::Resize { width, height } => {
|
||||||
|
let window = windows.get(&id).expect("No window found");
|
||||||
|
window.set_inner_size(glutin::dpi::LogicalSize {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window::Action::Move { x, y } => {
|
||||||
|
let window = windows.get(&id).expect("No window found");
|
||||||
|
window.set_outer_position(glutin::dpi::LogicalPosition {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window::Action::SetMode(mode) => {
|
||||||
|
let window = windows.get(&id).expect("No window found");
|
||||||
|
window.set_visible(conversion::visible(mode));
|
||||||
|
window.set_fullscreen(conversion::fullscreen(
|
||||||
|
window.primary_monitor(),
|
||||||
|
mode,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
window::Action::FetchMode(tag) => {
|
||||||
|
let window = windows.get(&id).expect("No window found");
|
||||||
|
let mode = if window.is_visible().unwrap_or(true) {
|
||||||
|
conversion::mode(window.fullscreen())
|
||||||
|
} else {
|
||||||
|
window::Mode::Hidden
|
||||||
|
};
|
||||||
|
|
||||||
|
proxy
|
||||||
|
.send_event(Event::Application(tag(mode)))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
|
},
|
||||||
command::Action::System(action) => match action {
|
command::Action::System(action) => match action {
|
||||||
system::Action::QueryInformation(_tag) => {
|
system::Action::QueryInformation(_tag) => {
|
||||||
#[cfg(feature = "iced_winit/system")]
|
#[cfg(feature = "iced_winit/system")]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::window::{Mode, UserAttention};
|
use crate::window::{self, Mode, UserAttention};
|
||||||
|
|
||||||
use iced_futures::MaybeSend;
|
use iced_futures::MaybeSend;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
@ -13,6 +13,11 @@ pub enum Action<T> {
|
||||||
/// There’s no guarantee that this will work unless the left mouse
|
/// There’s no guarantee that this will work unless the left mouse
|
||||||
/// button was pressed immediately before this function is called.
|
/// button was pressed immediately before this function is called.
|
||||||
Drag,
|
Drag,
|
||||||
|
/// TODO(derezzedex)
|
||||||
|
Spawn {
|
||||||
|
/// TODO(derezzedex)
|
||||||
|
settings: window::Settings,
|
||||||
|
},
|
||||||
/// Resize the window.
|
/// Resize the window.
|
||||||
Resize {
|
Resize {
|
||||||
/// The new logical width of the window
|
/// The new logical width of the window
|
||||||
|
|
@ -34,9 +39,9 @@ pub enum Action<T> {
|
||||||
y: i32,
|
y: i32,
|
||||||
},
|
},
|
||||||
/// Set the [`Mode`] of the window.
|
/// Set the [`Mode`] of the window.
|
||||||
SetMode(Mode),
|
SetMode(window::Mode),
|
||||||
/// Fetch the current [`Mode`] of the window.
|
/// Fetch the current [`Mode`] of the window.
|
||||||
FetchMode(Box<dyn FnOnce(Mode) -> T + 'static>),
|
FetchMode(Box<dyn FnOnce(window::Mode) -> T + 'static>),
|
||||||
/// Sets the window to maximized or back
|
/// Sets the window to maximized or back
|
||||||
ToggleMaximize,
|
ToggleMaximize,
|
||||||
/// Toggles whether window has decorations
|
/// Toggles whether window has decorations
|
||||||
|
|
@ -81,6 +86,7 @@ impl<T> Action<T> {
|
||||||
T: 'static,
|
T: 'static,
|
||||||
{
|
{
|
||||||
match self {
|
match self {
|
||||||
|
Self::Spawn { settings } => Action::Spawn { settings },
|
||||||
Self::Close => Action::Close,
|
Self::Close => Action::Close,
|
||||||
Self::Drag => Action::Drag,
|
Self::Drag => Action::Drag,
|
||||||
Self::Resize { width, height } => Action::Resize { width, height },
|
Self::Resize { width, height } => Action::Resize { width, height },
|
||||||
|
|
@ -104,6 +110,9 @@ impl<T> fmt::Debug for Action<T> {
|
||||||
match self {
|
match self {
|
||||||
Self::Close => write!(f, "Action::Close"),
|
Self::Close => write!(f, "Action::Close"),
|
||||||
Self::Drag => write!(f, "Action::Drag"),
|
Self::Drag => write!(f, "Action::Drag"),
|
||||||
|
Self::Spawn { settings } => {
|
||||||
|
write!(f, "Action::Spawn {{ settings: {:?} }}", settings)
|
||||||
|
}
|
||||||
Self::Resize { width, height } => write!(
|
Self::Resize { width, height } => write!(
|
||||||
f,
|
f,
|
||||||
"Action::Resize {{ widget: {}, height: {} }}",
|
"Action::Resize {{ widget: {}, height: {} }}",
|
||||||
|
|
|
||||||
|
|
@ -675,6 +675,11 @@ pub fn run_command<A, E>(
|
||||||
window::Action::Drag => {
|
window::Action::Drag => {
|
||||||
let _res = window.drag_window();
|
let _res = window.drag_window();
|
||||||
}
|
}
|
||||||
|
window::Action::Spawn { .. } | window::Action::Close => {
|
||||||
|
log::info!(
|
||||||
|
"This is only available on `multi_window::Application`"
|
||||||
|
)
|
||||||
|
}
|
||||||
window::Action::Resize { width, height } => {
|
window::Action::Resize { width, height } => {
|
||||||
window.set_inner_size(winit::dpi::LogicalSize {
|
window.set_inner_size(winit::dpi::LogicalSize {
|
||||||
width,
|
width,
|
||||||
|
|
|
||||||
|
|
@ -855,41 +855,52 @@ pub fn run_command<A, E>(
|
||||||
clipboard.write(contents);
|
clipboard.write(contents);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
command::Action::Window(id, action) => {
|
command::Action::Window(id, action) => match action {
|
||||||
let window = windows.get(&id).expect("No window found");
|
window::Action::Spawn { settings } => {
|
||||||
|
proxy
|
||||||
match action {
|
.send_event(Event::NewWindow(id, settings.into()))
|
||||||
window::Action::Resize { width, height } => {
|
.expect("Send message to event loop");
|
||||||
window.set_inner_size(winit::dpi::LogicalSize {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
window::Action::Move { x, y } => {
|
|
||||||
window.set_outer_position(
|
|
||||||
winit::dpi::LogicalPosition { x, y },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
window::Action::SetMode(mode) => {
|
|
||||||
window.set_visible(conversion::visible(mode));
|
|
||||||
window.set_fullscreen(conversion::fullscreen(
|
|
||||||
window.primary_monitor(),
|
|
||||||
mode,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
window::Action::FetchMode(tag) => {
|
|
||||||
let mode = if window.is_visible().unwrap_or(true) {
|
|
||||||
conversion::mode(window.fullscreen())
|
|
||||||
} else {
|
|
||||||
window::Mode::Hidden
|
|
||||||
};
|
|
||||||
|
|
||||||
proxy
|
|
||||||
.send_event(Event::Application(tag(mode)))
|
|
||||||
.expect("Send message to event loop");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
window::Action::Close => {
|
||||||
|
proxy
|
||||||
|
.send_event(Event::CloseWindow(id))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
|
window::Action::Resize { width, height } => {
|
||||||
|
let window = windows.get(&id).expect("No window found");
|
||||||
|
window.set_inner_size(winit::dpi::LogicalSize {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window::Action::Move { x, y } => {
|
||||||
|
let window = windows.get(&id).expect("No window found");
|
||||||
|
window.set_outer_position(winit::dpi::LogicalPosition {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window::Action::SetMode(mode) => {
|
||||||
|
let window = windows.get(&id).expect("No window found");
|
||||||
|
window.set_visible(conversion::visible(mode));
|
||||||
|
window.set_fullscreen(conversion::fullscreen(
|
||||||
|
window.primary_monitor(),
|
||||||
|
mode,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
window::Action::FetchMode(tag) => {
|
||||||
|
let window = windows.get(&id).expect("No window found");
|
||||||
|
let mode = if window.is_visible().unwrap_or(true) {
|
||||||
|
conversion::mode(window.fullscreen())
|
||||||
|
} else {
|
||||||
|
window::Mode::Hidden
|
||||||
|
};
|
||||||
|
|
||||||
|
proxy
|
||||||
|
.send_event(Event::Application(tag(mode)))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
|
},
|
||||||
command::Action::System(action) => match action {
|
command::Action::System(action) => match action {
|
||||||
system::Action::QueryInformation(_tag) => {
|
system::Action::QueryInformation(_tag) => {
|
||||||
#[cfg(feature = "system")]
|
#[cfg(feature = "system")]
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,22 @@ pub fn drag<Message>() -> Command<Message> {
|
||||||
Command::single(command::Action::Window(window::Action::Drag))
|
Command::single(command::Action::Window(window::Action::Drag))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// TODO(derezzedex)
|
||||||
|
pub fn spawn<Message>(
|
||||||
|
id: window::Id,
|
||||||
|
settings: window::Settings,
|
||||||
|
) -> Command<Message> {
|
||||||
|
Command::single(command::Action::Window(
|
||||||
|
id,
|
||||||
|
window::Action::Spawn { settings },
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO(derezzedex)
|
||||||
|
pub fn close<Message>(id: window::Id) -> Command<Message> {
|
||||||
|
Command::single(command::Action::Window(id, window::Action::Close))
|
||||||
|
}
|
||||||
|
|
||||||
/// Resizes the window to the given logical dimensions.
|
/// Resizes the window to the given logical dimensions.
|
||||||
pub fn resize<Message>(
|
pub fn resize<Message>(
|
||||||
id: window::Id,
|
id: window::Id,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue