Use Size in both Resize and FetchSize window actions
This commit is contained in:
parent
b394c84b37
commit
cc32bd4de0
3 changed files with 15 additions and 18 deletions
|
|
@ -6,6 +6,7 @@ pub use action::Action;
|
||||||
use crate::command::{self, Command};
|
use crate::command::{self, Command};
|
||||||
use crate::core::time::Instant;
|
use crate::core::time::Instant;
|
||||||
use crate::core::window::{Event, Icon, Level, Mode, UserAttention};
|
use crate::core::window::{Event, Icon, Level, Mode, UserAttention};
|
||||||
|
use crate::core::Size;
|
||||||
use crate::futures::subscription::{self, Subscription};
|
use crate::futures::subscription::{self, Subscription};
|
||||||
|
|
||||||
/// Subscribes to the frames of the window of the running application.
|
/// Subscribes to the frames of the window of the running application.
|
||||||
|
|
@ -34,8 +35,8 @@ pub fn drag<Message>() -> Command<Message> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resizes the window to the given logical dimensions.
|
/// Resizes the window to the given logical dimensions.
|
||||||
pub fn resize<Message>(width: u32, height: u32) -> Command<Message> {
|
pub fn resize<Message>(new_size: Size<u32>) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(Action::Resize { width, height }))
|
Command::single(command::Action::Window(Action::Resize(new_size)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Maximizes the window.
|
/// Maximizes the window.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::core::window::{Icon, Level, Mode, UserAttention};
|
use crate::core::window::{Icon, Level, Mode, UserAttention};
|
||||||
|
use crate::core::Size;
|
||||||
use crate::futures::MaybeSend;
|
use crate::futures::MaybeSend;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
@ -14,14 +15,9 @@ pub enum Action<T> {
|
||||||
/// button was pressed immediately before this function is called.
|
/// button was pressed immediately before this function is called.
|
||||||
Drag,
|
Drag,
|
||||||
/// Resize the window.
|
/// Resize the window.
|
||||||
Resize {
|
Resize(Size<u32>),
|
||||||
/// The new logical width of the window
|
|
||||||
width: u32,
|
|
||||||
/// The new logical height of the window
|
|
||||||
height: u32,
|
|
||||||
},
|
|
||||||
/// Fetch the current size of the window.
|
/// Fetch the current size of the window.
|
||||||
FetchSize(Box<dyn FnOnce((u32, u32)) -> T + 'static>),
|
FetchSize(Box<dyn FnOnce(Size<u32>) -> T + 'static>),
|
||||||
/// Set the window to maximized or back
|
/// Set the window to maximized or back
|
||||||
Maximize(bool),
|
Maximize(bool),
|
||||||
/// Set the window to minimized or back
|
/// Set the window to minimized or back
|
||||||
|
|
@ -105,7 +101,7 @@ impl<T> Action<T> {
|
||||||
match self {
|
match self {
|
||||||
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(size) => Action::Resize(size),
|
||||||
Self::FetchSize(o) => Action::FetchSize(Box::new(move |s| f(o(s)))),
|
Self::FetchSize(o) => Action::FetchSize(Box::new(move |s| f(o(s)))),
|
||||||
Self::Maximize(maximized) => Action::Maximize(maximized),
|
Self::Maximize(maximized) => Action::Maximize(maximized),
|
||||||
Self::Minimize(minimized) => Action::Minimize(minimized),
|
Self::Minimize(minimized) => Action::Minimize(minimized),
|
||||||
|
|
@ -130,10 +126,7 @@ 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::Resize { width, height } => write!(
|
Self::Resize(size) => write!(f, "Action::Resize({size:?})"),
|
||||||
f,
|
|
||||||
"Action::Resize {{ widget: {width}, height: {height} }}"
|
|
||||||
),
|
|
||||||
Self::FetchSize(_) => write!(f, "Action::FetchSize"),
|
Self::FetchSize(_) => write!(f, "Action::FetchSize"),
|
||||||
Self::Maximize(maximized) => {
|
Self::Maximize(maximized) => {
|
||||||
write!(f, "Action::Maximize({maximized})")
|
write!(f, "Action::Maximize({maximized})")
|
||||||
|
|
|
||||||
|
|
@ -741,17 +741,20 @@ pub fn run_command<A, E>(
|
||||||
window::Action::Drag => {
|
window::Action::Drag => {
|
||||||
let _res = window.drag_window();
|
let _res = window.drag_window();
|
||||||
}
|
}
|
||||||
window::Action::Resize { width, height } => {
|
window::Action::Resize(size) => {
|
||||||
window.set_inner_size(winit::dpi::LogicalSize {
|
window.set_inner_size(winit::dpi::LogicalSize {
|
||||||
width,
|
width: size.width,
|
||||||
height,
|
height: size.height,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
window::Action::FetchSize(callback) => {
|
window::Action::FetchSize(callback) => {
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
proxy
|
proxy
|
||||||
.send_event(callback((size.width, size.height)))
|
.send_event(callback(Size::new(
|
||||||
|
size.width,
|
||||||
|
size.height,
|
||||||
|
)))
|
||||||
.expect("Send message to event loop")
|
.expect("Send message to event loop")
|
||||||
}
|
}
|
||||||
window::Action::Maximize(maximized) => {
|
window::Action::Maximize(maximized) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue