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