mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Tweak ScrollArea fade effect (#8023)
* Follow-up to https://github.com/emilk/egui/pull/8018
This commit is contained in:
@@ -1513,11 +1513,11 @@ impl Prepared {
|
|||||||
/// indicate that more content is available beyond the visible region.
|
/// 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<R>(ui: &Ui, scroll_output: &ScrollAreaOutput<R>) {
|
||||||
let crate::style::ScrollFadeStyle {
|
let crate::style::ScrollFadeStyle {
|
||||||
enabled,
|
strength,
|
||||||
size: fade_size,
|
size: fade_size,
|
||||||
} = ui.spacing().scroll.fade;
|
} = ui.spacing().scroll.fade;
|
||||||
|
|
||||||
if !enabled {
|
if strength <= 0.0 {
|
||||||
return;
|
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.
|
// Top fade: animate opacity based on how far we've scrolled down.
|
||||||
if 0.0 < offset.y {
|
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 bg_faded = bg.gamma_multiply(t);
|
||||||
let rect = Rect::from_min_max(
|
let rect = Rect::from_min_max(
|
||||||
paint_rect.left_top(),
|
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.
|
// Bottom fade: animate opacity based on distance from the bottom.
|
||||||
let distance_from_bottom = overflow.y - offset.y;
|
let distance_from_bottom = overflow.y - offset.y;
|
||||||
if 0.0 < distance_from_bottom {
|
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 bg_faded = bg.gamma_multiply(t);
|
||||||
let rect = Rect::from_min_max(
|
let rect = Rect::from_min_max(
|
||||||
pos2(paint_rect.left(), paint_rect.bottom() - fade_size),
|
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.
|
// Left fade: animate opacity based on how far we've scrolled right.
|
||||||
|
|
||||||
if 0.0 < offset.x {
|
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 bg_faded = bg.gamma_multiply(t);
|
||||||
let rect = Rect::from_min_max(
|
let rect = Rect::from_min_max(
|
||||||
paint_rect.left_top(),
|
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.
|
// Right fade: animate opacity based on distance from the right edge.
|
||||||
let distance_from_right = overflow.x - offset.x;
|
let distance_from_right = overflow.x - offset.x;
|
||||||
if 0.0 < distance_from_right {
|
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 bg_faded = bg.gamma_multiply(t);
|
||||||
let rect = Rect::from_min_max(
|
let rect = Rect::from_min_max(
|
||||||
pos2(paint_rect.right() - fade_size, paint_rect.top()),
|
pos2(paint_rect.right() - fade_size, paint_rect.top()),
|
||||||
|
|||||||
@@ -790,8 +790,10 @@ impl ScrollStyle {
|
|||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[cfg_attr(feature = "serde", serde(default))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub struct ScrollFadeStyle {
|
pub struct ScrollFadeStyle {
|
||||||
/// Show fade areas?
|
/// Opacity of the fade effect at the outer edge, in 0.0-1.0.
|
||||||
pub enabled: bool,
|
///
|
||||||
|
/// Set to 0.0 to disable the fade effect.
|
||||||
|
pub strength: f32,
|
||||||
|
|
||||||
/// Size of the fade-area (height for vertical scrolling,
|
/// Size of the fade-area (height for vertical scrolling,
|
||||||
/// width for horizontal scrolling).
|
/// width for horizontal scrolling).
|
||||||
@@ -801,7 +803,7 @@ pub struct ScrollFadeStyle {
|
|||||||
impl Default for ScrollFadeStyle {
|
impl Default for ScrollFadeStyle {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
enabled: true,
|
strength: 0.5,
|
||||||
size: 20.0,
|
size: 20.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -809,13 +811,14 @@ impl Default for ScrollFadeStyle {
|
|||||||
|
|
||||||
impl ScrollFadeStyle {
|
impl ScrollFadeStyle {
|
||||||
pub fn ui(&mut self, ui: &mut Ui) {
|
pub fn ui(&mut self, ui: &mut Ui) {
|
||||||
let Self { enabled, size } = self;
|
let Self { strength, size } = self;
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
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.horizontal(|ui| {
|
||||||
ui.add(DragValue::new(size).range(0.0..=64.0));
|
ui.add(DragValue::new(size).range(0.0..=64.0));
|
||||||
ui.label("Fade size");
|
ui.label("Fade size");
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:65776e4d9e31e7163117166915a0cfaaece98b1dd69695533655dee889ac5597
|
oid sha256:84f0e72ce337d56f3767ebed1ab6a47f3d27c9fbcce4d8a19aeab358e12920f5
|
||||||
size 169277
|
size 169664
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:583003c59f40515a5de435ee1eea2ee6fceae409c7881456401b004c6409896a
|
oid sha256:deff441cd1d9142352f8759dff4b759f4572f0ddf93752349314da77abe4b254
|
||||||
size 114575
|
size 115028
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:8815473873602211a95e0a077dc77560de154a0a1a2f9c1418d90746670075f7
|
oid sha256:a46457b23b7b32694564d03b42bccac2f017a756225bc54b508bb6fe2ad8ee7b
|
||||||
size 248630
|
size 249548
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:2881255fa694b713a3c3049f30143ee60a20b68105fb724fbba188f81d34e572
|
oid sha256:927a497e8b6f9ce3b71dcb67086f477e19d327c163b2b8ad868af10009c2faf2
|
||||||
size 171778
|
size 172981
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:63fb9d15956efa69818cfd5398b4dfaa796dfbe1df3fb171b8ae413a6f641c9f
|
oid sha256:db4c0cf1c4cdae3d416afce5c58efd1cc382be86431e547fa66bcc95a0a17ddb
|
||||||
size 76049
|
size 76364
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:4ac837d03e3e8959196942d030a8511d00cdd0d5ac9bfe761d80b59d32e73581
|
oid sha256:57018beba5e4fb4f1e6de9c58bf898560b3a7669159d5bad91a4e2382ef57ce0
|
||||||
size 63967
|
size 64004
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:4107ba4569b3e37ce6720595cfc4de60aec11dcfdb835720442b244e121209fc
|
oid sha256:999f9cc006302b8951d97b510a02f1209969c376ecc7909ed5d7b46da27c0637
|
||||||
size 482862
|
size 483753
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:6f6d516cc3d1439256a19f72153468125bac1647e2e211e841579545570faef7
|
oid sha256:6154c8bb550575bcb9fa0bba06da4d47079a00dffc5754b62ef2a6e7529e2090
|
||||||
size 7366
|
size 7489
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:2e05d28e5541eb5926b4758e611f5c340311269fcd8b63055ff3a6793abbb140
|
oid sha256:df2578c198b29950254ec62c6cc615a4b1c003e7ae3ea027da22fc868b392c74
|
||||||
size 8279
|
size 8342
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:5dfd9b576e0ab4b47a0f8c8acfc2664f92faa88cc7fb088409bff359fa1dfadd
|
oid sha256:6f2a57ad8dbdd121cb181e74d76db68d800aba8fdc980d8de4e962e1e85fe8f6
|
||||||
size 1861
|
size 1803
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:4529530bb46af68260ca910a91f888e8b296790be2b976b450cec884799f53b4
|
oid sha256:43dc457cac18107772dbb7e5773961cf502dd685ce1cb4e94338e6b7daedaa77
|
||||||
size 1953
|
size 1861
|
||||||
|
|||||||
Reference in New Issue
Block a user