8000 Make the background in `SidePanel` fill the available space by birktj · Pull Request #1263 · emilk/egui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make the background in SidePanel fill the available space #1263

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions egui/src/containers/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,19 @@ impl SidePanel {
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.set_min_height(ui.max_rect().height()); // Make sure the frame fills the full height
ui.set_min_width(*width_range.start());
add_contents(ui)
let res = add_contents(ui);

// This is a hack to force the `Frame` to expand its background to fill the available
// space.
let mut rect = ui.min_rect();
rect.min -= Vec2::new(frame.margin.left, frame.margin.top);
rect.max += Vec2::new(frame.margin.right, frame.margin.bottom);
ui.allocate_space(ui.available_size());
Copy link
Owner

Choose a reason for hiding this comment

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

How does this work for left panels? Don't they just take up the entire width of the screen?

Copy link
Author

Choose a reason for hiding this comment

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

Good question. It seems to work fine and I think this is because the panel_ui given to the SidePanel has a its max_width set to the width of the panel, which initially is default_width and then ui.min_rect().width() for subsequent frames. I am not too familiar with the inner workings of the layout engine, but it seems to be this rect only grows if contents overflow somehow?

See Side::set_rect_width, the definition of panel_rect and panel_ui.


(rect, res)
});

let rect = inner_response.response.rect;
let rect = inner_response.inner.0;

{
let mut cursor = ui.cursor();
Expand Down Expand Up @@ -278,7 +287,10 @@ impl SidePanel {
.line_segment([top, bottom], stroke);
}

inner_response
InnerResponse {
inner: inner_response.inner.1,
response: inner_response.response,
}
}

/// Show the panel at the top level.
Expand Down
0