Repository navigation
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. |
IsseW
left a comment
There was a problem hiding this comment.
I think this looks good, just one comment about a newline.
| path = "examples/ui/window_fallthrough.rs" | ||
| doc-scrape-examples = true | ||
|
|
||
|
|
There was a problem hiding this comment.
Yes, that was a mistake. Will fix.
| /// 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.
I like this idea of using the existing CompassOctant 😄
| } | ||
| } | ||
|
|
||
| fn move_windows( |
There was a problem hiding this comment.
| fn move_windows( | |
| fn move_or_resize_window( |
| for mut window in windows.iter_mut() { | ||
| match *action { | ||
| LeftClickAction::Nothing => (), | ||
| LeftClickAction::Drag => window.start_drag_move(), |
There was a problem hiding this comment.
| LeftClickAction::Drag => window.start_drag_move(), | |
| LeftClickAction::Move => window.start_drag_move(), |
this would be more consistent with drag_move vs drag_resize
| //! | ||
| //! 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.
is being pressed sounds better to me. Currently the tenses are conflicting.
| //! 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.
When (inconsistent capitalization with other comments)
There was a problem hiding this comment.
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
ResizeDirectionenumeration in favor of usingCompassOctantwhich 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.