summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-18 14:48:33 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-18 14:48:33 +0700
commit54a9a232f8110364972a8eef966b7b7477573f4f (patch)
treea6abebbcfefbd53d4c4d006d6911353801ea3284 /graphics
parenta4f4d831615899046d36c96e6a580d5386aa25bf (diff)
downloadiced-54a9a232f8110364972a8eef966b7b7477573f4f.tar.gz
iced-54a9a232f8110364972a8eef966b7b7477573f4f.tar.bz2
iced-54a9a232f8110364972a8eef966b7b7477573f4f.zip
Draw scrollbar in `Widget::draw` for `Scrollable`
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/widget/scrollable.rs64
1 files changed, 1 insertions, 63 deletions
diff --git a/graphics/src/widget/scrollable.rs b/graphics/src/widget/scrollable.rs
index f1fe0d2d..61eae587 100644
--- a/graphics/src/widget/scrollable.rs
+++ b/graphics/src/widget/scrollable.rs
@@ -1,7 +1,5 @@
//! Navigate an endless amount of content with a scrollbar.
-use crate::{Backend, Renderer};
-use iced_native::scrollable;
-use iced_native::Rectangle;
+use crate::Renderer;
pub use iced_native::scrollable::State;
pub use iced_style::scrollable::{Scrollbar, Scroller, StyleSheet};
@@ -13,63 +11,3 @@ pub use iced_style::scrollable::{Scrollbar, Scroller, StyleSheet};
/// `Renderer`.
pub type Scrollable<'a, Message, Backend> =
iced_native::Scrollable<'a, Message, Renderer<Backend>>;
-
-impl<B> scrollable::Renderer for Renderer<B>
-where
- B: Backend,
-{
- type Style = Box<dyn iced_style::scrollable::StyleSheet>;
-
- fn scrollbar(
- &self,
- bounds: Rectangle,
- content_bounds: Rectangle,
- offset: u32,
- scrollbar_width: u16,
- scrollbar_margin: u16,
- scroller_width: u16,
- ) -> Option<scrollable::Scrollbar> {
- if content_bounds.height > bounds.height {
- let outer_width =
- scrollbar_width.max(scroller_width) + 2 * scrollbar_margin;
-
- let outer_bounds = Rectangle {
- x: bounds.x + bounds.width - outer_width as f32,
- y: bounds.y,
- width: outer_width as f32,
- height: bounds.height,
- };
-
- let scrollbar_bounds = Rectangle {
- x: bounds.x + bounds.width
- - f32::from(outer_width / 2 + scrollbar_width / 2),
- y: bounds.y,
- width: scrollbar_width as f32,
- height: bounds.height,
- };
-
- let ratio = bounds.height / content_bounds.height;
- let scroller_height = bounds.height * ratio;
- let y_offset = offset as f32 * ratio;
-
- let scroller_bounds = Rectangle {
- x: bounds.x + bounds.width
- - f32::from(outer_width / 2 + scroller_width / 2),
- y: scrollbar_bounds.y + y_offset,
- width: scroller_width as f32,
- height: scroller_height,
- };
-
- Some(scrollable::Scrollbar {
- outer_bounds,
- bounds: scrollbar_bounds,
- margin: scrollbar_margin,
- scroller: scrollable::Scroller {
- bounds: scroller_bounds,
- },
- })
- } else {
- None
- }
- }
-}