Skip to content

Commit

Permalink
Merge pull request #2273 from iced-rs/missing-default-styles
Browse files Browse the repository at this point in the history
Default `disabled` style for `checkbox` and `hovered` style for `Svg`
  • Loading branch information
hecrj authored Feb 21, 2024
2 parents 7a4e86a + 94fd336 commit c0c5a01
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `extend` and `from_vec` methods for `Column` and `Row`. [#2264](https://github.com/iced-rs/iced/pull/2264)
- `PartialOrd`, `Ord`, and `Hash` implementations for `keyboard::Modifiers`. [#2270](https://github.com/iced-rs/iced/pull/2270)
- `clipboard` module in `advanced` module. [#2272](https://github.com/iced-rs/iced/pull/2272)
- Default `disabled` style for `checkbox` and `hovered` style for `Svg`. [#2273](https://github.com/iced-rs/iced/pull/2273)

### Fixed
- Black images when using OpenGL backend in `iced_wgpu`. [#2259](https://github.com/iced-rs/iced/pull/2259)
Expand Down
17 changes: 16 additions & 1 deletion style/src/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,20 @@ pub trait StyleSheet {
fn hovered(&self, style: &Self::Style, is_checked: bool) -> Appearance;

/// Produces the disabled [`Appearance`] of a checkbox.
fn disabled(&self, style: &Self::Style, is_checked: bool) -> Appearance;
fn disabled(&self, style: &Self::Style, is_checked: bool) -> Appearance {
let active = self.active(style, is_checked);

Appearance {
background: match active.background {
Background::Color(color) => Background::Color(Color {
a: color.a * 0.5,
..color
}),
Background::Gradient(gradient) => {
Background::Gradient(gradient.mul_alpha(0.5))
}
},
..active
}
}
}
4 changes: 3 additions & 1 deletion style/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ pub trait StyleSheet {
fn appearance(&self, style: &Self::Style) -> Appearance;

/// Produces the hovered [`Appearance`] of a svg content.
fn hovered(&self, style: &Self::Style) -> Appearance;
fn hovered(&self, style: &Self::Style) -> Appearance {
self.appearance(style)
}
}

0 comments on commit c0c5a01

Please sign in to comment.