1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Refactor scroll area fade painting logic (#8214)

Reserve the scroll area before painting fades and update the fade
painting logic.

* Closes #8213
This commit is contained in:
rustbasic
2026-06-02 23:32:40 +09:00
committed by GitHub
parent 654a2a974d
commit db7559368d

View File

@@ -1042,17 +1042,13 @@ impl ScrollArea {
.inner;
let (content_size, state) = prepared.end(ui);
let output = ScrollAreaOutput {
ScrollAreaOutput {
inner,
id,
state,
content_size,
inner_rect,
};
paint_fade_areas(ui, &output);
output
}
}
}
@@ -1260,6 +1256,11 @@ impl Prepared {
let scroll_style = ui.spacing().scroll;
// Reserve the scroll area before painting fades, because fade painting uses ui.min_rect().
ui.advance_cursor_after_rect(outer_rect);
paint_fade_areas_impl(ui, inner_rect, content_size, state.offset);
// Paint the bars:
let scroll_bar_rect = scroll_bar_rect.unwrap_or(inner_rect);
for d in 0..2 {
@@ -1508,8 +1509,6 @@ impl Prepared {
}
}
ui.advance_cursor_after_rect(outer_rect);
if show_scroll_this_frame != state.show_scroll {
ui.request_repaint();
}
@@ -1551,7 +1550,7 @@ impl Prepared {
/// Paint fade-out gradients at the top and/or bottom of a scroll area to
/// indicate that more content is available beyond the visible region.
fn paint_fade_areas<R>(ui: &Ui, scroll_output: &ScrollAreaOutput<R>) {
fn paint_fade_areas_impl(ui: &Ui, inner_rect: Rect, content_size: Vec2, offset: Vec2) {
let crate::style::ScrollFadeStyle {
strength,
size: fade_size,
@@ -1563,11 +1562,9 @@ fn paint_fade_areas<R>(ui: &Ui, scroll_output: &ScrollAreaOutput<R>) {
let bg = ui.stack().bg_color();
let offset = scroll_output.state.offset;
let overflow = scroll_output.content_size - scroll_output.inner_rect.size();
let overflow = content_size - inner_rect.size();
let paint_rect = scroll_output
.inner_rect
let paint_rect = inner_rect
.intersect(ui.min_rect())
.expand(ui.visuals().clip_rect_margin);