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

Clip the invalidation example. #929

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion druid/examples/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ impl Widget<Point> for CircleView {

fn paint(&mut self, ctx: &mut PaintCtx, data: &Point, _env: &Env) {
ctx.with_save(|ctx| {
let rect = ctx.size().to_rect();
let rect = ctx.region().to_rect();
// Clip to the rect that was invalidated. This is usually not
// necessary, but if there's lots of drawing involved then there's a
// chance that clipping can be faster. Also, drawing outside the
// invalid region has backend-dependent behavior: for example, it
// has no effect on GTK but it does have an effect on wasm.
ctx.clip(rect);
ctx.fill(rect, &Color::WHITE);
ctx.fill(Circle::new(*data, RADIUS), &Color::BLACK);
Expand Down