Fix `Scrollable` scrollbar being rendered behind contents
... by issuing a new clip layer just for the scrollbar itself.
This commit is contained in:
parent
4b8ba8309f
commit
59c2500c55
|
@ -6,4 +6,4 @@ edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { path = "../.." }
|
iced = { path = "../..", features = ["debug"] }
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
mod style;
|
mod style;
|
||||||
|
|
||||||
use iced::{
|
use iced::{
|
||||||
scrollable, Column, Container, Element, Length, Radio, Row, Rule, Sandbox,
|
button, scrollable, Button, Column, Container, Element, Length, Radio, Row,
|
||||||
Scrollable, Settings, Space, Text,
|
Rule, Sandbox, Scrollable, Settings, Space, Text,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
|
@ -63,12 +63,14 @@ impl Sandbox for ScrollableDemo {
|
||||||
variants
|
variants
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.map(|variant| {
|
.map(|variant| {
|
||||||
let mut scrollable = Scrollable::new(&mut variant.state)
|
let mut scrollable =
|
||||||
.padding(10)
|
Scrollable::new(&mut variant.scrollable)
|
||||||
.width(Length::Fill)
|
.padding(10)
|
||||||
.height(Length::Fill)
|
.spacing(10)
|
||||||
.style(*theme)
|
.width(Length::Fill)
|
||||||
.push(Text::new(variant.title));
|
.height(Length::Fill)
|
||||||
|
.style(*theme)
|
||||||
|
.push(Text::new(variant.title));
|
||||||
|
|
||||||
if let Some(scrollbar_width) = variant.scrollbar_width {
|
if let Some(scrollbar_width) = variant.scrollbar_width {
|
||||||
scrollable = scrollable
|
scrollable = scrollable
|
||||||
|
@ -108,6 +110,14 @@ impl Sandbox for ScrollableDemo {
|
||||||
.push(Space::with_height(Length::Units(1200)))
|
.push(Space::with_height(Length::Units(1200)))
|
||||||
.push(Text::new("Middle"))
|
.push(Text::new("Middle"))
|
||||||
.push(Space::with_height(Length::Units(1200)))
|
.push(Space::with_height(Length::Units(1200)))
|
||||||
|
.push(
|
||||||
|
Button::new(
|
||||||
|
&mut variant.button,
|
||||||
|
Text::new("I am a button"),
|
||||||
|
)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.padding(10),
|
||||||
|
)
|
||||||
.push(Text::new("The End."));
|
.push(Text::new("The End."));
|
||||||
|
|
||||||
Container::new(scrollable)
|
Container::new(scrollable)
|
||||||
|
@ -142,7 +152,8 @@ impl Sandbox for ScrollableDemo {
|
||||||
/// A version of a scrollable
|
/// A version of a scrollable
|
||||||
struct Variant {
|
struct Variant {
|
||||||
title: &'static str,
|
title: &'static str,
|
||||||
state: scrollable::State,
|
scrollable: scrollable::State,
|
||||||
|
button: button::State,
|
||||||
scrollbar_width: Option<u16>,
|
scrollbar_width: Option<u16>,
|
||||||
scrollbar_margin: Option<u16>,
|
scrollbar_margin: Option<u16>,
|
||||||
scroller_width: Option<u16>,
|
scroller_width: Option<u16>,
|
||||||
|
@ -153,28 +164,32 @@ impl Variant {
|
||||||
vec![
|
vec![
|
||||||
Self {
|
Self {
|
||||||
title: "Default Scrollbar",
|
title: "Default Scrollbar",
|
||||||
state: scrollable::State::new(),
|
scrollable: scrollable::State::new(),
|
||||||
|
button: button::State::new(),
|
||||||
scrollbar_width: None,
|
scrollbar_width: None,
|
||||||
scrollbar_margin: None,
|
scrollbar_margin: None,
|
||||||
scroller_width: None,
|
scroller_width: None,
|
||||||
},
|
},
|
||||||
Self {
|
Self {
|
||||||
title: "Slimmed & Margin",
|
title: "Slimmed & Margin",
|
||||||
state: scrollable::State::new(),
|
scrollable: scrollable::State::new(),
|
||||||
|
button: button::State::new(),
|
||||||
scrollbar_width: Some(4),
|
scrollbar_width: Some(4),
|
||||||
scrollbar_margin: Some(3),
|
scrollbar_margin: Some(3),
|
||||||
scroller_width: Some(4),
|
scroller_width: Some(4),
|
||||||
},
|
},
|
||||||
Self {
|
Self {
|
||||||
title: "Wide Scroller",
|
title: "Wide Scroller",
|
||||||
state: scrollable::State::new(),
|
scrollable: scrollable::State::new(),
|
||||||
|
button: button::State::new(),
|
||||||
scrollbar_width: Some(4),
|
scrollbar_width: Some(4),
|
||||||
scrollbar_margin: None,
|
scrollbar_margin: None,
|
||||||
scroller_width: Some(10),
|
scroller_width: Some(10),
|
||||||
},
|
},
|
||||||
Self {
|
Self {
|
||||||
title: "Narrow Scroller",
|
title: "Narrow Scroller",
|
||||||
state: scrollable::State::new(),
|
scrollable: scrollable::State::new(),
|
||||||
|
button: button::State::new(),
|
||||||
scrollbar_width: Some(10),
|
scrollbar_width: Some(10),
|
||||||
scrollbar_margin: None,
|
scrollbar_margin: None,
|
||||||
scroller_width: Some(4),
|
scroller_width: Some(4),
|
||||||
|
|
|
@ -134,8 +134,16 @@ where
|
||||||
Primitive::None
|
Primitive::None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let scroll = Primitive::Clip {
|
||||||
|
bounds,
|
||||||
|
offset: Vector::new(0, 0),
|
||||||
|
content: Box::new(Primitive::Group {
|
||||||
|
primitives: vec![scrollbar, scroller],
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
Primitive::Group {
|
Primitive::Group {
|
||||||
primitives: vec![clip, scrollbar, scroller],
|
primitives: vec![clip, scroll],
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
content
|
content
|
||||||
|
|
Loading…
Reference in New Issue