Incular logoIncular
API ReferencePainting & Animation

Path

Immutable bezier paths with bounds, hit testing, and transforms.

Immutable Arc<BezPath> with cached bounds and a fresh PathId per build/transform.

BuilderSegment
move_to(p)Start a new contour
line_to(p)Straight segment
quadratic_to(c, p)Quadratic bezier
cubic_to(a, b, p)Cubic bezier
close()Close the contour
build()Freeze into an immutable Path

path.bez_path(), bounds(), id(), contains(point, rule), and transformed(t) (fresh id) round out the API — bounds and contains use the Kurbo winding rule.

use incular::prelude::*;
use std::sync::Arc;

fn main() {
    let mut b = Path::builder();
    b.move_to(Offset::new(0.0, 0.0));
    b.line_to(Offset::new(100.0, 40.0));
    b.close();
    let path = Arc::new(b.build());
    println!("bounded: {}", path.bounds().is_some());
    let app = Application::new(move |_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(CustomPaint::new(
                Size::new(200.0, 120.0),
                {
                    let mut canvas = Canvas::default();
                    canvas.fill_path(
                        path.clone(),
                        Brush::from(Color::WHITE),
                        FillRule::NonZero,
                    );
                    canvas.finish()
                },
            ))
            .build()
            .into()
    })
    .expect("valid application");
    incular::run(app).expect("run application");
}

path.bez_path(), path.bounds(), and path.id() read the frozen shape; path.contains(point, FillRule::NonZero) hit-tests with the Kurbo winding rule; path.transformed(transform) returns a copy with a fresh id.

FillRule: NonZero / EvenOdd (winding for contains and fills).

Decoration geometry

use incular::prelude::*;

fn main() {
    let border = RenderBorder::new(1.0, Color::BLACK);
    println!("border width: {}", border.width);
    let radii = CornerRadii::uniform(8.0);
    println!("radii: {:?}", radii);
    let rect = Rect::from_origin_size(
        Offset::new(0.0, 0.0),
        Size::new(100.0, 40.0),
    );
    let rrect = RRect::uniform(rect, 8.0);
    println!("contains: {}", rrect.contains(Offset::new(10.0, 10.0)));
}

Widget-level extras: BorderSide, BoxBorder, BoxShape::Rectangle (default) / Circle, BlurStyle, BoxShadow, TileMode, DecorationImage, full BoxDecoration with is_valid(), change_impact(), invalidation(). PathBuilder constructs paths (move_to / line_to / quadratic_to / cubic_to / close / build). BorderDirectional mirrors Border with start/end edges; BorderRadiusDirectional mirrors corner radii; BorderRadius is the four-corner radius set; BorderStyle: solid and decorative stroke styles.

Related: Paint, Canvas.

On this page