Canvas
Every Canvas recording command, clipping, transforms, and DisplayList.
Immediate recorder producing a DisplayList. restore panics if unbalanced;
finish asserts an empty save stack.
| Group | Commands |
|---|---|
| Shapes | rect, rrect, border |
| Paths | fill_path, stroke_path, draw_path |
| Images | image, image_with_sampling |
| Text | glyph_run |
| Clips | save_clip, save_clip_rrect, save_clip_oval, save_clip_path |
| Transforms | save_transform |
| Stack | restore, finish |
Drawing
A custom painter drawing a rect — copy, paste, and run:
use incular::prelude::*;
struct Dot;
impl CustomPainter for Dot {
fn paint(&self, size: Size) -> DisplayList {
let mut canvas = Canvas::default();
canvas.rect(
Rect::from_origin_size(Offset::ZERO, size),
Color::rgba(60, 110, 220, 255),
);
canvas.finish()
}
fn should_repaint(&self, _old: &Self) -> bool {
false
}
}
fn main() {
let app = Application::new(|_cx| {
Container::builder()
.padding(EdgeInsets::all(24.0))
.alignment(Alignment::CENTER)
.child(CustomPaint::from_painter(Size::new(200.0, 120.0), Dot))
.build()
.into()
})
.expect("valid application");
incular::run(app).expect("run application");
}FillRule: NonZero / EvenOdd. ImageSampling: Linear (default) /
Nearest.
Save and restore
save_transform, save_clip, save_clip_rrect, save_clip_oval,
save_clip_path push state that restore() pops — the painter above could
wrap its rect in a save/restore pair without changing the result.
DisplayList and CustomPaint
DisplayList::new() with push / extend_from / translated /
commands / len / is_empty; CustomPaint::new(size, display_list) for
prebuilt lists versus from_painter used above. ColoredBox::new(color, child) and RepaintBoundary::new(child) cover the one-liner cases.