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

Fix default height of top/bottom panels #4779

Merged
merged 1 commit into from
Jul 4, 2024
Merged
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
8 changes: 5 additions & 3 deletions crates/egui/src/containers/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl TopBottomPanel {
}

/// The initial height of the [`TopBottomPanel`], including margins.
/// Defaults to [`style::Spacing::interact_size`].y.
/// Defaults to [`style::Spacing::interact_size`].y, plus frame margins.
#[inline]
pub fn default_height(mut self, default_height: f32) -> Self {
self.default_height = Some(default_height);
Expand Down Expand Up @@ -712,13 +712,16 @@ impl TopBottomPanel {
height_range,
} = self;

let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style()));

let available_rect = ui.available_rect_before_wrap();
let mut panel_rect = available_rect;

let mut height = if let Some(state) = PanelState::load(ui.ctx(), id) {
state.rect.height()
} else {
default_height.unwrap_or_else(|| ui.style().spacing.interact_size.y)
default_height
.unwrap_or_else(|| ui.style().spacing.interact_size.y + frame.inner_margin.sum().y)
};
{
height = clamp_to_range(height, height_range).at_most(available_rect.height());
Expand Down Expand Up @@ -759,7 +762,6 @@ impl TopBottomPanel {
panel_ui.expand_to_include_rect(panel_rect);
panel_ui.set_clip_rect(panel_rect); // If we overflow, don't do so visibly (#4475)

let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style()));
let inner_response = frame.show(&mut panel_ui, |ui| {
ui.set_min_width(ui.max_rect().width()); // Make the frame fill full width
ui.set_min_height((height_range.min - frame.inner_margin.sum().y).at_least(0.0));
Expand Down
Loading