Introduce an appearance for a scrollable, ability to customize the scrollbar gap.

Update scrollable.rs
This commit is contained in:
dtzxporter 2024-02-06 13:55:42 -05:00 committed by Héctor Ramón Jiménez
parent 891f29eea0
commit 0f920e0435
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 71 additions and 6 deletions

View file

@ -15,7 +15,9 @@ use crate::core::{
};
use crate::runtime::Command;
pub use crate::style::scrollable::{Scrollbar, Scroller, StyleSheet};
pub use crate::style::scrollable::{
Appearance, Scrollbar, Scroller, StyleSheet,
};
pub use operation::scrollable::{AbsoluteOffset, RelativeOffset};
/// A widget that can vertically display an infinite amount of content with a
@ -878,6 +880,19 @@ pub fn draw<Theme, Renderer>(
_ => mouse::Cursor::Unavailable,
};
// Draw background.
let appearence = theme.appearance(style);
if let Some(background) = appearence.background {
renderer.fill_quad(
renderer::Quad {
bounds,
..Default::default()
},
background,
);
}
// Draw inner content
if scrollbars.active() {
renderer.with_layer(bounds, |renderer| {
@ -971,6 +986,26 @@ pub fn draw<Theme, Renderer>(
draw_scrollbar(renderer, style, &scrollbar);
}
//draw filler quad
if let (Some(x), Some(y)) = (scrollbars.x, scrollbars.y) {
let background = appearence.gap.or(appearence.background);
if let Some(background) = background {
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: y.bounds.x,
y: x.bounds.y,
width: y.bounds.width,
height: x.bounds.height,
},
..renderer::Quad::default()
},
background,
);
}
}
},
);
} else {