From 05884870fcca61849d8aa35cade354a192621092 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 20 Jul 2024 15:53:50 +0200 Subject: Make `container::Style` API more consistent --- widget/src/container.rs | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'widget/src/container.rs') 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, - width: impl Into, - ) -> Self { + /// Updates the text color of the [`Style`]. + pub fn color(self, color: impl Into) -> 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) -> Self { + Self { + border: border.into(), ..self } } /// Updates the background of the [`Style`]. - pub fn with_background(self, background: impl Into) -> Self { + pub fn background(self, background: impl Into) -> Self { Self { background: Some(background.into()), ..self } } + + /// Updates the shadow of the [`Style`]. + pub fn shadow(self, shadow: impl Into) -> Self { + Self { + shadow: shadow.into(), + ..self + } + } } impl From for Style { fn from(color: Color) -> Self { - Self::default().with_background(color) + Self::default().background(color) } } impl From for Style { fn from(gradient: Gradient) -> Self { - Self::default().with_background(gradient) + Self::default().background(gradient) } } impl From for Style { fn from(gradient: gradient::Linear) -> Self { - Self::default().with_background(gradient) + Self::default().background(gradient) } } -- cgit