-
Notifications
You must be signed in to change notification settings - Fork 1.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
How to add the resize handle button to the main window? #2548
Comments
There isn't a component for it, and all of the types used to draw and check for interactions are private. You can reimplement the basics by copying code or ideas. This is the "entry-point" for the resize handle on windows: egui/crates/egui/src/containers/window.rs Lines 584 to 624 in 34f587d
FWIW, I would probably label this a feature (make resize-handle a public widget) instead of a bug. |
I was mostly just asking a question so it didn't made sense to use the feature template as I didn't know this is a internal only widget and the bug label automatically applies to all issues created using bug template. But yea I will re-post this using feature template. Thanks! |
For any one else looking for a quick and dirty way to do this // offset from bottom right of window to trigger resize handle
let resize_area_size = 16.0;
// position of bottom right of window
let bottom_right = ui.max_rect().right_bottom();
// Easier to use a vector for the following math
let offset_vec = vec2(resize_area_size, resize_area_size);
// rect giving a square area at the bottom right of the window where the resize can be triggered
let bottom_right_resize_rect = bottom_right - offset_vec;
// set up the interaction so that the cursor changes and we can sense click/drag
let bottom_right_drag = ui.interact(bottom_right_resize_rect, "bottom-right-resize".into(), Sense::click_and_drag())
.on_hover_cursor(egui::CursorIcon::ResizeNwSe);
// if the rect gets dragged, just resize the window according to the current cursor position
if bottom_right_drag.dragged() {
let current_pos = bottom_right_drag.interact_pointer_pos();
if let Some(pos) = current_pos {
// + `offset_vec` so that the interaction never falls outside of the window area
ui.ctx().send_viewport_cmd(egui::ViewportCommand::InnerSize(pos.to_vec2() + offset_vec));
}
}
// Follow this basic idea for all the other corners you want the interaction for ... Only issue I ran into is that without the If anyone has thoughts on how to improve on this maybe it can be added to the demo code. edit: you probably also want to add some logic to ensure that you maintain some minimum size. It's 100% possible to make the window too small to interact with. Something like: let effective_size = pos.to_vec2() + offset_vec;
ui.ctx().send_viewport_cmd(egui::ViewportComand::InnerSize(effective_size.max(640., 480.).into())); Other considerations: if you're in fullscreen you probably want to disable this (though it does seem to work anyways). |
Another thing to look into, there's also if bottom_right_drag.dragged() {
ui.ctx().send_viewport_cmd(egui::ViewportCommand::BeginResize(egui::ResizeDirection::SouthEast));
} It seems to resolve all the issues relating to the interaction position falling outside the window. |
We have a problem with app window resize as we as with dragging, egui is not receiving event on mouse button release. |
How do I add this resize button or handle to the main window?
as a window with no decorations or custom decorations doesn't seems to be resizable unless there is a shortcut like Super + Right click and drag.
The text was updated successfully, but these errors were encountered: