Merge pull request #2642 from tsuza/master
feat: add a window drag resize task
This commit is contained in:
commit
24297c549b
5 changed files with 76 additions and 3 deletions
|
|
@ -3,6 +3,7 @@ pub mod icon;
|
||||||
pub mod screenshot;
|
pub mod screenshot;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
|
||||||
|
mod direction;
|
||||||
mod event;
|
mod event;
|
||||||
mod id;
|
mod id;
|
||||||
mod level;
|
mod level;
|
||||||
|
|
@ -11,6 +12,7 @@ mod position;
|
||||||
mod redraw_request;
|
mod redraw_request;
|
||||||
mod user_attention;
|
mod user_attention;
|
||||||
|
|
||||||
|
pub use direction::Direction;
|
||||||
pub use event::Event;
|
pub use event::Event;
|
||||||
pub use icon::Icon;
|
pub use icon::Icon;
|
||||||
pub use id::Id;
|
pub use id::Id;
|
||||||
|
|
|
||||||
27
core/src/window/direction.rs
Normal file
27
core/src/window/direction.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/// The cardinal directions relative to the center of a window.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum Direction {
|
||||||
|
/// Points to the top edge of a window.
|
||||||
|
North,
|
||||||
|
|
||||||
|
/// Points to the bottom edge of a window.
|
||||||
|
South,
|
||||||
|
|
||||||
|
/// Points to the right edge of a window.
|
||||||
|
East,
|
||||||
|
|
||||||
|
/// Points to the left edge of a window.
|
||||||
|
West,
|
||||||
|
|
||||||
|
/// Points to the top-right corner of a window.
|
||||||
|
NorthEast,
|
||||||
|
|
||||||
|
/// Points to the top-left corner of a window.
|
||||||
|
NorthWest,
|
||||||
|
|
||||||
|
/// Points to the bottom-right corner of a window.
|
||||||
|
SouthEast,
|
||||||
|
|
||||||
|
/// Points to the bottom-left corner of a window.
|
||||||
|
SouthWest,
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
//! Build window-based GUI applications.
|
//! Build window-based GUI applications.
|
||||||
use crate::core::time::Instant;
|
use crate::core::time::Instant;
|
||||||
use crate::core::window::{
|
use crate::core::window::{
|
||||||
Event, Icon, Id, Level, Mode, Screenshot, Settings, UserAttention,
|
Direction, Event, Icon, Id, Level, Mode, Screenshot, Settings,
|
||||||
|
UserAttention,
|
||||||
};
|
};
|
||||||
use crate::core::{Point, Size};
|
use crate::core::{Point, Size};
|
||||||
use crate::futures::event;
|
use crate::futures::event;
|
||||||
|
|
@ -31,10 +32,17 @@ pub enum Action {
|
||||||
/// Move the window with the left mouse button until the button is
|
/// Move the window with the left mouse button until the button is
|
||||||
/// released.
|
/// released.
|
||||||
///
|
///
|
||||||
/// 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(Id),
|
Drag(Id),
|
||||||
|
|
||||||
|
/// Resize the window with the left mouse button until the button is
|
||||||
|
/// released.
|
||||||
|
///
|
||||||
|
/// There's no guarantee that this will work unless the left mouse
|
||||||
|
/// button was pressed immediately before this function is called.
|
||||||
|
DragResize(Id, Direction),
|
||||||
|
|
||||||
/// Resize the window to the given logical dimensions.
|
/// Resize the window to the given logical dimensions.
|
||||||
Resize(Id, Size),
|
Resize(Id, Size),
|
||||||
|
|
||||||
|
|
@ -272,6 +280,11 @@ pub fn drag<T>(id: Id) -> Task<T> {
|
||||||
task::effect(crate::Action::Window(Action::Drag(id)))
|
task::effect(crate::Action::Window(Action::Drag(id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Begins resizing the window while the left mouse button is held.
|
||||||
|
pub fn drag_resize<T>(id: Id, direction: Direction) -> Task<T> {
|
||||||
|
task::effect(crate::Action::Window(Action::DragResize(id, direction)))
|
||||||
|
}
|
||||||
|
|
||||||
/// Resizes the window to the given logical dimensions.
|
/// Resizes the window to the given logical dimensions.
|
||||||
pub fn resize<T>(id: Id, new_size: Size) -> Task<T> {
|
pub fn resize<T>(id: Id, new_size: Size) -> Task<T> {
|
||||||
task::effect(crate::Action::Window(Action::Resize(id, new_size)))
|
task::effect(crate::Action::Window(Action::Resize(id, new_size)))
|
||||||
|
|
|
||||||
|
|
@ -1120,7 +1120,7 @@ pub fn native_key_code(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts some [`UserAttention`] into it's `winit` counterpart.
|
/// Converts some [`UserAttention`] into its `winit` counterpart.
|
||||||
///
|
///
|
||||||
/// [`UserAttention`]: window::UserAttention
|
/// [`UserAttention`]: window::UserAttention
|
||||||
pub fn user_attention(
|
pub fn user_attention(
|
||||||
|
|
@ -1136,6 +1136,30 @@ pub fn user_attention(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts some [`window::Direction`] into a [`winit::window::ResizeDirection`].
|
||||||
|
pub fn resize_direction(
|
||||||
|
resize_direction: window::Direction,
|
||||||
|
) -> winit::window::ResizeDirection {
|
||||||
|
match resize_direction {
|
||||||
|
window::Direction::North => winit::window::ResizeDirection::North,
|
||||||
|
window::Direction::South => winit::window::ResizeDirection::South,
|
||||||
|
window::Direction::East => winit::window::ResizeDirection::East,
|
||||||
|
window::Direction::West => winit::window::ResizeDirection::West,
|
||||||
|
window::Direction::NorthEast => {
|
||||||
|
winit::window::ResizeDirection::NorthEast
|
||||||
|
}
|
||||||
|
window::Direction::NorthWest => {
|
||||||
|
winit::window::ResizeDirection::NorthWest
|
||||||
|
}
|
||||||
|
window::Direction::SouthEast => {
|
||||||
|
winit::window::ResizeDirection::SouthEast
|
||||||
|
}
|
||||||
|
window::Direction::SouthWest => {
|
||||||
|
winit::window::ResizeDirection::SouthWest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts some [`window::Icon`] into it's `winit` counterpart.
|
/// Converts some [`window::Icon`] into it's `winit` counterpart.
|
||||||
///
|
///
|
||||||
/// Returns `None` if there is an error during the conversion.
|
/// Returns `None` if there is an error during the conversion.
|
||||||
|
|
|
||||||
|
|
@ -1265,6 +1265,13 @@ fn run_action<P, C>(
|
||||||
let _ = window.raw.drag_window();
|
let _ = window.raw.drag_window();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window::Action::DragResize(id, direction) => {
|
||||||
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
|
let _ = window.raw.drag_resize_window(
|
||||||
|
conversion::resize_direction(direction),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
window::Action::Resize(id, size) => {
|
window::Action::Resize(id, size) => {
|
||||||
if let Some(window) = window_manager.get_mut(id) {
|
if let Some(window) = window_manager.get_mut(id) {
|
||||||
let _ = window.raw.request_inner_size(
|
let _ = window.raw.request_inner_size(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue