Skip to content

Commit

Permalink
widget::Container requests paint when Key has changed (#1881)
Browse files Browse the repository at this point in the history
Fixes #1880 

Co-authored-by: Colin Rofls <colin@cmyr.net>
  • Loading branch information
maan2003 and cmyr committed Jul 27, 2021
1 parent 85c71ca commit 8bd8805
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions druid/src/widget/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ impl<T: Data> Widget<T> for Container<T> {
skip(self, ctx, old_data, data, env)
)]
fn update(&mut self, ctx: &mut UpdateCtx, old_data: &T, data: &T, env: &Env) {
if let Some(BackgroundBrush::Painter(p)) = self.background.as_mut() {
if let Some(brush) = self.background.as_mut() {
trace_span!("update background").in_scope(|| {
p.update(ctx, old_data, data, env);
brush.update(ctx, old_data, data, env);
});
}
self.inner.update(ctx, data, env);
Expand Down
11 changes: 11 additions & 0 deletions druid/src/widget/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ impl<T> Painter<T> {
}

impl<T: Data> BackgroundBrush<T> {
/// Request paint if the BackgroundBrush changed.
pub fn update(&mut self, ctx: &mut UpdateCtx, old_data: &T, data: &T, env: &Env) {
match self {
Self::ColorKey(key) if ctx.env_key_changed(key) => {
ctx.request_paint();
}
Self::Painter(p) => p.update(ctx, old_data, data, env),
_ => (),
}
}

/// Draw this `BackgroundBrush` into a provided [`PaintCtx`].
///
/// [`PaintCtx`]: ../struct.PaintCtx.html
Expand Down

0 comments on commit 8bd8805

Please sign in to comment.