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

Implement toggle for egui::Window to only accept move events from the title bar. #2775

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

NotAPenguin0
Copy link

@NotAPenguin0 NotAPenguin0 commented Mar 2, 2023

Closes #2774. For a more detailed description of the problem, refer to that issue.

demo gif.

List of changes

  • Added egui::Window::movable_from_contents() to toggle the new behaviour on.
  • In window::window_interaction(), split resize and move behaviour, since they might now use two different rects.

My apologies that there are so many commits, it's the unfortunate result of some dependencies I have to manage while developing. Just squashing on merge should get rid of the problem.

@NotAPenguin0 NotAPenguin0 marked this pull request as ready for review March 2, 2023 20:39
Comment on lines +96 to +97
/// Only allow moving by dragging from the title bar.
pub fn movable_from_contents(mut self, movable: bool) -> Self {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
/// Only allow moving by dragging from the title bar.
pub fn movable_from_contents(mut self, movable: bool) -> Self {
/// Allow moving the window by dragging its content?
///
/// Default: `true`.
/// Regardless of this value, dragging the title-bar will move the window (if moveable).
pub fn movable_from_contents(mut self, movable: bool) -> Self {

@@ -91,6 +93,12 @@ impl<'open> Window<'open> {
self
}

/// Only allow moving by dragging from the title bar.
pub fn movable_from_contents(mut self, movable: bool) -> Self {
self.move_title_bar_only = !movable;
Copy link
Owner

Choose a reason for hiding this comment

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

avoid negation in names

Suggested change
self.move_title_bar_only = !movable;
self.movable_from_contents = movable;

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

This seems like a lot of new code and complexity for a small change.

We should be able to just pipe in a smaller rect into move_and_resize_window?

@NotAPenguin0
Copy link
Author

NotAPenguin0 commented Apr 19, 2023

That is what I did initially, the problem is that this also moves the resize handle to a very weird and awkward position. I've also been able to implement this exact behaviour without touching egui internals at all, by simply doing

let remaining_size = ui.available_size();
let (response, painter) = ui.allocate_painter(remaining_size, Sense::drag());

and handling the drag value from this Response myself, so I don't think this change is needed anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow setting window to only support dragging from title bar
2 participants