Skip to content

fix: avoid CentralPanel overflowing in a window #7042

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

avalsch
Copy link
Contributor

@avalsch avalsch commented May 9, 2025

use eframe::egui;

fn main() -> eframe::Result<()> {
    eframe::run_simple_native("window overflow", Default::default(), |ctx, _| {
        egui::Window::new("window overflow").show(ctx, |ui| {
            egui::CentralPanel::default().show_inside(ui, |ui| {
                ui.label("Hello, World");
            });
        });
    })
}

Old behavior:

image

New behavior:

image

I'd ideally add a test for this but I'm not sure how to go about doing that.

Copy link

github-actions bot commented May 9, 2025

Preview available at https://egui-pr-preview.github.io/pr/7042-window-panel-overflow
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

Copy link
Collaborator

@lucasmerlin lucasmerlin left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! To add tests, the easiest would be to add a new kittest test to tests/egui_tests, the test could just simply be a screenshot test with the repro you provided.

Comment on lines 1124 to 1131
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.expand_to_include_rect(ui.max_rect()); // Expand frame to include it all
add_contents(ui)
})
});

ui.expand_to_include_rect(inner_response.response.rect);

inner_response
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think instead of ui.new_child we could also do ui.scope_builder which should do the expand_to_include_rect for us. Might be a bit cleaner.

.layout(Layout::top_down(Align::Min)),
);
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to me like scope_builder doesn't preserve the same behavior with set_clip_rect. This might break some things, but I'm not sure?

@avalsch
Copy link
Contributor Author

avalsch commented May 18, 2025

Regarding using scope_builder rather than new_child, the other panel implementations (SidePanel, TopBottomPanel) also use new_child. Is this something we would want to change?

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.

CentralPanel overflows in a window unless there is a Top, Bottom or Right pannel
2 participants