summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/combo_box/src/main.rs14
-rw-r--r--native/src/widget/scrollable.rs18
2 files changed, 27 insertions, 5 deletions
diff --git a/examples/combo_box/src/main.rs b/examples/combo_box/src/main.rs
index 75a3f713..977dc196 100644
--- a/examples/combo_box/src/main.rs
+++ b/examples/combo_box/src/main.rs
@@ -1,6 +1,6 @@
use iced::{
- button, combo_box, Button, Column, ComboBox, Container, Element, Length,
- Sandbox, Settings, Text,
+ button, combo_box, scrollable, Align, Button, ComboBox, Container, Element,
+ Length, Sandbox, Scrollable, Settings, Space, Text,
};
pub fn main() {
@@ -9,6 +9,7 @@ pub fn main() {
#[derive(Default)]
struct Example {
+ scroll: scrollable::State,
button: button::State,
combo_box: combo_box::State,
selected_language: Language,
@@ -51,8 +52,11 @@ impl Sandbox for Example {
let button = Button::new(&mut self.button, Text::new("Press me!"))
.on_press(Message::ButtonPressed);
- let mut content = Column::new()
+ let mut content = Scrollable::new(&mut self.scroll)
+ .width(Length::Fill)
+ .align_items(Align::Center)
.spacing(10)
+ .push(Space::with_height(Length::Units(800)))
.push(Text::new("Which is your favorite language?"))
.push(combo_box);
@@ -60,7 +64,9 @@ impl Sandbox for Example {
content = content.push(Text::new("You are wrong!"));
}
- content = content.push(button);
+ content = content
+ .push(button)
+ .push(Space::with_height(Length::Units(800)));
Container::new(content)
.width(Length::Fill)
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs
index 25fd8982..92e5265a 100644
--- a/native/src/widget/scrollable.rs
+++ b/native/src/widget/scrollable.rs
@@ -1,7 +1,7 @@
//! Navigate an endless amount of content with a scrollbar.
use crate::{
column, layout, mouse, Align, Clipboard, Column, Element, Event, Hasher,
- Layout, Length, Point, Rectangle, Size, Widget,
+ Layout, Length, Overlay, Point, Rectangle, Size, Vector, Widget,
};
use std::{f32, hash::Hash, u32};
@@ -315,6 +315,22 @@ where
self.content.hash_layout(state)
}
+
+ fn overlay(
+ &mut self,
+ layout: Layout<'_>,
+ ) -> Option<Overlay<'a, Message, Renderer>> {
+ self.content
+ .overlay(layout.children().next().unwrap())
+ .map(|overlay| {
+ let bounds = layout.bounds();
+ let content_layout = layout.children().next().unwrap();
+ let content_bounds = content_layout.bounds();
+ let offset = self.state.offset(bounds, content_bounds);
+
+ overlay.translate(Vector::new(0.0, -(offset as f32)))
+ })
+ }
}
/// The local state of a [`Scrollable`].