summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--widget/src/button.rs7
-rw-r--r--widget/src/column.rs15
-rw-r--r--widget/src/container.rs98
-rw-r--r--widget/src/helpers.rs2
-rw-r--r--widget/src/overlay/menu.rs7
-rw-r--r--widget/src/progress_bar.rs8
-rw-r--r--widget/src/radio.rs7
-rw-r--r--widget/src/row.rs15
-rw-r--r--widget/src/rule.rs4
-rw-r--r--widget/src/scrollable.rs183
-rw-r--r--widget/src/slider.rs10
-rw-r--r--widget/src/vertical_slider.rs9
12 files changed, 196 insertions, 169 deletions
diff --git a/widget/src/button.rs b/widget/src/button.rs
index fb505d6e..64a639d2 100644
--- a/widget/src/button.rs
+++ b/widget/src/button.rs
@@ -1,4 +1,5 @@
//! Allow your users to perform actions by pressing a button.
+use crate::core::border::{self, Border};
use crate::core::event::{self, Event};
use crate::core::layout;
use crate::core::mouse;
@@ -9,8 +10,8 @@ use crate::core::touch;
use crate::core::widget::tree::{self, Tree};
use crate::core::widget::Operation;
use crate::core::{
- Background, Border, Clipboard, Color, Element, Layout, Length, Padding,
- Rectangle, Shadow, Shell, Size, Theme, Vector, Widget,
+ Background, Clipboard, Color, Element, Layout, Length, Padding, Rectangle,
+ Shadow, Shell, Size, Theme, Vector, Widget,
};
/// A generic widget that produces a message when pressed.
@@ -591,7 +592,7 @@ fn styled(pair: palette::Pair) -> Style {
Style {
background: Some(Background::Color(pair.color)),
text_color: pair.text,
- border: Border::rounded(2),
+ border: border::rounded(2),
..Style::default()
}
}
diff --git a/widget/src/column.rs b/widget/src/column.rs
index 0b81c545..ae82ccaa 100644
--- a/widget/src/column.rs
+++ b/widget/src/column.rs
@@ -1,4 +1,5 @@
//! Distribute content vertically.
+use crate::core::alignment::{self, Alignment};
use crate::core::event::{self, Event};
use crate::core::layout;
use crate::core::mouse;
@@ -6,8 +7,8 @@ use crate::core::overlay;
use crate::core::renderer;
use crate::core::widget::{Operation, Tree};
use crate::core::{
- Alignment, Clipboard, Element, Layout, Length, Padding, Pixels, Rectangle,
- Shell, Size, Vector, Widget,
+ Clipboard, Element, Layout, Length, Padding, Pixels, Rectangle, Shell,
+ Size, Vector, Widget,
};
/// A container that distributes its contents vertically.
@@ -19,7 +20,7 @@ pub struct Column<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer>
width: Length,
height: Length,
max_width: f32,
- align_items: Alignment,
+ align: Alignment,
clip: bool,
children: Vec<Element<'a, Message, Theme, Renderer>>,
}
@@ -63,7 +64,7 @@ where
width: Length::Shrink,
height: Length::Shrink,
max_width: f32::INFINITY,
- align_items: Alignment::Start,
+ align: Alignment::Start,
clip: false,
children,
}
@@ -104,8 +105,8 @@ where
}
/// Sets the horizontal alignment of the contents of the [`Column`] .
- pub fn align_items(mut self, align: Alignment) -> Self {
- self.align_items = align;
+ pub fn align_x(mut self, align: impl Into<alignment::Horizontal>) -> Self {
+ self.align = Alignment::from(align.into());
self
}
@@ -210,7 +211,7 @@ where
self.height,
self.padding,
self.spacing,
- self.align_items,
+ self.align,
&self.children,
&mut tree.children,
)
diff --git a/widget/src/container.rs b/widget/src/container.rs
index 08d5cb17..5680bc30 100644
--- a/widget/src/container.rs
+++ b/widget/src/container.rs
@@ -1,5 +1,6 @@
//! Decorate content and apply alignment.
use crate::core::alignment::{self, Alignment};
+use crate::core::border::{self, Border};
use crate::core::event::{self, Event};
use crate::core::gradient::{self, Gradient};
use crate::core::layout;
@@ -9,9 +10,8 @@ use crate::core::renderer;
use crate::core::widget::tree::{self, Tree};
use crate::core::widget::{self, Operation};
use crate::core::{
- self, Background, Border, Clipboard, Color, Element, Layout, Length,
- Padding, Pixels, Point, Rectangle, Shadow, Shell, Size, Theme, Vector,
- Widget,
+ self, Background, Clipboard, Color, Element, Layout, Length, Padding,
+ Pixels, Point, Rectangle, Shadow, Shell, Size, Theme, Vector, Widget,
};
use crate::runtime::task::{self, Task};
@@ -92,46 +92,6 @@ where
self
}
- /// Sets the [`Container`] to fill the available space in the horizontal axis.
- ///
- /// This can be useful to quickly position content when chained with
- /// alignment functions—like [`center_x`].
- ///
- /// Calling this method is equivalent to calling [`width`] with a
- /// [`Length::Fill`].
- ///
- /// [`center_x`]: Self::center_x
- /// [`width`]: Self::width
- pub fn fill_x(self) -> Self {
- self.width(Length::Fill)
- }
-
- /// Sets the [`Container`] to fill the available space in the vetical axis.
- ///
- /// This can be useful to quickly position content when chained with
- /// alignment functions—like [`center_y`].
- ///
- /// Calling this method is equivalent to calling [`height`] with a
- /// [`Length::Fill`].
- ///
- /// [`center_y`]: Self::center_x
- /// [`height`]: Self::height
- pub fn fill_y(self) -> Self {
- self.height(Length::Fill)
- }
-
- /// Sets the [`Container`] to fill all the available space.
- ///
- /// Calling this method is equivalent to chaining [`fill_x`] and
- /// [`fill_y`].
- ///
- /// [`center`]: Self::center
- /// [`fill_x`]: Self::fill_x
- /// [`fill_y`]: Self::fill_y
- pub fn fill(self) -> Self {
- self.width(Length::Fill).height(Length::Fill)
- }
-
/// Sets the maximum width of the [`Container`].
pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {
self.max_width = max_width.into().0;
@@ -144,18 +104,6 @@ where
self
}
- /// Sets the content alignment for the horizontal axis of the [`Container`].
- pub fn align_x(mut self, alignment: alignment::Horizontal) -> Self {
- self.horizontal_alignment = alignment;
- self
- }
-
- /// Sets the content alignment for the vertical axis of the [`Container`].
- pub fn align_y(mut self, alignment: alignment::Vertical) -> Self {
- self.vertical_alignment = alignment;
- self
- }
-
/// Sets the width of the [`Container`] and centers its contents horizontally.
pub fn center_x(self, width: impl Into<Length>) -> Self {
self.width(width).align_x(alignment::Horizontal::Center)
@@ -179,6 +127,44 @@ where
self.center_x(length).center_y(length)
}
+ /// Aligns the contents of the [`Container`] to the left.
+ pub fn align_left(self, width: impl Into<Length>) -> Self {
+ self.width(width).align_x(alignment::Horizontal::Left)
+ }
+
+ /// Aligns the contents of the [`Container`] to the right.
+ pub fn align_right(self, width: impl Into<Length>) -> Self {
+ self.width(width).align_x(alignment::Horizontal::Right)
+ }
+
+ /// Aligns the contents of the [`Container`] to the top.
+ pub fn align_top(self, height: impl Into<Length>) -> Self {
+ self.height(height).align_y(alignment::Vertical::Top)
+ }
+
+ /// Aligns the contents of the [`Container`] to the bottom.
+ pub fn align_bottom(self, height: impl Into<Length>) -> Self {
+ self.height(height).align_y(alignment::Vertical::Bottom)
+ }
+
+ /// Sets the content alignment for the horizontal axis of the [`Container`].
+ pub fn align_x(
+ mut self,
+ alignment: impl Into<alignment::Horizontal>,
+ ) -> Self {
+ self.horizontal_alignment = alignment.into();
+ self
+ }
+
+ /// Sets the content alignment for the vertical axis of the [`Container`].
+ pub fn align_y(
+ mut self,
+ alignment: impl Into<alignment::Vertical>,
+ ) -> Self {
+ self.vertical_alignment = alignment.into();
+ self
+ }
+
/// Sets whether the contents of the [`Container`] should be clipped on
/// overflow.
pub fn clip(mut self, clip: bool) -> Self {
@@ -641,7 +627,7 @@ pub fn rounded_box(theme: &Theme) -> Style {
Style {
background: Some(palette.background.weak.color.into()),
- border: Border::rounded(2),
+ border: border::rounded(2),
..Style::default()
}
}
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index d7631959..1f282f54 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -921,7 +921,7 @@ where
text("iced").size(text_size).font(Font::MONOSPACE)
]
.spacing(text_size.0 / 3.0)
- .align_items(Alignment::Center)
+ .align_y(Alignment::Center)
.into()
}
diff --git a/widget/src/overlay/menu.rs b/widget/src/overlay/menu.rs
index a43c8e8b..73d1cc8c 100644
--- a/widget/src/overlay/menu.rs
+++ b/widget/src/overlay/menu.rs
@@ -1,5 +1,6 @@
//! Build and show dropdown menus.
use crate::core::alignment;
+use crate::core::border::{self, Border};
use crate::core::event::{self, Event};
use crate::core::layout::{self, Layout};
use crate::core::mouse;
@@ -9,8 +10,8 @@ use crate::core::text::{self, Text};
use crate::core::touch;
use crate::core::widget::Tree;
use crate::core::{
- Background, Border, Clipboard, Color, Length, Padding, Pixels, Point,
- Rectangle, Size, Theme, Vector,
+ Background, Clipboard, Color, Length, Padding, Pixels, Point, Rectangle,
+ Size, Theme, Vector,
};
use crate::core::{Element, Shell, Widget};
use crate::scrollable::{self, Scrollable};
@@ -514,7 +515,7 @@ where
width: bounds.width - style.border.width * 2.0,
..bounds
},
- border: Border::rounded(style.border.radius),
+ border: border::rounded(style.border.radius),
..renderer::Quad::default()
},
style.selected_background,
diff --git a/widget/src/progress_bar.rs b/widget/src/progress_bar.rs
index e7821b43..88d1850a 100644
--- a/widget/src/progress_bar.rs
+++ b/widget/src/progress_bar.rs
@@ -1,11 +1,11 @@
//! Provide progress feedback to your users.
+use crate::core::border::{self, Border};
use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::Tree;
use crate::core::{
- self, Background, Border, Element, Layout, Length, Rectangle, Size, Theme,
- Widget,
+ self, Background, Element, Layout, Length, Rectangle, Size, Theme, Widget,
};
use std::ops::RangeInclusive;
@@ -151,7 +151,7 @@ where
width: active_progress_width,
..bounds
},
- border: Border::rounded(style.border.radius),
+ border: border::rounded(style.border.radius),
..renderer::Quad::default()
},
style.bar,
@@ -255,6 +255,6 @@ fn styled(
Style {
background: background.into(),
bar: bar.into(),
- border: Border::rounded(2),
+ border: border::rounded(2),
}
}
diff --git a/widget/src/radio.rs b/widget/src/radio.rs
index 6b22961d..ccc6a21e 100644
--- a/widget/src/radio.rs
+++ b/widget/src/radio.rs
@@ -1,5 +1,6 @@
//! Create choices using radio buttons.
use crate::core::alignment;
+use crate::core::border::{self, Border};
use crate::core::event::{self, Event};
use crate::core::layout;
use crate::core::mouse;
@@ -9,8 +10,8 @@ use crate::core::touch;
use crate::core::widget;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
- Background, Border, Clipboard, Color, Element, Layout, Length, Pixels,
- Rectangle, Shell, Size, Theme, Widget,
+ Background, Clipboard, Color, Element, Layout, Length, Pixels, Rectangle,
+ Shell, Size, Theme, Widget,
};
/// A circular button representing a choice.
@@ -342,7 +343,7 @@ where
width: bounds.width - dot_size,
height: bounds.height - dot_size,
},
- border: Border::rounded(dot_size / 2.0),
+ border: border::rounded(dot_size / 2.0),
..renderer::Quad::default()
},
style.dot_color,
diff --git a/widget/src/row.rs b/widget/src/row.rs
index c8fcdb61..3feeaa7e 100644
--- a/widget/src/row.rs
+++ b/widget/src/row.rs
@@ -1,4 +1,5 @@
//! Distribute content horizontally.
+use crate::core::alignment::{self, Alignment};
use crate::core::event::{self, Event};
use crate::core::layout::{self, Layout};
use crate::core::mouse;
@@ -6,8 +7,8 @@ use crate::core::overlay;
use crate::core::renderer;
use crate::core::widget::{Operation, Tree};
use crate::core::{
- Alignment, Clipboard, Element, Length, Padding, Pixels, Rectangle, Shell,
- Size, Vector, Widget,
+ Clipboard, Element, Length, Padding, Pixels, Rectangle, Shell, Size,
+ Vector, Widget,
};
/// A container that distributes its contents horizontally.
@@ -17,7 +18,7 @@ pub struct Row<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer> {
padding: Padding,
width: Length,
height: Length,
- align_items: Alignment,
+ align: Alignment,
clip: bool,
children: Vec<Element<'a, Message, Theme, Renderer>>,
}
@@ -60,7 +61,7 @@ where
padding: Padding::ZERO,
width: Length::Shrink,
height: Length::Shrink,
- align_items: Alignment::Start,
+ align: Alignment::Start,
clip: false,
children,
}
@@ -95,8 +96,8 @@ where
}
/// Sets the vertical alignment of the contents of the [`Row`] .
- pub fn align_items(mut self, align: Alignment) -> Self {
- self.align_items = align;
+ pub fn align_y(mut self, align: impl Into<alignment::Vertical>) -> Self {
+ self.align = Alignment::from(align.into());
self
}
@@ -199,7 +200,7 @@ where
self.height,
self.padding,
self.spacing,
- self.align_items,
+ self.align,
&self.children,
&mut tree.children,
)
diff --git a/widget/src/rule.rs b/widget/src/rule.rs
index 1a536d2f..bbcd577e 100644
--- a/widget/src/rule.rs
+++ b/widget/src/rule.rs
@@ -1,6 +1,6 @@
//! Display a horizontal or vertical rule for dividing content.
use crate::core;
-use crate::core::border::{self, Border};
+use crate::core::border;
use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
@@ -132,7 +132,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
- border: Border::rounded(style.radius),
+ border: border::rounded(style.radius),
..renderer::Quad::default()
},
style.color,
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs
index e6208528..52e5391e 100644
--- a/widget/src/scrollable.rs
+++ b/widget/src/scrollable.rs
@@ -1,5 +1,6 @@
//! Navigate an endless amount of content with a scrollbar.
use crate::container;
+use crate::core::border::{self, Border};
use crate::core::event::{self, Event};
use crate::core::keyboard;
use crate::core::layout;
@@ -11,8 +12,8 @@ use crate::core::widget;
use crate::core::widget::operation::{self, Operation};
use crate::core::widget::tree::{self, Tree};
use crate::core::{
- self, Background, Border, Clipboard, Color, Element, Layout, Length,
- Padding, Pixels, Point, Rectangle, Shell, Size, Theme, Vector, Widget,
+ self, Background, Clipboard, Color, Element, Layout, Length, Padding,
+ Pixels, Point, Rectangle, Shell, Size, Theme, Vector, Widget,
};
use crate::runtime::task::{self, Task};
use crate::runtime::Action;
@@ -109,53 +110,70 @@ where
self
}
- /// Sets the alignment of the horizontal direction of the [`Scrollable`], if applicable.
- pub fn align_x(mut self, alignment: Alignment) -> Self {
+ /// Anchors the vertical [`Scrollable`] direction to the top.
+ pub fn anchor_top(self) -> Self {
+ self.anchor_y(Anchor::Start)
+ }
+
+ /// Anchors the vertical [`Scrollable`] direction to the bottom.
+ pub fn anchor_bottom(self) -> Self {
+ self.anchor_y(Anchor::End)
+ }
+
+ /// Anchors the horizontal [`Scrollable`] direction to the left.
+ pub fn anchor_left(self) -> Self {
+ self.anchor_x(Anchor::Start)
+ }
+
+ /// Anchors the horizontal [`Scrollable`] direction to the right.
+ pub fn anchor_right(self) -> Self {
+ self.anchor_x(Anchor::End)
+ }
+
+ /// Sets the [`Anchor`] of the horizontal direction of the [`Scrollable`], if applicable.
+ pub fn anchor_x(mut self, alignment: Anchor) -> Self {
match &mut self.direction {
- Direction::Horizontal(horizontal)
+ Direction::Horizontal {
+ scrollbar: horizontal,
+ ..
+ }
| Direction::Both { horizontal, .. } => {
horizontal.alignment = alignment;
}
- Direction::Vertical(_) => {}
+ Direction::Vertical { .. } => {}
}
self
}
- /// Sets the alignment of the vertical direction of the [`Scrollable`], if applicable.
- pub fn align_y(mut self, alignment: Alignment) -> Self {
+ /// Sets the [`Anchor`] of the vertical direction of the [`Scrollable`], if applicable.
+ pub fn anchor_y(mut self, alignment: Anchor) -> Self {
match &mut self.direction {
- Direction::Vertical(vertical)
+ Direction::Vertical {
+ scrollbar: vertical,
+ ..
+ }
| Direction::Both { vertical, .. } => {
vertical.alignment = alignment;
}
- Direction::Horizontal(_) => {}
+ Direction::Horizontal { .. } => {}
}
self
}
- /// Sets whether the horizontal [`Scrollbar`] should be embedded in the [`Scrollable`].
- pub fn embed_x(mut self, embedded: bool) -> Self {
- match &mut self.direction {
- Direction::Horizontal(horizontal)
- | Direction::Both { horizontal, .. } => {
- horizontal.embedded = embedded;
- }
- Direction::Vertical(_) => {}
- }
-
- self
- }
-
- /// Sets whether the vertical [`Scrollbar`] should be embedded in the [`Scrollable`].
- pub fn embed_y(mut self, embedded: bool) -> Self {
+ /// Embeds the [`Scrollbar`] into the [`Scrollable`], instead of floating on top of the
+ /// content.
+ ///
+ /// The `spacing` provided will be used as space between the [`Scrollbar`] and the contents
+ /// of the [`Scrollable`].
+ pub fn spacing(mut self, new_spacing: impl Into<Pixels>) -> Self {
match &mut self.direction {
- Direction::Vertical(vertical)
- | Direction::Both { vertical, .. } => {
- vertical.embedded = embedded;
+ Direction::Horizontal { spacing, .. }
+ | Direction::Vertical { spacing, .. } => {
+ *spacing = Some(new_spacing.into().0);
}
- Direction::Horizontal(_) => {}
+ Direction::Both { .. } => {}
}
self
@@ -184,9 +202,19 @@ where
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Direction {
/// Vertical scrolling
- Vertical(Scrollbar),
+ Vertical {
+ /// The vertical [`Scrollbar`].
+ scrollbar: Scrollbar,
+ /// The amount of spacing between the [`Scrollbar`] and the contents, if embedded.
+ spacing: Option<f32>,
+ },
/// Horizontal scrolling
- Horizontal(Scrollbar),
+ Horizontal {
+ /// The horizontal [`Scrollbar`].
+ scrollbar: Scrollbar,
+ /// The amount of spacing between the [`Scrollbar`] and the contents, if embedded.
+ spacing: Option<f32>,
+ },
/// Both vertical and horizontal scrolling
Both {
/// The properties of the vertical scrollbar.
@@ -200,25 +228,28 @@ impl Direction {
/// Returns the horizontal [`Scrollbar`], if any.
pub fn horizontal(&self) -> Option<&Scrollbar> {
match self {
- Self::Horizontal(properties) => Some(properties),
+ Self::Horizontal { scrollbar, .. } => Some(scrollbar),
Self::Both { horizontal, .. } => Some(horizontal),
- Self::Vertical(_) => None,
+ Self::Vertical { .. } => None,
}
}
/// Returns the vertical [`Scrollbar`], if any.
pub fn vertical(&self) -> Option<&Scrollbar> {
match self {
- Self::Vertical(properties) => Some(properties),
+ Self::Vertical { scrollbar, .. } => Some(scrollbar),
Self::Both { vertical, .. } => Some(vertical),
- Self::Horizontal(_) => None,
+ Self::Horizontal { .. } => None,
}
}
}
impl Default for Direction {
fn default() -> Self {
- Self::Vertical(Scrollbar::default())
+ Self::Vertical {
+ scrollbar: Scrollbar::default(),
+ spacing: None,
+ }
}
}
@@ -228,8 +259,8 @@ pub struct Scrollbar {
width: f32,
margin: f32,
scroller_width: f32,
- alignment: Alignment,
- embedded: bool,
+ alignment: Anchor,
+ spacing: Option<f32>,
}
impl Default for Scrollbar {
@@ -238,8 +269,8 @@ impl Default for Scrollbar {
width: 10.0,
margin: 0.0,
scroller_width: 10.0,
- alignment: Alignment::Start,
- embedded: false,
+ alignment: Anchor::Start,
+ spacing: None,
}
}
}
@@ -250,47 +281,49 @@ impl Scrollbar {
Self::default()
}
- /// Sets the scrollbar width of the [`Scrollable`] .
+ /// Sets the scrollbar width of the [`Scrollbar`] .
pub fn width(mut self, width: impl Into<Pixels>) -> Self {
self.width = width.into().0.max(0.0);
self
}
- /// Sets the scrollbar margin of the [`Scrollable`] .
+ /// Sets the scrollbar margin of the [`Scrollbar`] .
pub fn margin(mut self, margin: impl Into<Pixels>) -> Self {
self.margin = margin.into().0;
self
}
- /// Sets the scroller width of the [`Scrollable`] .
+ /// Sets the scroller width of the [`Scrollbar`] .
pub fn scroller_width(mut self, scroller_width: impl Into<Pixels>) -> Self {
self.scroller_width = scroller_width.into().0.max(0.0);
self
}
- /// Sets the alignment of the [`Scrollable`] .
- pub fn alignment(mut self, alignment: Alignment) -> Self {
+ /// Sets the [`Anchor`] of the [`Scrollbar`] .
+ pub fn anchor(mut self, alignment: Anchor) -> Self {
self.alignment = alignment;
self
}
- /// Sets whether the [`Scrollbar`] should be embedded in the [`Scrollable`].
+ /// Sets whether the [`Scrollbar`] should be embedded in the [`Scrollable`], using
+ /// the given spacing between itself and the contents.
///
/// An embedded [`Scrollbar`] will always be displayed, will take layout space,
/// and will not float over the contents.
- pub fn embedded(mut self, embedded: bool) -> Self {
- self.embedded = embedded;
+ pub fn spacing(mut self, spacing: impl Into<Pixels>) -> Self {
+ self.spacing = Some(spacing.into().0);
self
}
}
-/// Alignment of the scrollable's content relative to it's [`Viewport`] in one direction.
+/// The anchor of the scroller of the [`Scrollable`] relative to its [`Viewport`]
+/// on a given axis.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
-pub enum Alignment {
- /// Content is aligned to the start of the [`Viewport`].
+pub enum Anchor {
+ /// Scroller is anchoer to the start of the [`Viewport`].
#[default]
Start,
- /// Content is aligned to the end of the [`Viewport`]
+ /// Content is aligned to the end of the [`Viewport`].
End,
}
@@ -330,12 +363,14 @@ where
limits: &layout::Limits,
) -> layout::Node {
let (right_padding, bottom_padding) = match self.direction {
- Direction::Vertical(scrollbar) if scrollbar.embedded => {
- (scrollbar.width + scrollbar.margin * 2.0, 0.0)
- }
- Direction::Horizontal(scrollbar) if scrollbar.embedded => {
- (0.0, scrollbar.width + scrollbar.margin * 2.0)
- }
+ Direction::Vertical {
+ scrollbar,
+ spacing: Some(spacing),
+ } => (scrollbar.width + scrollbar.margin * 2.0 + spacing, 0.0),
+ Direction::Horizontal {
+ scrollbar,
+ spacing: Some(spacing),
+ } => (0.0, scrollbar.width + scrollbar.margin * 2.0 + spacing),
_ => (0.0, 0.0),
};
@@ -1159,13 +1194,13 @@ impl Offset {
self,
viewport: f32,
content: f32,
- alignment: Alignment,
+ alignment: Anchor,
) -> f32 {
let offset = self.absolute(viewport, content);
match alignment {
- Alignment::Start => offset,
- Alignment::End => ((content - viewport).max(0.0) - offset).max(0.0),
+ Anchor::Start => offset,
+ Anchor::End => ((content - viewport).max(0.0) - offset).max(0.0),
}
}
}
@@ -1252,9 +1287,9 @@ impl State {
.map(|p| p.alignment)
.unwrap_or_default();
- let align = |alignment: Alignment, delta: f32| match alignment {
- Alignment::Start => delta,
- Alignment::End => -delta,
+ let align = |alignment: Anchor, delta: f32| match alignment {
+ Anchor::Start => delta,
+ Anchor::End => -delta,
};
let delta = Vector::new(
@@ -1385,11 +1420,11 @@ impl Scrollbars {
let translation = state.translation(direction, bounds, content_bounds);
let show_scrollbar_x = direction.horizontal().filter(|scrollbar| {
- scrollbar.embedded || content_bounds.width > bounds.width
+ scrollbar.spacing.is_some() || content_bounds.width > bounds.width
});
let show_scrollbar_y = direction.vertical().filter(|scrollbar| {
- scrollbar.embedded || content_bounds.height > bounds.height
+ scrollbar.spacing.is_some() || content_bounds.height > bounds.height
});
let y_scrollbar = if let Some(vertical) = show_scrollbar_y {
@@ -1592,14 +1627,14 @@ impl Scrollbars {
pub(super) mod internals {
use crate::core::{Point, Rectangle};
- use super::Alignment;
+ use super::Anchor;
#[derive(Debug, Copy, Clone)]
pub struct Scrollbar {
pub total_bounds: Rectangle,
pub bounds: Rectangle,
pub scroller: Option<Scroller>,
- pub alignment: Alignment,
+ pub alignment: Anchor,
}
impl Scrollbar {
@@ -1621,8 +1656,8 @@ pub(super) mod internals {
/ (self.bounds.height - scroller.bounds.height);
match self.alignment {
- Alignment::Start => percentage,
- Alignment::End => 1.0 - percentage,
+ Anchor::Start => percentage,
+ Anchor::End => 1.0 - percentage,
}
} else {
0.0
@@ -1642,8 +1677,8 @@ pub(super) mod internals {
/ (self.bounds.width - scroller.bounds.width);
match self.alignment {
- Alignment::Start => percentage,
- Alignment::End => 1.0 - percentage,
+ Anchor::Start => percentage,
+ Anchor::End => 1.0 - percentage,
}
} else {
0.0
@@ -1746,10 +1781,10 @@ pub fn default(theme: &Theme, status: Status) -> Style {
let scrollbar = Rail {
background: Some(palette.background.weak.color.into()),
- border: Border::rounded(2),
+ border: border::rounded(2),
scroller: Scroller {
color: palette.background.strong.color,
- border: Border::rounded(2),
+ border: border::rounded(2),
},
};
diff --git a/widget/src/slider.rs b/widget/src/slider.rs
index 74e6f8d3..b9419232 100644
--- a/widget/src/slider.rs
+++ b/widget/src/slider.rs
@@ -1,5 +1,5 @@
//! Display an interactive selector of a single value from a range of values.
-use crate::core::border;
+use crate::core::border::{self, Border};
use crate::core::event::{self, Event};
use crate::core::keyboard;
use crate::core::keyboard::key::{self, Key};
@@ -9,8 +9,8 @@ use crate::core::renderer;
use crate::core::touch;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
- self, Border, Clipboard, Color, Element, Layout, Length, Pixels, Point,
- Rectangle, Shell, Size, Theme, Widget,
+ self, Clipboard, Color, Element, Layout, Length, Pixels, Point, Rectangle,
+ Shell, Size, Theme, Widget,
};
use std::ops::RangeInclusive;
@@ -408,7 +408,7 @@ where
width: offset + handle_width / 2.0,
height: style.rail.width,
},
- border: Border::rounded(style.rail.border_radius),
+ border: border::rounded(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.0,
@@ -422,7 +422,7 @@ where
width: bounds.width - offset - handle_width / 2.0,
height: style.rail.width,
},
- border: Border::rounded(style.rail.border_radius),
+ border: border::rounded(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.1,
diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs
index 33c591f5..6185295b 100644
--- a/widget/src/vertical_slider.rs
+++ b/widget/src/vertical_slider.rs
@@ -5,6 +5,7 @@ pub use crate::slider::{
default, Catalog, Handle, HandleShape, Status, Style, StyleFn,
};
+use crate::core::border::{self, Border};
use crate::core::event::{self, Event};
use crate::core::keyboard;
use crate::core::keyboard::key::{self, Key};
@@ -14,8 +15,8 @@ use crate::core::renderer;
use crate::core::touch;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
- self, Border, Clipboard, Element, Length, Pixels, Point, Rectangle, Shell,
- Size, Widget,
+ self, Clipboard, Element, Length, Pixels, Point, Rectangle, Shell, Size,
+ Widget,
};
/// An vertical bar and a handle that selects a single value from a range of
@@ -412,7 +413,7 @@ where
width: style.rail.width,
height: offset + handle_width / 2.0,
},
- border: Border::rounded(style.rail.border_radius),
+ border: border::rounded(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.1,
@@ -426,7 +427,7 @@ where
width: style.rail.width,
height: bounds.height - offset - handle_width / 2.0,
},
- border: Border::rounded(style.rail.border_radius),
+ border: border::rounded(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.0,