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

widget::Container requests paint when Key has changed #1881

Merged
merged 2 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
13 changes: 13 additions & 0 deletions druid/src/widget/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ 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();
}
}
maan2003 marked this conversation as resolved.
Show resolved Hide resolved
Self::Painter(p) => p.update(ctx, old_data, data, env),
_ => {}
maan2003 marked this conversation as resolved.
Show resolved Hide resolved
}
}

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