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

SidePanel frame leaks into BottomPanel #4475

Open
abey79 opened this issue May 7, 2024 · 3 comments
Open

SidePanel frame leaks into BottomPanel #4475

abey79 opened this issue May 7, 2024 · 3 comments
Labels
bug Something is broken egui rerun Desired for Rerun.io

Comments

@abey79
Copy link
Collaborator

abey79 commented May 7, 2024

Consider this code:

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
#![allow(rustdoc::missing_crate_level_docs)] // it's an example

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
    env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
        ..Default::default()
    };
    eframe::run_native("My egui App", options, Box::new(|cc| Box::new(MyApp)))
}

struct MyApp;

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            egui::TopBottomPanel::bottom("bottom")
                .resizable(true)
                .show_animated_inside(ui, true, |ui| {
                    egui::ScrollArea::vertical().show(ui, |ui| {
                        for _ in 0..20 {
                            ui.label("bottom panel");
                        }
                    })
                });

            // fix attempt (1) — doesn't work
            //ui.set_clip_rect(ui.max_rect());

            egui::SidePanel::left("left panel")
                .resizable(true)
                .frame(egui::Frame {
                    fill: egui::Color32::RED,
                    ..Default::default()
                })
                .show_animated_inside(ui, true, |ui| {
                    // fix attempt (2) - only clips content, not the fill
                    //ui.set_clip_rect(ui.max_rect());

                    for _ in 0..20 {
                        ui.label("left panel");
                    }
                });
        });
    }
}

The left panel badly bleed into the bottom panel:

image

Fix attempt (1) consist of setting a clip rect before the panel code, and doesn't appear to make any change.

Fix attempt (2) does clip the left panel's content correctly, but not it's fill:

image

This is the root cause of rerun-io/rerun#6227

@abey79 abey79 added bug Something is broken egui rerun Desired for Rerun.io labels May 7, 2024
@abey79 abey79 changed the title SidePanel frame leaks into `BottomPanel SidePanel frame leaks into BottomPanel May 7, 2024
@abey79
Copy link
Collaborator Author

abey79 commented May 7, 2024

Possible work around: disable all drawing by the SidePanel and emulate it from the closure:

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            egui::TopBottomPanel::bottom("bottom")
                .resizable(true)
                .show_animated_inside(ui, true, |ui| {
                    egui::ScrollArea::vertical().show(ui, |ui| {
                        for _ in 0..20 {
                            ui.label("bottom panel");
                        }
                    })
                });

            egui::SidePanel::left("left panel")
                .resizable(true)
                .frame(egui::Frame::default())
                .show_separator_line(false)
                .show_animated_inside(ui, true, |ui| {
                    ui.painter()
                        .rect_filled(ui.max_rect(), 0.0, egui::Color32::RED);
                    ui.painter().vline(
                        ui.max_rect().right(),
                        ui.max_rect().y_range(),
                        ui.style().visuals.widgets.noninteractive.bg_stroke,
                    );
                    ui.set_clip_rect(ui.max_rect());

                    for _ in 0..20 {
                        ui.label("left panel");
                    }
                });
        });
    }
}
image

Note:

  • for a better effect, the outer CentralPanel must have zero inner margin
  • this work around is imperfect: the on-hover separator line still overlaps the bottom panel

@abey79
Copy link
Collaborator Author

abey79 commented May 7, 2024

An obvious workaround is to wrap the entire content of the SidePanel in a ScrollArea. However, this is not convenient in every case, for example when the panel content is already made of multiple, independent scroll areas (e.g. rerun's left panel).

abey79 added a commit to rerun-io/rerun that referenced this issue May 8, 2024
### What

- Fixes #6227

A workaround for emilk/egui#4475 was needed
that will need to be cleaned:
- #6256

**NOTE**: chained to #6248 to minimise conflicts.

Note that this doesn't _entirely_ fix the visual glitch, but makes it
much less visible. Now the time panel must be disproportionately be
stretched _and_ one must hover the separator:

<img width="445" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/d66ccccb-2a22-4d00-bb8e-7c020c806928">


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6255?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6255?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6255)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
@s-nie
Copy link
Contributor

s-nie commented May 14, 2024

May be related to #4349

@abey79 abey79 added this to the Next Major Release milestone May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken egui rerun Desired for Rerun.io
Projects
None yet
Development

No branches or pull requests

2 participants