Skip to content
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

Merged
merged 11 commits into from
Oct 15, 2024

Conversation

shanecelis
Copy link
Contributor

@shanecelis shanecelis commented Oct 10, 2024

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.

Screenshot 2024-10-10 at 4 06 43 AM

Name

The example is called window_drag_move. Happy to have that bikeshedded.

Contentious Refactor?

This PR removed the ResizeDirection enumeration in favor of using CompassOctant which had the same variants. Perhaps this is contentious.

Unsafe?

In PR #15674 I mentioned that start_drag_move() and start_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.

@alice-i-cecile alice-i-cecile added C-Examples An addition or correction to our examples A-Windowing Platform-agnostic interface layer to run your app in labels Oct 10, 2024
@alice-i-cecile
Copy link
Member

@IsseW can I get your review here?

@alice-i-cecile alice-i-cecile added D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge labels Oct 10, 2024
@IsseW
Copy link
Contributor

IsseW commented Oct 10, 2024

@IsseW can I get your review here?

I can review tomorrow!

@shanecelis
Copy link
Contributor Author

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.

Copy link
Contributor

@IsseW IsseW left a 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


Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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 😄

@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Oct 11, 2024
Copy link
Contributor

@MiniaczQ MiniaczQ left a 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?

}
}

fn move_windows(
Copy link
Contributor

@MiniaczQ MiniaczQ Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LeftClickAction::Drag => window.start_drag_move(),
LeftClickAction::Move => window.start_drag_move(),

this would be more consistent with drag_move vs drag_resize

Copy link
Contributor

@BenjaminBrienen BenjaminBrienen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only nits

//!
//! 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
Copy link
Contributor

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.

//! 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.
Copy link
Contributor

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)

Copy link
Contributor Author

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.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge labels Oct 13, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 15, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 15, 2024
@alice-i-cecile
Copy link
Member

@shanecelis this needs minor changes following #15887.

@shanecelis
Copy link
Contributor Author

Will do.

Some refactoring from feedback too.
@shanecelis
Copy link
Contributor Author

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.

@MiniaczQ
Copy link
Contributor

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 TextUiWriter after #15887

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 15, 2024
Merged via the queue into bevyengine:main with commit 5157fef Oct 15, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Examples An addition or correction to our examples D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add drag move example
5 participants