Rename fetch_location to fetch_position
This commit is contained in:
parent
59885e9a36
commit
d6454b5d0c
4 changed files with 47 additions and 45 deletions
|
|
@ -101,22 +101,22 @@ pub fn minimize<Message>(id: Id, minimized: bool) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(Action::Minimize(id, minimized)))
|
Command::single(command::Action::Window(Action::Minimize(id, minimized)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Moves the window to the given logical coordinates.
|
/// Fetches the current window position in logical coordinates.
|
||||||
pub fn move_to<Message>(id: Id, position: Point) -> Command<Message> {
|
pub fn fetch_position<Message>(
|
||||||
Command::single(command::Action::Window(Action::Move(id, position)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetches the window's location in logical coordinates.
|
|
||||||
pub fn fetch_location<Message>(
|
|
||||||
id: Id,
|
id: Id,
|
||||||
f: impl FnOnce(Option<Point>) -> Message + 'static,
|
f: impl FnOnce(Option<Point>) -> Message + 'static,
|
||||||
) -> Command<Message> {
|
) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(Action::FetchLocation(
|
Command::single(command::Action::Window(Action::FetchPosition(
|
||||||
id,
|
id,
|
||||||
Box::new(f),
|
Box::new(f),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Moves the window to the given logical coordinates.
|
||||||
|
pub fn move_to<Message>(id: Id, position: Point) -> Command<Message> {
|
||||||
|
Command::single(command::Action::Window(Action::Move(id, position)))
|
||||||
|
}
|
||||||
|
|
||||||
/// Changes the [`Mode`] of the window.
|
/// Changes the [`Mode`] of the window.
|
||||||
pub fn change_mode<Message>(id: Id, mode: Mode) -> Command<Message> {
|
pub fn change_mode<Message>(id: Id, mode: Mode) -> Command<Message> {
|
||||||
Command::single(command::Action::Window(Action::ChangeMode(id, mode)))
|
Command::single(command::Action::Window(Action::ChangeMode(id, mode)))
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,12 @@ pub enum Action<T> {
|
||||||
FetchMinimized(Id, Box<dyn FnOnce(Option<bool>) -> T + 'static>),
|
FetchMinimized(Id, Box<dyn FnOnce(Option<bool>) -> T + 'static>),
|
||||||
/// Set the window to minimized or back
|
/// Set the window to minimized or back
|
||||||
Minimize(Id, bool),
|
Minimize(Id, bool),
|
||||||
|
/// Fetch the current logical coordinates of the window.
|
||||||
|
FetchPosition(Id, Box<dyn FnOnce(Option<Point>) -> T + 'static>),
|
||||||
/// Move the window to the given logical coordinates.
|
/// Move the window to the given logical coordinates.
|
||||||
///
|
///
|
||||||
/// Unsupported on Wayland.
|
/// Unsupported on Wayland.
|
||||||
Move(Id, Point),
|
Move(Id, Point),
|
||||||
/// Fetch the current logical coordinates of the window.
|
|
||||||
FetchLocation(Id, Box<dyn FnOnce(Option<Point>) -> T + 'static>),
|
|
||||||
/// Change the [`Mode`] of the window.
|
/// Change the [`Mode`] of the window.
|
||||||
ChangeMode(Id, Mode),
|
ChangeMode(Id, Mode),
|
||||||
/// Fetch the current [`Mode`] of the window.
|
/// Fetch the current [`Mode`] of the window.
|
||||||
|
|
@ -136,10 +136,10 @@ impl<T> Action<T> {
|
||||||
Action::FetchMinimized(id, Box::new(move |s| f(o(s))))
|
Action::FetchMinimized(id, Box::new(move |s| f(o(s))))
|
||||||
}
|
}
|
||||||
Self::Minimize(id, minimized) => Action::Minimize(id, minimized),
|
Self::Minimize(id, minimized) => Action::Minimize(id, minimized),
|
||||||
Self::Move(id, position) => Action::Move(id, position),
|
Self::FetchPosition(id, o) => {
|
||||||
Self::FetchLocation(id, o) => {
|
Action::FetchPosition(id, Box::new(move |s| f(o(s))))
|
||||||
Action::FetchLocation(id, Box::new(move |s| f(o(s))))
|
|
||||||
}
|
}
|
||||||
|
Self::Move(id, position) => Action::Move(id, position),
|
||||||
Self::ChangeMode(id, mode) => Action::ChangeMode(id, mode),
|
Self::ChangeMode(id, mode) => Action::ChangeMode(id, mode),
|
||||||
Self::FetchMode(id, o) => {
|
Self::FetchMode(id, o) => {
|
||||||
Action::FetchMode(id, Box::new(move |s| f(o(s))))
|
Action::FetchMode(id, Box::new(move |s| f(o(s))))
|
||||||
|
|
@ -191,12 +191,12 @@ impl<T> fmt::Debug for Action<T> {
|
||||||
Self::Minimize(id, minimized) => {
|
Self::Minimize(id, minimized) => {
|
||||||
write!(f, "Action::Minimize({id:?}, {minimized}")
|
write!(f, "Action::Minimize({id:?}, {minimized}")
|
||||||
}
|
}
|
||||||
|
Self::FetchPosition(id, _) => {
|
||||||
|
write!(f, "Action::FetchPosition({id:?})")
|
||||||
|
}
|
||||||
Self::Move(id, position) => {
|
Self::Move(id, position) => {
|
||||||
write!(f, "Action::Move({id:?}, {position})")
|
write!(f, "Action::Move({id:?}, {position})")
|
||||||
}
|
}
|
||||||
Self::FetchLocation(id, _) => {
|
|
||||||
write!(f, "Action::FetchLocation({id:?})")
|
|
||||||
}
|
|
||||||
Self::ChangeMode(id, mode) => {
|
Self::ChangeMode(id, mode) => {
|
||||||
write!(f, "Action::SetMode({id:?}, {mode:?})")
|
write!(f, "Action::SetMode({id:?}, {mode:?})")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -767,19 +767,14 @@ pub fn run_command<A, C, E>(
|
||||||
window::Action::Minimize(_id, minimized) => {
|
window::Action::Minimize(_id, minimized) => {
|
||||||
window.set_minimized(minimized);
|
window.set_minimized(minimized);
|
||||||
}
|
}
|
||||||
window::Action::Move(_id, position) => {
|
window::Action::FetchPosition(_id, callback) => {
|
||||||
window.set_outer_position(winit::dpi::LogicalPosition {
|
|
||||||
x: position.x,
|
|
||||||
y: position.y,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
window::Action::FetchLocation(_id, callback) => {
|
|
||||||
let position = window
|
let position = window
|
||||||
.inner_position()
|
.inner_position()
|
||||||
.map(|p| {
|
.map(|position| {
|
||||||
let pos =
|
let position = position
|
||||||
p.to_logical::<f32>(window.scale_factor());
|
.to_logical::<f32>(window.scale_factor());
|
||||||
crate::core::Point::new(pos.x, pos.y)
|
|
||||||
|
crate::core::Point::new(position.x, position.y)
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
|
|
@ -787,6 +782,12 @@ pub fn run_command<A, C, E>(
|
||||||
.send_event(callback(position))
|
.send_event(callback(position))
|
||||||
.expect("Send message to event loop");
|
.expect("Send message to event loop");
|
||||||
}
|
}
|
||||||
|
window::Action::Move(_id, position) => {
|
||||||
|
window.set_outer_position(winit::dpi::LogicalPosition {
|
||||||
|
x: position.x,
|
||||||
|
y: position.y,
|
||||||
|
});
|
||||||
|
}
|
||||||
window::Action::ChangeMode(_id, mode) => {
|
window::Action::ChangeMode(_id, mode) => {
|
||||||
window.set_visible(conversion::visible(mode));
|
window.set_visible(conversion::visible(mode));
|
||||||
window.set_fullscreen(conversion::fullscreen(
|
window.set_fullscreen(conversion::fullscreen(
|
||||||
|
|
|
||||||
|
|
@ -993,6 +993,25 @@ fn run_command<A, C, E>(
|
||||||
window.raw.set_minimized(minimized);
|
window.raw.set_minimized(minimized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window::Action::FetchPosition(id, callback) => {
|
||||||
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
|
let position = window
|
||||||
|
.raw
|
||||||
|
.inner_position()
|
||||||
|
.map(|position| {
|
||||||
|
let position = position.to_logical::<f32>(
|
||||||
|
window.raw.scale_factor(),
|
||||||
|
);
|
||||||
|
|
||||||
|
crate::core::Point::new(position.x, position.y)
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
proxy
|
||||||
|
.send_event(callback(position))
|
||||||
|
.expect("Send message to event loop");
|
||||||
|
}
|
||||||
|
}
|
||||||
window::Action::Move(id, position) => {
|
window::Action::Move(id, position) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
window.raw.set_outer_position(
|
window.raw.set_outer_position(
|
||||||
|
|
@ -1003,24 +1022,6 @@ fn run_command<A, C, E>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window::Action::FetchLocation(id, callback) => {
|
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
|
||||||
let position = window
|
|
||||||
.raw
|
|
||||||
.inner_position()
|
|
||||||
.map(|p| {
|
|
||||||
let pos = p.to_logical::<f32>(
|
|
||||||
window.raw.scale_factor(),
|
|
||||||
);
|
|
||||||
crate::core::Point::new(pos.x, pos.y)
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
proxy
|
|
||||||
.send_event(callback(position))
|
|
||||||
.expect("Send message to event loop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
window::Action::ChangeMode(id, mode) => {
|
window::Action::ChangeMode(id, mode) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
window.raw.set_visible(conversion::visible(mode));
|
window.raw.set_visible(conversion::visible(mode));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue