Skip to content

Commit

Permalink
Container::rounded takes KeyOrValue<f64> instead of f64 (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
binomial0 authored Jun 25, 2020
1 parent 94825d0 commit 6742a46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ You can find its changes [documented below](#060---2020-06-01).

- `Image` and `ImageData` exported by default. ([#1011] by [@covercash2])
- `Scale::from_scale` to `Scale::new`, and `Scale` methods `scale_x` / `scale_y` to `x` / `y`. ([#1042] by [@xStrom])
- `Container::rounded` takes `KeyOrValue<f64>` instead of `f64`. ([#1054] by [@binomial0])

### Deprecated

Expand Down Expand Up @@ -233,6 +234,7 @@ Last release without a changelog :(
[@jrmuizel]: https://github.com/jrmuizel
[@scholtzan]: https://github.com/scholtzan
[@covercash2]: https://github.com/covercash2
[@binomial0]: https://github.com/binomial0

[#599]: https://github.com/linebender/druid/pull/599
[#611]: https://github.com/linebender/druid/pull/611
Expand Down Expand Up @@ -337,10 +339,12 @@ Last release without a changelog :(
[#1042]: https://github.com/linebender/druid/pull/1042
[#1043]: https://github.com/linebender/druid/pull/1043
[#1050]: https://github.com/linebender/druid/pull/1050
[#1054]: https://github.com/linebender/druid/pull/1054

[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/linebender/druid/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/linebender/druid/compare/v0.3.2...v0.4.0
[0.3.2]: https://github.com/linebender/druid/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/linebender/druid/compare/v0.3.0...v0.3.1

14 changes: 8 additions & 6 deletions druid/src/widget/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct BorderStyle {
pub struct Container<T> {
background: Option<BackgroundBrush<T>>,
border: Option<BorderStyle>,
corner_radius: f64,
corner_radius: KeyOrValue<f64>,

inner: WidgetPod<T, Box<dyn Widget<T>>>,
}
Expand All @@ -41,7 +41,7 @@ impl<T: Data> Container<T> {
Self {
background: None,
border: None,
corner_radius: 0.0,
corner_radius: 0.0.into(),
inner: WidgetPod::new(inner).boxed(),
}
}
Expand Down Expand Up @@ -81,8 +81,8 @@ impl<T: Data> Container<T> {
}

/// Round off corners of this container by setting a corner radius
pub fn rounded(mut self, radius: f64) -> Self {
self.corner_radius = radius;
pub fn rounded(mut self, radius: impl Into<KeyOrValue<f64>>) -> Self {
self.corner_radius = radius.into();
self
}

Expand Down Expand Up @@ -138,8 +138,10 @@ impl<T: Data> Widget<T> for Container<T> {
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
let corner_radius = self.corner_radius.resolve(env);

if let Some(background) = self.background.as_mut() {
let panel = ctx.size().to_rounded_rect(self.corner_radius);
let panel = ctx.size().to_rounded_rect(corner_radius);

ctx.with_save(|ctx| {
ctx.clip(panel);
Expand All @@ -153,7 +155,7 @@ impl<T: Data> Widget<T> for Container<T> {
.size()
.to_rect()
.inset(border_width / -2.0)
.to_rounded_rect(self.corner_radius);
.to_rounded_rect(corner_radius);
ctx.stroke(border_rect, &border.color.resolve(env), border_width);
};

Expand Down

0 comments on commit 6742a46

Please sign in to comment.