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

Resizing a window allows it to be dragged outside of the screen. #202

Open
aakamenov opened this issue Mar 2, 2021 · 3 comments
Open

Resizing a window allows it to be dragged outside of the screen. #202

aakamenov opened this issue Mar 2, 2021 · 3 comments
Labels
bug Something is broken

Comments

@aakamenov
Copy link
Contributor

Hello,

Resizing a Window can cause the window to go outside of the boundaries of the screen and allows the window to be extended over the side or top panels, where it normally cannot be dragged. This can be reproduced more easily on a smaller screen space on desktop.

resize_bug

@aakamenov aakamenov added the bug Something is broken label Mar 2, 2021
@DrOptix
Copy link
Contributor

DrOptix commented Mar 21, 2021

I wanted to fix this, but I think this is by design. Looking at the following snippet:

egui/egui/src/context.rs

Lines 487 to 516 in f5c3729

/// Constrain the position of a window/area
/// so it fits within the provided boundary.
pub(crate) fn constrain_window_rect_to_area(&self, window: Rect, mut area: Rect) -> Rect {
if window.width() > area.width() {
// Allow overlapping side bars.
// This is important for small screens, e.g. mobiles running the web demo.
area.max.x = self.input().screen_rect().max.x;
area.min.x = self.input().screen_rect().min.x;
}
if window.height() > area.height() {
// Allow overlapping top/bottom bars:
area.max.y = self.input().screen_rect().max.y;
area.min.y = self.input().screen_rect().min.y;
}
let mut pos = window.min;
// Constrain to screen, unless window is too large to fit:
let margin_x = (window.width() - area.width()).at_least(0.0);
let margin_y = (window.height() - area.height()).at_least(0.0);
pos.x = pos.x.at_most(area.right() + margin_x - window.width()); // move left if needed
pos.x = pos.x.at_least(area.left() - margin_x); // move right if needed
pos.y = pos.y.at_most(area.bottom() + margin_y - window.height()); // move right if needed
pos.y = pos.y.at_least(area.top() - margin_y); // move down if needed
pos = self.round_pos_to_pixels(pos);
Rect::from_min_size(pos, window.size())
}

Now the discussion is, should we limit it to the screen size or should we keep as designed?

One idea I have is to make it configurable. If a overlap_panels flag is set then overlap the panels, if not go under them.

I thought this a good first issue for me so I'll try to add that flag. If I succeed I will send a PR.

@aakamenov
Copy link
Contributor Author

I had actually tried playing around with this method as to simply constrain the window bounds within the area but could still drag it outside of the screen, so I suspected that something else might be going on here. However, I could've totally missed something!

Before adding anything like this though, its probably better getting @emilk 's input on the matter.

@emilk
Copy link
Owner

emilk commented Mar 23, 2021

👋

To understand the motivation of the current behavior: resize the egui frame window to the size of a phone screen (or open the web demo on a mobile phone). Some windows are too wide to fit the screen, and all need to be able to cover the side bar to fit. When the screen is wide enough, however, I think it makes sense to only allow the windows on the central panel area. I agree this is a bit confusing. An option to toggle the behavior would not solve the core problem. I think the best solution (from a UI perspective) is to have a collapsible side bar so that for phone screens the side bar becomes a hamburger-menu or similar. That way the "allow windows to overlap sidebar" feature wouldn't be needed.

Some of the other confusing behavior in the gif comes from making the widget windows very large. In many cases it may make sense to have a maximum width, or restricting the resizing mouse cursor to the inside of the screen.

There is also the separate issue of moving a window by dragging the top edge of it: this is more of a bug, or an artifact of how resizing is done. It is a bit hard to handle it well in immediate mode without frame delay.

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

No branches or pull requests

3 participants