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

Fade out the edges of ScrollAreas (#8018)

## Before:
<img width="381" height="307" alt="image"
src="https://github.com/user-attachments/assets/0528ae2a-44bf-4d9e-89a4-c3f4ab438eb2"
/>

It is very hard here to realize this is a scrollable area

## After
<img width="383" height="310" alt="image"
src="https://github.com/user-attachments/assets/9e0ee6de-8b96-4e5c-a505-f57977010990"
/>

The fade at the bottom tells the user they should try scrolling.

You can turn if off with `style.spacing.scroll.fade.enabled`
This commit is contained in:
Emil Ernerfeldt
2026-03-25 12:53:00 +01:00
committed by GitHub
parent 845b8c2f09
commit 0b0c561a81
22 changed files with 241 additions and 72 deletions

View File

@@ -5,7 +5,7 @@ use std::sync::Arc;
use emath::{Align2, Pos2, Rangef, Rect, TSTransform, Vec2, pos2};
use crate::{
Color32, CornerRadius, Mesh, Stroke, StrokeKind, TextureId,
Color32, CornerRadius, Direction, Mesh, Stroke, StrokeKind, TextureId, Vertex,
stroke::PathStroke,
text::{FontId, FontsView, Galley},
};
@@ -297,6 +297,32 @@ impl Shape {
Self::Rect(RectShape::stroke(rect, corner_radius, stroke, stroke_kind))
}
/// Paints a gradient rectangle that transitions from `color_from` to `color_to`
/// along the given `direction`.
///
/// For example, [`Direction::TopDown`] paints `color_from` at the top edge fading
/// to `color_to` at the bottom edge.
#[inline]
pub fn gradient_rect(rect: Rect, direction: Direction, [from, to]: [Color32; 2]) -> Self {
let (left_top, right_top, left_bottom, right_bottom) = match direction {
Direction::TopDown => (from, from, to, to),
Direction::BottomUp => (to, to, from, from),
Direction::LeftToRight => (from, to, from, to),
Direction::RightToLeft => (to, from, to, from),
};
Self::from(Mesh {
indices: vec![0, 1, 2, 2, 1, 3],
vertices: vec![
Vertex::untextured(rect.left_top(), left_top),
Vertex::untextured(rect.right_top(), right_top),
Vertex::untextured(rect.left_bottom(), left_bottom),
Vertex::untextured(rect.right_bottom(), right_bottom),
],
texture_id: Default::default(),
})
}
#[expect(clippy::needless_pass_by_value)]
pub fn text(
fonts: &mut FontsView<'_>,