Add command to retrieve window size
This commit is contained in:
parent
59bb5a99aa
commit
21a71b753d
4 changed files with 42 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ mod level;
|
|||
mod mode;
|
||||
mod redraw_request;
|
||||
mod user_attention;
|
||||
mod fetch_size;
|
||||
|
||||
pub use event::Event;
|
||||
pub use icon::Icon;
|
||||
|
|
@ -13,3 +14,4 @@ pub use level::Level;
|
|||
pub use mode::Mode;
|
||||
pub use redraw_request::RedrawRequest;
|
||||
pub use user_attention::UserAttention;
|
||||
pub use fetch_size::SizeType;
|
||||
8
core/src/window/fetch_size.rs
Normal file
8
core/src/window/fetch_size.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/// A `struct` defining which size to fetch.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum SizeType {
|
||||
/// Inner size. (not including title bars and so other OS decorations)
|
||||
Inner,
|
||||
/// Outer size. (including everything)
|
||||
Outer,
|
||||
}
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
|
||||
|
||||
use iced_core::window::SizeType;
|
||||
|
||||
use crate::core::window::{Icon, Level, Mode, UserAttention};
|
||||
use crate::futures::MaybeSend;
|
||||
|
||||
|
|
@ -20,6 +24,13 @@ pub enum Action<T> {
|
|||
/// The new logical height of the window
|
||||
height: u32,
|
||||
},
|
||||
/// Fetch the current size of the window.
|
||||
FetchSize {
|
||||
/// Which size to fetch
|
||||
size_type: SizeType,
|
||||
/// Callback function
|
||||
callback: Box<dyn FnOnce((u32, u32)) -> T + 'static>,
|
||||
},
|
||||
/// Set the window to maximized or back
|
||||
Maximize(bool),
|
||||
/// Set the window to minimized or back
|
||||
|
|
@ -104,6 +115,10 @@ impl<T> Action<T> {
|
|||
Self::Close => Action::Close,
|
||||
Self::Drag => Action::Drag,
|
||||
Self::Resize { width, height } => Action::Resize { width, height },
|
||||
Self::FetchSize { size_type, callback } => Action::FetchSize {
|
||||
size_type: size_type,
|
||||
callback: Box::new(move |s| f(callback(s))),
|
||||
},
|
||||
Self::Maximize(maximized) => Action::Maximize(maximized),
|
||||
Self::Minimize(minimized) => Action::Minimize(minimized),
|
||||
Self::Move { x, y } => Action::Move { x, y },
|
||||
|
|
@ -131,6 +146,7 @@ impl<T> fmt::Debug for Action<T> {
|
|||
f,
|
||||
"Action::Resize {{ widget: {width}, height: {height} }}"
|
||||
),
|
||||
Self::FetchSize { size_type, .. } => write!(f, "Action::FetchSize {{ size_type: {size_type:?} }}"),
|
||||
Self::Maximize(maximized) => {
|
||||
write!(f, "Action::Maximize({maximized})")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
mod profiler;
|
||||
mod state;
|
||||
|
||||
use iced_graphics::core::window::SizeType;
|
||||
pub use state::State;
|
||||
|
||||
use crate::conversion;
|
||||
|
|
@ -747,6 +748,21 @@ pub fn run_command<A, E>(
|
|||
height,
|
||||
});
|
||||
}
|
||||
window::Action::FetchSize {
|
||||
size_type,
|
||||
callback,
|
||||
} => {
|
||||
let width_height = match size_type {
|
||||
SizeType::Inner => window.inner_size(),
|
||||
SizeType::Outer => window.outer_size(),
|
||||
};
|
||||
let width_height =
|
||||
(width_height.width, width_height.height);
|
||||
|
||||
proxy
|
||||
.send_event(callback(width_height))
|
||||
.expect("Send message to event loop")
|
||||
}
|
||||
window::Action::Maximize(maximized) => {
|
||||
window.set_maximized(maximized);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue