Skip to content

Commit

Permalink
Fixed scrollbar in floating element example
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Jul 21, 2023
1 parent d638ddf commit 414a213
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
6 changes: 3 additions & 3 deletions examples/floating_element/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Application for FloatingElementExample {
match self {

Check failure on line 59 in examples/floating_element/src/main.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced_aw/iced_aw/examples/floating_element/src/main.rs
FloatingElementExample::Loading => {
if let Message::Loaded(_) = message {
*self = FloatingElementExample::Loaded(State { lines: Vec::new() })
*self = FloatingElementExample::Loaded(State { lines: (0..3000).into_iter().map(|_| "This is a newly added line.".into()).collect() })

Check failure on line 62 in examples/floating_element/src/main.rs

View workflow job for this annotation

GitHub Actions / all

useless conversion to the same type: `std::ops::Range<i32>`
}
}
FloatingElementExample::Loaded(State { lines }) => {
Expand Down Expand Up @@ -88,11 +88,11 @@ impl Application for FloatingElementExample {
let scrollable_content = lines.iter().enumerate().fold(
Column::new()
.width(Length::Fill)
.height(Length::Fill)
.height(Length::Shrink)
.padding(10),
|scroll, (i, line)| scroll.push(Text::new(format!("{}. {}", i + 1, line))),
);
let scrollable_content = Scrollable::new(scrollable_content);
let scrollable_content = Scrollable::new(scrollable_content).height(Length::Fill);

let content = floating_element(
Container::new(scrollable_content)
Expand Down
1 change: 0 additions & 1 deletion src/native/floating_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ where
&mut self.element,
&self.anchor,
&self.offset,
layout.bounds().size(),
)),
))
} else {
Expand Down
12 changes: 4 additions & 8 deletions src/native/overlay/floating_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iced_widget::core::{
mouse::{self, Cursor},
overlay, renderer,
widget::Tree,
Clipboard, Element, Event, Layout, Length, Point, Rectangle, Shell, Size, Vector,
Clipboard, Element, Event, Layout, Point, Rectangle, Shell, Size,
};

use crate::native::floating_element::{Anchor, Offset};
Expand All @@ -24,8 +24,6 @@ pub struct FloatingElementOverlay<'a, 'b, Message, Renderer: core::Renderer> {
anchor: &'b Anchor,
/// The offset of the element.
offset: &'b Offset,
/// Size of the layout,
size: Size,
}

impl<'a, 'b, Message, Renderer> FloatingElementOverlay<'a, 'b, Message, Renderer>
Expand All @@ -39,14 +37,12 @@ where
element: &'b mut Element<'a, Message, Renderer>,
anchor: &'b Anchor,
offset: &'b Offset,
size: Size,
) -> Self {
FloatingElementOverlay {
state,
element,
anchor,
offset,
size,
}
}
}
Expand All @@ -58,7 +54,7 @@ where
{
fn layout(&self, renderer: &Renderer, bounds: Size, position: Point) -> layout::Node {
let limits = layout::Limits::new(Size::ZERO, bounds);
let mut element = self.element.as_widget().layout(renderer, &limits);
let element = self.element.as_widget().layout(renderer, &limits);

let size = match self.anchor {
Anchor::NorthWest | Anchor::North => Size::new(
Expand All @@ -82,11 +78,11 @@ where
),
Anchor::East => Size::new(
position.x - self.offset.x,
position.y,
position.y + element.bounds().height / 2.0,
),
Anchor::West => Size::new(
position.x + self.offset.x + element.bounds().width,
position.y,
position.y + element.bounds().height / 2.0,
),
};

Expand Down

0 comments on commit 414a213

Please sign in to comment.