Rename Variant to Style and Style to Appearance
This commit is contained in:
parent
7f3b7075db
commit
cf0230072c
12 changed files with 91 additions and 99 deletions
|
|
@ -3,7 +3,7 @@ use iced_core::{Background, Color, Vector};
|
|||
|
||||
/// The appearance of a button.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Style {
|
||||
pub struct Appearance {
|
||||
pub shadow_offset: Vector,
|
||||
pub background: Option<Background>,
|
||||
pub border_radius: f32,
|
||||
|
|
@ -12,7 +12,7 @@ pub struct Style {
|
|||
pub text_color: Color,
|
||||
}
|
||||
|
||||
impl std::default::Default for Style {
|
||||
impl std::default::Default for Appearance {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
shadow_offset: Vector::default(),
|
||||
|
|
@ -27,30 +27,30 @@ impl std::default::Default for Style {
|
|||
|
||||
/// A set of rules that dictate the style of a button.
|
||||
pub trait StyleSheet {
|
||||
type Variant;
|
||||
type Style: Default + Copy;
|
||||
|
||||
fn active(&self, variant: Self::Variant) -> Style;
|
||||
fn active(&self, style: Self::Style) -> Appearance;
|
||||
|
||||
fn hovered(&self, variant: Self::Variant) -> Style {
|
||||
let active = self.active(variant);
|
||||
fn hovered(&self, style: Self::Style) -> Appearance {
|
||||
let active = self.active(style);
|
||||
|
||||
Style {
|
||||
Appearance {
|
||||
shadow_offset: active.shadow_offset + Vector::new(0.0, 1.0),
|
||||
..active
|
||||
}
|
||||
}
|
||||
|
||||
fn pressed(&self, variant: Self::Variant) -> Style {
|
||||
Style {
|
||||
fn pressed(&self, style: Self::Style) -> Appearance {
|
||||
Appearance {
|
||||
shadow_offset: Vector::default(),
|
||||
..self.active(variant)
|
||||
..self.active(style)
|
||||
}
|
||||
}
|
||||
|
||||
fn disabled(&self, variant: Self::Variant) -> Style {
|
||||
let active = self.active(variant);
|
||||
fn disabled(&self, style: Self::Style) -> Appearance {
|
||||
let active = self.active(style);
|
||||
|
||||
Style {
|
||||
Appearance {
|
||||
shadow_offset: Vector::default(),
|
||||
background: active.background.map(|background| match background {
|
||||
Background::Color(color) => Background::Color(Color {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use iced_core::Color;
|
|||
|
||||
/// The appearance of a slider.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Style {
|
||||
pub struct Appearance {
|
||||
pub rail_colors: (Color, Color),
|
||||
pub handle: Handle,
|
||||
}
|
||||
|
|
@ -26,14 +26,14 @@ pub enum HandleShape {
|
|||
|
||||
/// A set of rules that dictate the style of a slider.
|
||||
pub trait StyleSheet {
|
||||
type Variant: Default + Copy;
|
||||
type Style: Default + Copy;
|
||||
|
||||
/// Produces the style of an active slider.
|
||||
fn active(&self, variant: Self::Variant) -> Style;
|
||||
fn active(&self, style: Self::Style) -> Appearance;
|
||||
|
||||
/// Produces the style of an hovered slider.
|
||||
fn hovered(&self, variant: Self::Variant) -> Style;
|
||||
fn hovered(&self, style: Self::Style) -> Appearance;
|
||||
|
||||
/// Produces the style of a slider that is being dragged.
|
||||
fn dragging(&self, variant: Self::Variant) -> Style;
|
||||
fn dragging(&self, style: Self::Style) -> Appearance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,49 +66,49 @@ impl Default for Button {
|
|||
}
|
||||
|
||||
impl button::StyleSheet for Theme {
|
||||
type Variant = Button;
|
||||
type Style = Button;
|
||||
|
||||
fn active(&self, variant: Self::Variant) -> button::Style {
|
||||
fn active(&self, style: Self::Style) -> button::Appearance {
|
||||
let palette = self.extended_palette();
|
||||
|
||||
let style = button::Style {
|
||||
let appearance = button::Appearance {
|
||||
border_radius: 2.0,
|
||||
..button::Style::default()
|
||||
..button::Appearance::default()
|
||||
};
|
||||
|
||||
match variant {
|
||||
Button::Primary => button::Style {
|
||||
match style {
|
||||
Button::Primary => button::Appearance {
|
||||
background: Some(palette.primary.strong.into()),
|
||||
text_color: palette.primary.text,
|
||||
..style
|
||||
..appearance
|
||||
},
|
||||
Button::Secondary => button::Style {
|
||||
Button::Secondary => button::Appearance {
|
||||
background: Some(palette.background.weak.into()),
|
||||
text_color: palette.background.text,
|
||||
..style
|
||||
..appearance
|
||||
},
|
||||
Button::Positive => button::Style {
|
||||
Button::Positive => button::Appearance {
|
||||
background: Some(palette.success.base.into()),
|
||||
text_color: palette.success.text,
|
||||
..style
|
||||
..appearance
|
||||
},
|
||||
Button::Destructive => button::Style {
|
||||
Button::Destructive => button::Appearance {
|
||||
background: Some(palette.danger.base.into()),
|
||||
text_color: palette.danger.text,
|
||||
..style
|
||||
..appearance
|
||||
},
|
||||
Button::Text => button::Style {
|
||||
Button::Text => button::Appearance {
|
||||
text_color: palette.background.text,
|
||||
..style
|
||||
..appearance
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn hovered(&self, variant: Self::Variant) -> button::Style {
|
||||
let active = self.active(variant);
|
||||
fn hovered(&self, style: Self::Style) -> button::Appearance {
|
||||
let active = self.active(style);
|
||||
let palette = self.extended_palette();
|
||||
|
||||
let background = match variant {
|
||||
let background = match style {
|
||||
Button::Primary => Some(palette.primary.base),
|
||||
Button::Secondary => Some(palette.background.strong),
|
||||
Button::Positive => Some(palette.success.strong),
|
||||
|
|
@ -116,7 +116,7 @@ impl button::StyleSheet for Theme {
|
|||
Button::Text => None,
|
||||
};
|
||||
|
||||
button::Style {
|
||||
button::Appearance {
|
||||
background: background.map(Background::from),
|
||||
..active
|
||||
}
|
||||
|
|
@ -124,9 +124,9 @@ impl button::StyleSheet for Theme {
|
|||
}
|
||||
|
||||
impl slider::StyleSheet for Theme {
|
||||
type Variant = ();
|
||||
type Style = ();
|
||||
|
||||
fn active(&self, _variant: Self::Variant) -> slider::Style {
|
||||
fn active(&self, _style: Self::Style) -> slider::Appearance {
|
||||
let palette = self.extended_palette();
|
||||
|
||||
let handle = slider::Handle {
|
||||
|
|
@ -139,7 +139,7 @@ impl slider::StyleSheet for Theme {
|
|||
border_width: 1.0,
|
||||
};
|
||||
|
||||
slider::Style {
|
||||
slider::Appearance {
|
||||
rail_colors: (palette.primary.base, palette.background.base),
|
||||
handle: slider::Handle {
|
||||
color: palette.background.base,
|
||||
|
|
@ -149,11 +149,11 @@ impl slider::StyleSheet for Theme {
|
|||
}
|
||||
}
|
||||
|
||||
fn hovered(&self, variant: Self::Variant) -> slider::Style {
|
||||
let active = self.active(variant);
|
||||
fn hovered(&self, style: Self::Style) -> slider::Appearance {
|
||||
let active = self.active(style);
|
||||
let palette = self.extended_palette();
|
||||
|
||||
slider::Style {
|
||||
slider::Appearance {
|
||||
handle: slider::Handle {
|
||||
color: palette.primary.weak,
|
||||
..active.handle
|
||||
|
|
@ -162,11 +162,11 @@ impl slider::StyleSheet for Theme {
|
|||
}
|
||||
}
|
||||
|
||||
fn dragging(&self, variant: Self::Variant) -> slider::Style {
|
||||
let active = self.active(variant);
|
||||
fn dragging(&self, style: Self::Style) -> slider::Appearance {
|
||||
let active = self.active(style);
|
||||
let palette = self.extended_palette();
|
||||
|
||||
slider::Style {
|
||||
slider::Appearance {
|
||||
handle: slider::Handle {
|
||||
color: palette.primary.base,
|
||||
..active.handle
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue