linebender / piet

An abstraction for 2D graphics.
Apache License 2.0
1.24k stars 93 forks source link

Document clear() is not affected by clip() #508

Closed elbaro closed 2 years ago

elbaro commented 2 years ago
use piet::{kurbo::Rect, Color, RenderContext};

fn main() {
    let mut device = piet_common::Device::new().unwrap();
    let mut bitmap: piet_common::BitmapTarget = device.bitmap_target(400, 400, 1.0).unwrap();
    let mut rc = bitmap.render_context();
    rc.clip(Rect::new(100.0, 100.0, 200.0, 200.0));
    rc.clear(None, Color::AQUA);
    bitmap.save_to_file("test.png").unwrap();
}

RenderContext::clear() does not respect RenderContext::clip() and clears the entire target.

cmyr commented 2 years ago

This is not a bug; see the docs (including the note) for more explanation.

For an alternative that respects clipping, you can use fill, passing a rectangle the same size as your drawing context. :)