diff options
author | 2024-07-20 15:53:50 +0200 | |
---|---|---|
committer | 2024-07-20 15:53:50 +0200 | |
commit | 05884870fcca61849d8aa35cade354a192621092 (patch) | |
tree | 1e26b7314493c76de7b6038573d678ca88a3973a /widget | |
parent | c851e67734ec0c761adfd7881c576856ea38734b (diff) | |
download | iced-05884870fcca61849d8aa35cade354a192621092.tar.gz iced-05884870fcca61849d8aa35cade354a192621092.tar.bz2 iced-05884870fcca61849d8aa35cade354a192621092.zip |
Make `container::Style` API more consistent
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/container.rs | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/widget/src/container.rs b/widget/src/container.rs index 5680bc30..d65bb086 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -546,46 +546,54 @@ pub struct Style { } impl Style { - /// Updates the border of the [`Style`] with the given [`Color`] and `width`. - pub fn with_border( - self, - color: impl Into<Color>, - width: impl Into<Pixels>, - ) -> Self { + /// Updates the text color of the [`Style`]. + pub fn color(self, color: impl Into<Color>) -> Self { Self { - border: Border { - color: color.into(), - width: width.into().0, - ..Border::default() - }, + text_color: Some(color.into()), + ..self + } + } + + /// Updates the border of the [`Style`]. + pub fn border(self, border: impl Into<Border>) -> Self { + Self { + border: border.into(), ..self } } /// Updates the background of the [`Style`]. - pub fn with_background(self, background: impl Into<Background>) -> Self { + pub fn background(self, background: impl Into<Background>) -> Self { Self { background: Some(background.into()), ..self } } + + /// Updates the shadow of the [`Style`]. + pub fn shadow(self, shadow: impl Into<Shadow>) -> Self { + Self { + shadow: shadow.into(), + ..self + } + } } impl From<Color> for Style { fn from(color: Color) -> Self { - Self::default().with_background(color) + Self::default().background(color) } } impl From<Gradient> for Style { fn from(gradient: Gradient) -> Self { - Self::default().with_background(gradient) + Self::default().background(gradient) } } impl From<gradient::Linear> for Style { fn from(gradient: gradient::Linear) -> Self { - Self::default().with_background(gradient) + Self::default().background(gradient) } } |