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

Add clip rect in panels and use them for large collapsing headers #2936

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions crates/re_ui/examples/re_ui_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ impl eframe::App for ExampleApp {
..Default::default()
})
.show_animated(egui_ctx, self.left_panel, |ui| {
// no need to extend `ui.max_rect()` as the enclosing frame doesn't have margins
ui.set_clip_rect(ui.max_rect());

egui::TopBottomPanel::top("left_panel_tio_bar")
.exact_height(re_ui::ReUi::title_bar_height())
.frame(egui::Frame {
Expand Down Expand Up @@ -225,8 +228,20 @@ impl eframe::App for ExampleApp {
egui::SidePanel::right("right_panel")
.frame(panel_frame)
.show_animated(egui_ctx, self.right_panel, |ui| {
// TODO(ab): use the proper `egui::Rect` function when egui 0.23 is released
let clip_rect = egui::Rect::from_min_max(
ui.max_rect().min - panel_frame.inner_margin.left_top(),
ui.max_rect().max + panel_frame.inner_margin.right_bottom(),
);
ui.set_clip_rect(clip_rect);

ui.strong("Right panel");
selection_buttons(ui);
self.re_ui
.large_collapsing_header(ui, "Large Collapsing Header", true, |ui| {
ui.label("Some data here");
ui.label("Some data there");
});
});

egui::CentralPanel::default()
Expand Down
8 changes: 7 additions & 1 deletion crates/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ impl ReUi {
response
}

/// Show a prominent collapsing header to be used as section delimitation in side panels.
///
/// Note that a clip rect must be set (typically by the panel) to avoid any overdraw.
#[allow(clippy::unused_self)]
pub fn large_collapsing_header<R>(
&self,
Expand Down Expand Up @@ -507,7 +510,10 @@ impl ReUi {
.galley_with_color(text_pos, galley, visuals.text_color());

// Let the rect cover the full panel width:
let bg_rect = rect.expand2(egui::vec2(1000.0, 0.0));
let mut bg_rect = rect;
bg_rect.extend_with_x(ui.clip_rect().right());
bg_rect.extend_with_x(ui.clip_rect().left());

ui.painter().set(
background_frame,
Shape::rect_filled(bg_rect, 0.0, visuals.bg_fill),
Expand Down
5 changes: 5 additions & 0 deletions crates/re_viewer/src/ui/blueprint_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub fn blueprint_panel_ui(
.default_width((0.35 * screen_width).min(200.0).round());

panel.show_animated_inside(ui, expanded, |ui: &mut egui::Ui| {
// Set the clip rectangle to the panel for the benefit of nested, "full span" widgets like
// large collapsing headers. Here, no need to extend `ui.max_rect()` as the enclosing frame
// doesn't have inner margins.
ui.set_clip_rect(ui.max_rect());

title_bar_ui(blueprint, ctx, ui, spaces_info);

egui::Frame {
Expand Down
5 changes: 5 additions & 0 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ impl SelectionPanel {
});

panel.show_animated_inside(ui, expanded, |ui: &mut egui::Ui| {
// Set the clip rectangle to the panel for the benefit of nested, "full span" widgets
// like large collapsing headers. Here, no need to extend `ui.max_rect()` as the
// enclosing frame doesn't have inner margins.
ui.set_clip_rect(ui.max_rect());

egui::TopBottomPanel::top("selection_panel_title_bar")
.exact_height(re_ui::ReUi::title_bar_height())
.frame(egui::Frame {
Expand Down