summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer/widget/scrollable.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2019-11-24 11:34:30 +0100
committerLibravatar GitHub <noreply@github.com>2019-11-24 11:34:30 +0100
commit149fd2aa1fa86858c7c1dcec8fd844caa78cec94 (patch)
treea199cf8d2caaf6aa60e48e93d6dd0688969d43b0 /wgpu/src/renderer/widget/scrollable.rs
parent9712b319bb7a32848001b96bd84977430f14b623 (diff)
parent47196c9007d12d3b3e0036ffabe3bf6d14ff4523 (diff)
downloadiced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.tar.gz
iced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.tar.bz2
iced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.zip
Merge pull request #65 from hecrj/improvement/docs
Documentation
Diffstat (limited to 'wgpu/src/renderer/widget/scrollable.rs')
-rw-r--r--wgpu/src/renderer/widget/scrollable.rs42
1 files changed, 11 insertions, 31 deletions
diff --git a/wgpu/src/renderer/widget/scrollable.rs b/wgpu/src/renderer/widget/scrollable.rs
index dd6ebcc1..58dc3df9 100644
--- a/wgpu/src/renderer/widget/scrollable.rs
+++ b/wgpu/src/renderer/widget/scrollable.rs
@@ -1,7 +1,6 @@
use crate::{Primitive, Renderer};
use iced_native::{
- scrollable, Background, Layout, MouseCursor, Point, Rectangle, Scrollable,
- Vector, Widget,
+ scrollable, Background, MouseCursor, Point, Rectangle, Vector,
};
const SCROLLBAR_WIDTH: u16 = 10;
@@ -28,33 +27,18 @@ impl scrollable::Renderer for Renderer {
&& scrollbar_bounds(bounds).contains(cursor_position)
}
- fn draw<Message>(
+ fn draw(
&mut self,
- scrollable: &Scrollable<'_, Message, Self>,
+ state: &scrollable::State,
bounds: Rectangle,
- content: Layout<'_>,
- cursor_position: Point,
+ content_bounds: Rectangle,
+ is_mouse_over: bool,
+ is_mouse_over_scrollbar: bool,
+ offset: u32,
+ (content, mouse_cursor): Self::Output,
) -> Self::Output {
- let is_mouse_over = bounds.contains(cursor_position);
- let content_bounds = content.bounds();
-
- let offset = scrollable.state.offset(bounds, content_bounds);
let is_content_overflowing = content_bounds.height > bounds.height;
let scrollbar_bounds = scrollbar_bounds(bounds);
- let is_mouse_over_scrollbar = self.is_mouse_over_scrollbar(
- bounds,
- content_bounds,
- cursor_position,
- );
-
- let cursor_position = if is_mouse_over && !is_mouse_over_scrollbar {
- Point::new(cursor_position.x, cursor_position.y + offset as f32)
- } else {
- Point::new(cursor_position.x, -1.0)
- };
-
- let (content, mouse_cursor) =
- scrollable.content.draw(self, content, cursor_position);
let clip = Primitive::Clip {
bounds,
@@ -64,7 +48,7 @@ impl scrollable::Renderer for Renderer {
(
if is_content_overflowing
- && (is_mouse_over || scrollable.state.is_scrollbar_grabbed())
+ && (is_mouse_over || state.is_scrollbar_grabbed())
{
let ratio = bounds.height / content_bounds.height;
let scrollbar_height = bounds.height * ratio;
@@ -82,9 +66,7 @@ impl scrollable::Renderer for Renderer {
border_radius: 5,
};
- if is_mouse_over_scrollbar
- || scrollable.state.is_scrollbar_grabbed()
- {
+ if is_mouse_over_scrollbar || state.is_scrollbar_grabbed() {
let scrollbar_background = Primitive::Quad {
bounds: Rectangle {
x: scrollbar_bounds.x + f32::from(SCROLLBAR_MARGIN),
@@ -109,9 +91,7 @@ impl scrollable::Renderer for Renderer {
} else {
clip
},
- if is_mouse_over_scrollbar
- || scrollable.state.is_scrollbar_grabbed()
- {
+ if is_mouse_over_scrollbar || state.is_scrollbar_grabbed() {
MouseCursor::Idle
} else {
mouse_cursor