diff options
author | 2024-03-07 21:02:17 +0100 | |
---|---|---|
committer | 2024-03-07 21:02:17 +0100 | |
commit | 7ece5eea509f3595432babfc7729701f2e063b21 (patch) | |
tree | 42502a52270f24d1d323a268a36c689cd92aec82 /core | |
parent | b8f05eb8dd0394e308385796c229cfc5bc4f3a73 (diff) | |
download | iced-7ece5eea509f3595432babfc7729701f2e063b21.tar.gz iced-7ece5eea509f3595432babfc7729701f2e063b21.tar.bz2 iced-7ece5eea509f3595432babfc7729701f2e063b21.zip |
Implement additional helpers for `Border` and `container::Appearance`
Diffstat (limited to 'core')
-rw-r--r-- | core/src/border.rs | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/core/src/border.rs b/core/src/border.rs index 64262471..2df24988 100644 --- a/core/src/border.rs +++ b/core/src/border.rs @@ -1,5 +1,5 @@ //! Draw lines around containers. -use crate::Color; +use crate::{Color, Pixels}; /// A border. #[derive(Debug, Clone, Copy, PartialEq, Default)] @@ -15,11 +15,38 @@ pub struct Border { } impl Border { - /// Creates a new default [`Border`] with the given [`Radius`]. - pub fn with_radius(radius: impl Into<Radius>) -> Self { + /// Creates a new default rounded [`Border`] with the given [`Radius`]. + /// + /// ``` + /// # use iced_core::Border; + /// # + /// assert_eq!(Border::rounded(10), Border::default().with_radius(10)); + /// ``` + pub fn rounded(radius: impl Into<Radius>) -> Self { + Self::default().with_radius(radius) + } + + /// Updates the [`Color`] of the [`Border`]. + pub fn with_color(self, color: impl Into<Color>) -> Self { + Self { + color: color.into(), + ..self + } + } + + /// Updates the [`Radius`] of the [`Border`]. + pub fn with_radius(self, radius: impl Into<Radius>) -> Self { Self { radius: radius.into(), - ..Self::default() + ..self + } + } + + /// Updates the width of the [`Border`]. + pub fn with_width(self, width: impl Into<Pixels>) -> Self { + Self { + width: width.into().0, + ..self } } } |