-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add window drag move and drag resize without decoration example. #15814
Add window drag move and drag resize without decoration example. #15814
Conversation
@IsseW can I get your review here? |
I can review tomorrow! |
Re: unsafe I've submitted a PR to winit so it may not panic in the future when a left-click event isn't present, which I'd then be satisfied without any unsafe markers on the functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good, just one comment about a newline.
Cargo.toml
Outdated
@@ -2934,6 +2934,7 @@ name = "window_fallthrough" | |||
path = "examples/ui/window_fallthrough.rs" | |||
doc-scrape-examples = true | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this added by mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was a mistake. Will fix.
@@ -379,7 +379,7 @@ impl Window { | |||
/// | |||
/// There is no guarantee that this will work unless the left mouse button was | |||
/// pressed immediately before this function was called. | |||
pub fn start_drag_resize(&mut self, direction: ResizeDirection) { | |||
pub fn start_drag_resize(&mut self, direction: CompassOctant) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea of using the existing CompassOctant
😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few naming nits, I like the example 👍
Works on Windows 11
One side question, would it be possible to call redraw while we're resizing, so window gets updated immediately, rather than just stretching until we're done?
examples/window/window_drag_move.rs
Outdated
} | ||
} | ||
|
||
fn move_windows( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn move_windows( | |
fn move_or_resize_window( |
examples/window/window_drag_move.rs
Outdated
for mut window in windows.iter_mut() { | ||
match *action { | ||
LeftClickAction::Nothing => (), | ||
LeftClickAction::Drag => window.start_drag_move(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LeftClickAction::Drag => window.start_drag_move(), | |
LeftClickAction::Move => window.start_drag_move(), |
this would be more consistent with drag_move
vs drag_resize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only nits
examples/window/window_drag_move.rs
Outdated
//! | ||
//! When window decorations are not present, the user cannot drag the window. | ||
//! The `start_drag_move()` function will permit the application to make the | ||
//! window draggable. It does require that the left mouse button was pressed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is being pressed sounds better to me. Currently the tenses are conflicting.
examples/window/window_drag_move.rs
Outdated
//! When window decorations are not present, the user cannot drag the window. | ||
//! The `start_drag_move()` function will permit the application to make the | ||
//! window draggable. It does require that the left mouse button was pressed | ||
//! when it is called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When (inconsistent capitalization with other comments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize. I don't quite follow this suggestion. I have rewritten that paragraph. Please see if your comment still applies.
@shanecelis this needs minor changes following #15887. |
Will do. |
Some refactoring from feedback too.
Strange. CI failed, but the same command works on my M2 macOS. It complains about the UiTextWriter not being found, which is strange because many examples use that symbol. |
It's |
Objective
Add an example for the new drag move and drag resize introduced by PR #15674 and fix #15734.
Solution
I created an example that allows the user to exercise drag move and drag resize separately. The user can also choose what direction the resize works in.
Name
The example is called
window_drag_move
. Happy to have that bikeshedded.Contentious Refactor?
This PR removed the
ResizeDirection
enumeration in favor of usingCompassOctant
which had the same variants. Perhaps this is contentious.Unsafe?
In PR #15674 I mentioned that
start_drag_move()
andstart_drag_resize()
's requirement to only be called in the presence of a left-click looks like a compiler-unenforceable contract that can cause intermittent panics when not observed, so perhaps the functions should be marked them unsafe. I have not made that change here since I didn't see a clear consensus on that.Testing
I exercised this on x86 macOS. However, winit for macOS does not support drag resize. It reports a good error when
start_drag_resize()
is called. I'd like to see it tested on Windows and Linux.Showcase
Example window_drag_move shows how to drag or resize a window without decoration.