fix: resize border
This commit is contained in:
parent
40b6bfe9ca
commit
a839760e2a
5 changed files with 60 additions and 23 deletions
|
|
@ -56,6 +56,9 @@ pub struct Settings {
|
|||
/// Whether the window should be resizable or not.
|
||||
pub resizable: bool,
|
||||
|
||||
/// The border area for the drag resize handle.
|
||||
pub resize_border: u32,
|
||||
|
||||
/// Whether the title bar has Close button or not
|
||||
pub closeable: bool,
|
||||
|
||||
|
|
@ -120,6 +123,7 @@ impl Default for Settings {
|
|||
icon: None,
|
||||
exit_on_close_request: true,
|
||||
platform_specific: PlatformSpecific::default(),
|
||||
resize_border: 8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use winit::window::{CursorIcon, ResizeDirection};
|
||||
use cursor_icon::CursorIcon;
|
||||
use winit::window::ResizeDirection;
|
||||
|
||||
#[cfg(any(
|
||||
all(
|
||||
|
|
@ -44,8 +45,9 @@ pub fn event_func(
|
|||
-> bool {
|
||||
// Keep track of border resize state and set cursor icon when in range
|
||||
match window_event {
|
||||
winit::event::WindowEvent::CursorMoved {
|
||||
position, ..
|
||||
winit::event::WindowEvent::PointerMoved {
|
||||
position,
|
||||
..
|
||||
} => {
|
||||
if !window.is_decorated() {
|
||||
let location = cursor_resize_direction(
|
||||
|
|
@ -63,9 +65,16 @@ pub fn event_func(
|
|||
}
|
||||
}
|
||||
}
|
||||
winit::event::WindowEvent::MouseInput {
|
||||
winit::event::WindowEvent::PointerButton {
|
||||
state: winit::event::ElementState::Pressed,
|
||||
button: winit::event::MouseButton::Left,
|
||||
button:
|
||||
winit::event::ButtonSource::Mouse(
|
||||
winit::event::MouseButton::Left,
|
||||
)
|
||||
| winit::event::ButtonSource::Touch {
|
||||
finger_id: _, ..
|
||||
},
|
||||
primary: true,
|
||||
..
|
||||
} => {
|
||||
if let Some(direction) = cursor_prev_resize_direction {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@
|
|||
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
||||
)]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
|
||||
#[path = "application/drag_resize.rs"]
|
||||
mod drag_resize;
|
||||
|
||||
use dnd::DndSurface;
|
||||
pub use iced_debug as debug;
|
||||
pub use iced_program as program;
|
||||
|
|
@ -404,7 +408,7 @@ where
|
|||
#[cfg(target_arch = "wasm32")]
|
||||
let target =
|
||||
settings.platform_specific.target.clone();
|
||||
|
||||
let resize_border = settings.resize_border;
|
||||
let window_attributes =
|
||||
conversion::window_attributes(
|
||||
settings,
|
||||
|
|
@ -500,6 +504,7 @@ where
|
|||
exit_on_close_request,
|
||||
make_visible: visible,
|
||||
on_open,
|
||||
resize_border,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -667,6 +672,7 @@ enum Event<Message: 'static> {
|
|||
exit_on_close_request: bool,
|
||||
make_visible: bool,
|
||||
on_open: oneshot::Sender<window::Id>,
|
||||
resize_border: u32,
|
||||
},
|
||||
Exit,
|
||||
Dnd(dnd::DndEvent<dnd::DndSurface>),
|
||||
|
|
@ -824,6 +830,7 @@ async fn run_instance<P>(
|
|||
exit_on_close_request,
|
||||
make_visible,
|
||||
on_open,
|
||||
resize_border
|
||||
} => {
|
||||
#[cfg(feature = "a11y")]
|
||||
control_sender
|
||||
|
|
@ -882,6 +889,7 @@ async fn run_instance<P>(
|
|||
compositor,
|
||||
exit_on_close_request,
|
||||
system_theme,
|
||||
resize_border
|
||||
);
|
||||
|
||||
window.raw.set_theme(conversion::window_theme(
|
||||
|
|
@ -1287,7 +1295,14 @@ async fn run_instance<P>(
|
|||
else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// Initiates a drag resize window state when found.
|
||||
if let Some(func) =
|
||||
window.drag_resize_window_func.as_mut()
|
||||
{
|
||||
if func(window.raw.as_ref(), &event) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
match event {
|
||||
winit::event::WindowEvent::SurfaceResized(_) => {
|
||||
window.raw.request_redraw();
|
||||
|
|
|
|||
|
|
@ -795,6 +795,7 @@ impl SctkEvent {
|
|||
compositor,
|
||||
false, // TODO do we want to get this value here?
|
||||
theme::Mode::None, // TODO do we really need to track the system theme here?
|
||||
0,
|
||||
);
|
||||
_ = surface_ids.insert(object_id, wrapper.clone());
|
||||
let logical_size = window.logical_size();
|
||||
|
|
@ -1009,6 +1010,7 @@ impl SctkEvent {
|
|||
compositor,
|
||||
false, // TODO do we want to get this value here?
|
||||
theme::Mode::None, // TODO do we really need to track the system theme here?
|
||||
0,
|
||||
);
|
||||
window.state.ready = false;
|
||||
let logical_size = window.logical_size();
|
||||
|
|
@ -1098,9 +1100,8 @@ impl SctkEvent {
|
|||
proxy.wake_up();
|
||||
}
|
||||
let physical = w.raw.surface_size();
|
||||
let (p_w, p_h) = if physical.width > 0
|
||||
&& physical.height > 0
|
||||
{
|
||||
let (p_w, p_h) =
|
||||
if physical.width > 0 && physical.height > 0 {
|
||||
(physical.width, physical.height)
|
||||
} else {
|
||||
// Fallback if backend has not reported an updated
|
||||
|
|
@ -1108,9 +1109,11 @@ impl SctkEvent {
|
|||
let scale = w.state.scale_factor();
|
||||
(
|
||||
(configure.width.max(1) as f64 * scale)
|
||||
.ceil() as u32,
|
||||
.ceil()
|
||||
as u32,
|
||||
(configure.height.max(1) as f64 * scale)
|
||||
.ceil() as u32,
|
||||
.ceil()
|
||||
as u32,
|
||||
)
|
||||
};
|
||||
|
||||
|
|
@ -1261,6 +1264,7 @@ impl SctkEvent {
|
|||
compositor,
|
||||
false, // TODO do we want to get this value here?
|
||||
theme::Mode::None, // TODO do we really need to track the system theme here?
|
||||
0,
|
||||
);
|
||||
_ = surface_ids.insert(object_id, wrapper.clone());
|
||||
let logical_size = window.logical_size();
|
||||
|
|
@ -1575,6 +1579,7 @@ impl SctkEvent {
|
|||
compositor,
|
||||
false, // TODO do we want to get this value here?
|
||||
theme::Mode::None,
|
||||
0,
|
||||
);
|
||||
let logical_size = window.logical_size();
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ where
|
|||
compositor: &mut C,
|
||||
exit_on_close_request: bool,
|
||||
system_theme: theme::Mode,
|
||||
resize_border: u32,
|
||||
) -> &mut Window<P, C> {
|
||||
let state = State::new(program, id, system_theme, window.as_ref());
|
||||
let surface_size = state.physical_size();
|
||||
|
|
@ -79,6 +80,10 @@ where
|
|||
let _ = self.entries.insert(
|
||||
id,
|
||||
Window {
|
||||
drag_resize_window_func: super::drag_resize::event_func(
|
||||
window.as_ref(),
|
||||
resize_border as f64 * window.scale_factor(),
|
||||
),
|
||||
raw: window,
|
||||
state,
|
||||
exit_on_close_request,
|
||||
|
|
@ -89,7 +94,6 @@ where
|
|||
redraw_at: None,
|
||||
preedit: None,
|
||||
ime_state: None,
|
||||
drag_resize_window_func: None,
|
||||
prev_dnd_destination_rectangles_count: 0,
|
||||
viewport_version: 0,
|
||||
redraw_requested: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue