1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Tweak ScrollArea fade effect (#8023)

* Follow-up to https://github.com/emilk/egui/pull/8018
This commit is contained in:
Emil Ernerfeldt
2026-03-25 15:44:41 +01:00
committed by GitHub
parent 02ff040b74
commit 048f8ccd2a
13 changed files with 37 additions and 35 deletions

View File

@@ -1513,11 +1513,11 @@ impl Prepared {
/// indicate that more content is available beyond the visible region.
fn paint_fade_areas<R>(ui: &Ui, scroll_output: &ScrollAreaOutput<R>) {
let crate::style::ScrollFadeStyle {
enabled,
strength,
size: fade_size,
} = ui.spacing().scroll.fade;
if !enabled {
if strength <= 0.0 {
return;
}
@@ -1533,7 +1533,7 @@ fn paint_fade_areas<R>(ui: &Ui, scroll_output: &ScrollAreaOutput<R>) {
// Top fade: animate opacity based on how far we've scrolled down.
if 0.0 < offset.y {
let t = (offset.y / fade_size).clamp(0.0, 1.0);
let t = (offset.y / fade_size).clamp(0.0, 1.0) * strength;
let bg_faded = bg.gamma_multiply(t);
let rect = Rect::from_min_max(
paint_rect.left_top(),
@@ -1549,7 +1549,7 @@ fn paint_fade_areas<R>(ui: &Ui, scroll_output: &ScrollAreaOutput<R>) {
// Bottom fade: animate opacity based on distance from the bottom.
let distance_from_bottom = overflow.y - offset.y;
if 0.0 < distance_from_bottom {
let t = (distance_from_bottom / fade_size).clamp(0.0, 1.0);
let t = (distance_from_bottom / fade_size).clamp(0.0, 1.0) * strength;
let bg_faded = bg.gamma_multiply(t);
let rect = Rect::from_min_max(
pos2(paint_rect.left(), paint_rect.bottom() - fade_size),
@@ -1563,9 +1563,8 @@ fn paint_fade_areas<R>(ui: &Ui, scroll_output: &ScrollAreaOutput<R>) {
}
// Left fade: animate opacity based on how far we've scrolled right.
if 0.0 < offset.x {
let t = (offset.x / fade_size).clamp(0.0, 1.0);
let t = (offset.x / fade_size).clamp(0.0, 1.0) * strength;
let bg_faded = bg.gamma_multiply(t);
let rect = Rect::from_min_max(
paint_rect.left_top(),
@@ -1581,7 +1580,7 @@ fn paint_fade_areas<R>(ui: &Ui, scroll_output: &ScrollAreaOutput<R>) {
// Right fade: animate opacity based on distance from the right edge.
let distance_from_right = overflow.x - offset.x;
if 0.0 < distance_from_right {
let t = (distance_from_right / fade_size).clamp(0.0, 1.0);
let t = (distance_from_right / fade_size).clamp(0.0, 1.0) * strength;
let bg_faded = bg.gamma_multiply(t);
let rect = Rect::from_min_max(
pos2(paint_rect.right() - fade_size, paint_rect.top()),

View File

@@ -790,8 +790,10 @@ impl ScrollStyle {
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct ScrollFadeStyle {
/// Show fade areas?
pub enabled: bool,
/// Opacity of the fade effect at the outer edge, in 0.0-1.0.
///
/// Set to 0.0 to disable the fade effect.
pub strength: f32,
/// Size of the fade-area (height for vertical scrolling,
/// width for horizontal scrolling).
@@ -801,7 +803,7 @@ pub struct ScrollFadeStyle {
impl Default for ScrollFadeStyle {
fn default() -> Self {
Self {
enabled: true,
strength: 0.5,
size: 20.0,
}
}
@@ -809,13 +811,14 @@ impl Default for ScrollFadeStyle {
impl ScrollFadeStyle {
pub fn ui(&mut self, ui: &mut Ui) {
let Self { enabled, size } = self;
let Self { strength, size } = self;
ui.horizontal(|ui| {
ui.checkbox(enabled, "Fade edges");
ui.add(DragValue::new(strength).speed(0.01).range(0.0..=1.0));
ui.label("Fade strength");
});
if *enabled {
if 0.0 < *strength {
ui.horizontal(|ui| {
ui.add(DragValue::new(size).range(0.0..=64.0));
ui.label("Fade size");