Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix progress bar rendering #949

Merged
merged 3 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i
- Keep hot state consistent with mouse position. ([#841] by [@xStrom])
- Open file menu item works again. ([#851] by [@kindlychung])
- Supply correct `LifeCycleCtx` to `Event::FocusChanged`. ([#878] by [@cmyr])
- Windows: Termiate app when all windows have closed. ([#763] by [@xStrom])
- Windows: Terminate app when all windows have closed. ([#763] by [@xStrom])
- macOS: `Application::quit` now quits the run loop instead of killing the process. ([#763] by [@xStrom])
- macOS/GTK/web: `MouseButton::X1` and `MouseButton::X2` clicks are now recognized. ([#843] by [@xStrom])
- GTK: Support disabled menu items. ([#897] by [@jneem])
Expand All @@ -105,6 +105,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i
- Improved `Split` accuracy. ([#738] by [@xStrom])
- Built-in widgets no longer stroke outside their `paint_rect`. ([#861] by [@jneem])
- `Switch` toggles with animation when its data changes externally. ([#898] by [@finnerale])
- Render progress bar correctly. ([#949] by [@scholtzan])

### Docs

Expand Down Expand Up @@ -200,6 +201,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i
[#953]: https://github.com/xi-editor/druid/pull/953
[#954]: https://github.com/xi-editor/druid/pull/954
[#959]: https://github.com/xi-editor/druid/pull/959
[#949]: https://github.com/xi-editor/druid/pull/949

## [0.5.0] - 2020-04-01

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

[Unreleased]: https://github.com/xi-editor/druid/compare/v0.5.0...master
[0.5.0]: https://github.com/xi-editor/druid/compare/v0.4.0...v0.5.0
Expand Down
15 changes: 9 additions & 6 deletions druid/src/widget/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl Widget<f64> for ProgressBar {
fn paint(&mut self, ctx: &mut PaintCtx, data: &f64, env: &Env) {
let clamped = data.max(0.0).min(1.0);
let stroke_width = 2.0;
let inset = -stroke_width / 2.0;

let rounded_rect = Rect::from_origin_size(
Point::ORIGIN,
Expand All @@ -69,13 +70,13 @@ impl Widget<f64> for ProgressBar {
})
.to_vec2(),
)
.inset(-stroke_width / 2.0)
.inset(inset)
.to_rounded_rect(4.0);

//Paint the border
// Paint the border
ctx.stroke(rounded_rect, &env.get(theme::BORDER_DARK), stroke_width);

//Paint the background
// Paint the background
let background_gradient = LinearGradient::new(
UnitPoint::TOP,
UnitPoint::BOTTOM,
Expand All @@ -86,18 +87,20 @@ impl Widget<f64> for ProgressBar {
);
ctx.fill(rounded_rect, &background_gradient);

//Paint the bar
// Paint the bar
let calculated_bar_width = clamped * rounded_rect.width();

let rounded_rect = Rect::from_origin_size(
Point::ORIGIN,
Point::new(-inset, 0.),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to translate the rect to respect the x inset.

(Size {
width: calculated_bar_width,
height: env.get(theme::BASIC_WIDGET_HEIGHT),
})
.to_vec2(),
)
.inset(-stroke_width / 2.0)
.inset((0.0, inset))
.to_rounded_rect(env.get(theme::PROGRESS_BAR_RADIUS));

let bar_gradient = LinearGradient::new(
UnitPoint::TOP,
UnitPoint::BOTTOM,
Expand Down