-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
ScrollAreas can overrun their container's margins #3385
Comments
The reason I added it is because a lot of widgets draw their border outline at their margin, and so if the border is e.g. 2 points wide, half of the outline is outside the widget rect. This means that if you put such a widget first thing inside e.g. a I think there are a few ways to fix this mess:
|
Painting the borders inside the lines seems like the best solution to me as well. It seems like egui doesn't currently count borders as taking up any space. This would make them more similar to the CSS It seems like most of the current use cases for
|
Hm, it seems like a lot of widgets draw outside their rectangle. For example, the I tried removing On the other hand, if I just stop It seems like the right place for clipping to happen is Maybe instead of having one hardcoded |
I may tackle this when I start working on #3284 |
I'm thinking about this once again, and I think I've convinced myself that the real issue has been In the HTML/CSS world, you have one primitive: the box. It has a border, margin, and padding, and you can make it scrollable. In egui, if you want a scrollable container, you have to put a There's also resizability--as far as I can tell, the I think that it's better to conceptualize "scrollable" and "resizable" as attributes of a box/layout, rather than their own distinct widgets. From there, you would need to rework the container widgets' APIs with this in mind. I think the best way would be to create a struct that contains both the What are your thoughts on this API? I may try to implement it--I will probably fail, but I think it's worth exploring. |
Describe the bug
When displaying a ScrollArea inside a container, and it only scrolls along one axis, it will be a few pixels too big and will overflow into that container's margins along that axis.
This is easiest to see when we set the container's margins to 0. Here's an example with a ScrollArea containing the grey rectangle in the central panel, surrounded by 4 panels:
I haven't delved into the code much, but it seems like the scroll area overruns the container margin by
clip_rect_margin
pixels. Settingclip_rect_margin
to 0.0 before rendering the scroll area fixes the issue.To Reproduce
Steps to reproduce the behavior:
See the following demo code, which renders the UI shown above:
Demo code
```rust use eframe::egui;fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(480.0, 360.0)),
..Default::default()
};
eframe::run_native(
"My egui App",
options,
Box::new(|_cc| Box::::default()),
)
}
#[derive(Default)]
struct MyApp {}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
let no_margins = egui::Frame::side_top_panel(&ctx.style()).inner_margin(0.0);
egui::TopBottomPanel::top("top").show(ctx, || {});
egui::TopBottomPanel::bottom("bottom").show(ctx, || {});
egui::SidePanel::left("left").show(ctx, || {});
egui::SidePanel::right("right").show(ctx, |_| {});
egui::CentralPanel::default()
.frame(no_margins)
.show(ctx, |ui| {
egui::ScrollArea::new([true; 2]).show(ui, |ui| {
ui.add(
egui::Image::from_texture((
egui::TextureId::default(),
egui::vec2(360.0, 240.0),
))
.uv(egui::Rect::from_min_max(
egui::pos2(0.0, 0.0),
egui::pos2(0.0, 0.0),
))
.tint(egui::Color32::GRAY),
);
});
});
}
}
The text was updated successfully, but these errors were encountered: