Make container::Style API more consistent
This commit is contained in:
parent
c851e67734
commit
05884870fc
2 changed files with 26 additions and 17 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use iced::border;
|
||||
use iced::keyboard;
|
||||
use iced::mouse;
|
||||
use iced::widget::{
|
||||
|
|
@ -85,7 +86,7 @@ impl Layout {
|
|||
let palette = theme.extended_palette();
|
||||
|
||||
container::Style::default()
|
||||
.with_border(palette.background.strong.color, 4.0)
|
||||
.border(border::color(palette.background.strong.color).width(4))
|
||||
})
|
||||
.padding(4);
|
||||
|
||||
|
|
@ -240,7 +241,7 @@ fn application<'a>() -> Element<'a, Message> {
|
|||
let palette = theme.extended_palette();
|
||||
|
||||
container::Style::default()
|
||||
.with_border(palette.background.strong.color, 1)
|
||||
.border(border::color(palette.background.strong.color).width(1))
|
||||
});
|
||||
|
||||
let sidebar = container(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue