summaryrefslogtreecommitdiffstats
path: root/native/src/widget
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/widget')
-rw-r--r--native/src/widget/button.rs1
-rw-r--r--native/src/widget/checkbox.rs1
-rw-r--r--native/src/widget/column.rs16
-rw-r--r--native/src/widget/container.rs3
-rw-r--r--native/src/widget/image.rs4
-rw-r--r--native/src/widget/pane_grid.rs1
-rw-r--r--native/src/widget/pick_list.rs1
-rw-r--r--native/src/widget/progress_bar.rs1
-rw-r--r--native/src/widget/radio.rs1
-rw-r--r--native/src/widget/row.rs19
-rw-r--r--native/src/widget/rule.rs1
-rw-r--r--native/src/widget/scrollable.rs74
-rw-r--r--native/src/widget/slider.rs1
-rw-r--r--native/src/widget/space.rs1
-rw-r--r--native/src/widget/svg.rs4
-rw-r--r--native/src/widget/text.rs1
-rw-r--r--native/src/widget/text_input.rs1
17 files changed, 117 insertions, 14 deletions
diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs
index fd74563a..995ba7bc 100644
--- a/native/src/widget/button.rs
+++ b/native/src/widget/button.rs
@@ -217,6 +217,7 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
renderer.draw(
defaults,
diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs
index 99178aae..e389427e 100644
--- a/native/src/widget/checkbox.rs
+++ b/native/src/widget/checkbox.rs
@@ -180,6 +180,7 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
let bounds = layout.bounds();
let mut children = layout.children();
diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs
index a5ac2101..e874ad42 100644
--- a/native/src/widget/column.rs
+++ b/native/src/widget/column.rs
@@ -1,9 +1,11 @@
//! Distribute content vertically.
use std::hash::Hash;
+use crate::layout;
+use crate::overlay;
use crate::{
- layout, overlay, Align, Clipboard, Element, Event, Hasher, Layout, Length,
- Point, Widget,
+ Align, Clipboard, Element, Event, Hasher, Layout, Length, Point, Rectangle,
+ Widget,
};
use std::u32;
@@ -181,8 +183,15 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ viewport: &Rectangle,
) -> Renderer::Output {
- renderer.draw(defaults, &self.children, layout, cursor_position)
+ renderer.draw(
+ defaults,
+ &self.children,
+ layout,
+ cursor_position,
+ viewport,
+ )
}
fn hash_layout(&self, state: &mut Hasher) {
@@ -237,6 +246,7 @@ pub trait Renderer: crate::Renderer + Sized {
content: &[Element<'_, Message, Self>],
layout: Layout<'_>,
cursor_position: Point,
+ viewport: &Rectangle,
) -> Self::Output;
}
diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs
index b8316e62..5b04d699 100644
--- a/native/src/widget/container.rs
+++ b/native/src/widget/container.rs
@@ -191,11 +191,13 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ viewport: &Rectangle,
) -> Renderer::Output {
renderer.draw(
defaults,
layout.bounds(),
cursor_position,
+ viewport,
&self.style,
&self.content,
layout.children().next().unwrap(),
@@ -242,6 +244,7 @@ pub trait Renderer: crate::Renderer {
defaults: &Self::Defaults,
bounds: Rectangle,
cursor_position: Point,
+ viewport: &Rectangle,
style: &Self::Style,
content: &Element<'_, Message, Self>,
content_layout: Layout<'_>,
diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs
index 132f249d..9586da0f 100644
--- a/native/src/widget/image.rs
+++ b/native/src/widget/image.rs
@@ -1,5 +1,6 @@
//! Display images in your user interface.
-use crate::{layout, Element, Hasher, Layout, Length, Point, Size, Widget};
+use crate::layout;
+use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget};
use std::{
hash::{Hash, Hasher as _},
@@ -97,6 +98,7 @@ where
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
renderer.draw(self.handle.clone(), layout)
}
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index 5180fd3b..276bfae3 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -588,6 +588,7 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
let picked_split = self
.state
diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs
index 0e42a3e4..e086e367 100644
--- a/native/src/widget/pick_list.rs
+++ b/native/src/widget/pick_list.rs
@@ -256,6 +256,7 @@ where
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
self::Renderer::draw(
renderer,
diff --git a/native/src/widget/progress_bar.rs b/native/src/widget/progress_bar.rs
index 5ab76d47..4f8a7e1b 100644
--- a/native/src/widget/progress_bar.rs
+++ b/native/src/widget/progress_bar.rs
@@ -104,6 +104,7 @@ where
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
renderer.draw(
layout.bounds(),
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index a7cabd49..06d3f846 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -183,6 +183,7 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
let bounds = layout.bounds();
let mut children = layout.children();
diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs
index b37a5cfc..bc8a3df1 100644
--- a/native/src/widget/row.rs
+++ b/native/src/widget/row.rs
@@ -1,11 +1,12 @@
//! Distribute content horizontally.
-use std::hash::Hash;
-
+use crate::layout;
+use crate::overlay;
use crate::{
- layout, overlay, Align, Clipboard, Element, Event, Hasher, Layout, Length,
- Point, Widget,
+ Align, Clipboard, Element, Event, Hasher, Layout, Length, Point, Rectangle,
+ Widget,
};
+use std::hash::Hash;
use std::u32;
/// A container that distributes its contents horizontally.
@@ -182,8 +183,15 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ viewport: &Rectangle,
) -> Renderer::Output {
- renderer.draw(defaults, &self.children, layout, cursor_position)
+ renderer.draw(
+ defaults,
+ &self.children,
+ layout,
+ cursor_position,
+ viewport,
+ )
}
fn hash_layout(&self, state: &mut Hasher) {
@@ -238,6 +246,7 @@ pub trait Renderer: crate::Renderer + Sized {
children: &[Element<'_, Message, Self>],
layout: Layout<'_>,
cursor_position: Point,
+ viewport: &Rectangle,
) -> Self::Output;
}
diff --git a/native/src/widget/rule.rs b/native/src/widget/rule.rs
index 25cec53b..66328c08 100644
--- a/native/src/widget/rule.rs
+++ b/native/src/widget/rule.rs
@@ -77,6 +77,7 @@ where
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
renderer.draw(layout.bounds(), &self.style, self.is_horizontal)
}
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs
index 75e97027..60ec2d7d 100644
--- a/native/src/widget/scrollable.rs
+++ b/native/src/widget/scrollable.rs
@@ -13,6 +13,9 @@ pub struct Scrollable<'a, Message, Renderer: self::Renderer> {
state: &'a mut State,
height: Length,
max_height: u32,
+ scrollbar_width: u16,
+ scrollbar_margin: u16,
+ scroller_width: u16,
content: Column<'a, Message, Renderer>,
style: Renderer::Style,
}
@@ -27,6 +30,9 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> {
state,
height: Length::Shrink,
max_height: u32::MAX,
+ scrollbar_width: 10,
+ scrollbar_margin: 0,
+ scroller_width: 10,
content: Column::new(),
style: Renderer::Style::default(),
}
@@ -90,6 +96,32 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> {
self
}
+ /// Sets the scrollbar width of the [`Scrollable`] .
+ /// Silently enforces a minimum value of 1.
+ ///
+ /// [`Scrollable`]: struct.Scrollable.html
+ pub fn scrollbar_width(mut self, scrollbar_width: u16) -> Self {
+ self.scrollbar_width = scrollbar_width.max(1);
+ self
+ }
+
+ /// Sets the scrollbar margin of the [`Scrollable`] .
+ ///
+ /// [`Scrollable`]: struct.Scrollable.html
+ pub fn scrollbar_margin(mut self, scrollbar_margin: u16) -> Self {
+ self.scrollbar_margin = scrollbar_margin;
+ self
+ }
+
+ /// Sets the scroller width of the [`Scrollable`] .
+ /// Silently enforces a minimum value of 1.
+ ///
+ /// [`Scrollable`]: struct.Scrollable.html
+ pub fn scroller_width(mut self, scroller_width: u16) -> Self {
+ self.scroller_width = scroller_width.max(1);
+ self
+ }
+
/// Sets the style of the [`Scrollable`] .
///
/// [`Scrollable`]: struct.Scrollable.html
@@ -178,7 +210,14 @@ where
}
let offset = self.state.offset(bounds, content_bounds);
- let scrollbar = renderer.scrollbar(bounds, content_bounds, offset);
+ let scrollbar = renderer.scrollbar(
+ bounds,
+ content_bounds,
+ offset,
+ self.scrollbar_width,
+ self.scrollbar_margin,
+ self.scroller_width,
+ );
let is_mouse_over_scrollbar = scrollbar
.as_ref()
.map(|scrollbar| scrollbar.is_mouse_over(cursor_position))
@@ -264,12 +303,20 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
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);
- let scrollbar = renderer.scrollbar(bounds, content_bounds, offset);
+ let scrollbar = renderer.scrollbar(
+ bounds,
+ content_bounds,
+ offset,
+ self.scrollbar_width,
+ self.scrollbar_margin,
+ self.scroller_width,
+ );
let is_mouse_over = bounds.contains(cursor_position);
let is_mouse_over_scrollbar = scrollbar
@@ -289,6 +336,10 @@ where
defaults,
content_layout,
cursor_position,
+ &Rectangle {
+ y: bounds.y + offset as f32,
+ ..bounds
+ },
)
};
@@ -413,11 +464,23 @@ impl State {
/// [`Scrollable`]: struct.Scrollable.html
#[derive(Debug)]
pub struct Scrollbar {
+ /// The outer bounds of the scrollable, including the [`Scrollbar`] and
+ /// [`Scroller`].
+ ///
+ /// [`Scrollbar`]: struct.Scrollbar.html
+ /// [`Scroller`]: struct.Scroller.html
+ pub outer_bounds: Rectangle,
+
/// The bounds of the [`Scrollbar`].
///
/// [`Scrollbar`]: struct.Scrollbar.html
pub bounds: Rectangle,
+ /// The margin within the [`Scrollbar`].
+ ///
+ /// [`Scrollbar`]: struct.Scrollbar.html
+ pub margin: u16,
+
/// The bounds of the [`Scroller`].
///
/// [`Scroller`]: struct.Scroller.html
@@ -426,11 +489,11 @@ pub struct Scrollbar {
impl Scrollbar {
fn is_mouse_over(&self, cursor_position: Point) -> bool {
- self.bounds.contains(cursor_position)
+ self.outer_bounds.contains(cursor_position)
}
fn grab_scroller(&self, cursor_position: Point) -> Option<f32> {
- if self.bounds.contains(cursor_position) {
+ if self.outer_bounds.contains(cursor_position) {
Some(if self.scroller.bounds.contains(cursor_position) {
(cursor_position.y - self.scroller.bounds.y)
/ self.scroller.bounds.height
@@ -486,6 +549,9 @@ pub trait Renderer: column::Renderer + Sized {
bounds: Rectangle,
content_bounds: Rectangle,
offset: u32,
+ scrollbar_width: u16,
+ scrollbar_margin: u16,
+ scroller_width: u16,
) -> Option<Scrollbar>;
/// Draws the [`Scrollable`].
diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs
index 3255dd04..d6e366aa 100644
--- a/native/src/widget/slider.rs
+++ b/native/src/widget/slider.rs
@@ -259,6 +259,7 @@ where
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
let start = *self.range.start();
let end = *self.range.end();
diff --git a/native/src/widget/space.rs b/native/src/widget/space.rs
index f1576ffb..032f341d 100644
--- a/native/src/widget/space.rs
+++ b/native/src/widget/space.rs
@@ -71,6 +71,7 @@ where
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
renderer.draw(layout.bounds())
}
diff --git a/native/src/widget/svg.rs b/native/src/widget/svg.rs
index 114d5e41..ede1aff8 100644
--- a/native/src/widget/svg.rs
+++ b/native/src/widget/svg.rs
@@ -1,5 +1,6 @@
//! Display vector graphics in your application.
-use crate::{layout, Element, Hasher, Layout, Length, Point, Size, Widget};
+use crate::layout;
+use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget};
use std::{
hash::{Hash, Hasher as _},
@@ -103,6 +104,7 @@ where
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
renderer.draw(self.handle.clone(), layout)
}
diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs
index 48a69e34..c2544b8e 100644
--- a/native/src/widget/text.rs
+++ b/native/src/widget/text.rs
@@ -149,6 +149,7 @@ where
defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
renderer.draw(
defaults,
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index 32a57ce6..64182f2d 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -497,6 +497,7 @@ where
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point,
+ _viewport: &Rectangle,
) -> Renderer::Output {
let bounds = layout.bounds();
let text_bounds = layout.children().next().unwrap().bounds();