calcit_paint 0.0.10

Native Skia canvas bindings for the Calcit language
docs.rs failed to build calcit_paint-0.0.10
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

(Toy)Calcit Paint

2D renderer for Calcit.

Usages

It runs Calcit and is driven by the canonical calcit.cirru Snapshot source.

./build.sh
calcit ./calcit.cirru

Available APIs:

calcit-paint.core/push-drawing-data! |reset-canvas! nil
calcit-paint.core/push-drawing-data! |render-canvas! shape-data

calcit-paint.core/launch-canvas! $ fn (event)
  println "|rendering to canvas..."

Native FFI / 原生 FFI

The C-safe buffer-v1 and blocking-callback descriptors, ownership rules, Cirru EDN transport, and adapters are provided by calcit_native_ffi. Paint keeps ownership of the Skia/winit event loop, rendering state, shape decoding, and callback scheduling. The module tracks calcit_native_ffi 0.1.2; buffer and blocking-callback protocols remain at v1. It requires Calcit 0.13.57.

C-safe buffer-v1/blocking-callback descriptor、ownership 规则、Cirru EDN transport 与 adapter 由 calcit_native_ffi 统一维护。 Paint 仍负责 Skia/winit 事件循环、绘制状态、shape 解析和回调调度; 模块当前使用 calcit_native_ffi 0.1.2,buffer 与 blocking-callback protocol 均继续保持 v1;模块要求 Calcit 0.13.57。

A custom mirror may be used for Skia binaries when it is known to be healthy:

export SKIA_BINARIES_URL=https://cdn.tiye.me/skia-binaries/{tag}/skia-binaries-{key}.tar.gz

If the mirror is unavailable, unset SKIA_BINARIES_URL to use rust-skia's official GitHub release assets. CI deliberately leaves this variable unset.

只在镜像站可用时设置 SKIA_BINARIES_URL;镜像异常时取消该变量, 回退到 rust-skia 的 GitHub Release 产物。CI 不设置该变量。

Shapes

Position represented with [] x y. Color with [] h s l a?

Drawing with lyon 0.17.5:

  • Rect, using rect or rectangle:
rect {
  position: Vec2,
  width: f32,
  height: f32,
  line_style: Option<(Color, f32)>,
  fill_style: Option<Color>,
},
  • Group, using group
Group {
  position: Vec2,
  children: Vec<Shape>,
},
  • Circle, using circle
Circle {
  position: Vec2,
  radius: f32,
  line_style: Option<(Color, f32)>,
  fill_style: Option<Color>,
},

Arc is not supported at current.

  • Text, using text
Text {
  text: String,
  position: Vec2,
  size: f32,
  // weight: String, // TODO
  color: Color,
  // align: TextAlign,
},
  • Paint operations, with ops
PaintOps {
  position: Vec2,
  path: Vec<PaintPathTo>,
  line_style: Option<(Color, f32)>,
  fill_style: Option<Color>,
},

It's rendered based on lyon SVG path builder. Only small subset:

[]
  [] :move-to ([] 1 2)
  [] :line-to ([] 3 4)
  [] :quadratic-bezier-to ([] 5 6) ([] 7 8)
  [] :cubic-bezier-to ([] 1 2) ([] 3 4) ([] 5 6)

Since then name is too long, I also use alies: bezier2-to -> quadratic-bezier-to, and bezier3-to -> cubic-bezier-to.

  • Polyline, using polyline
Polyline {
  position: Vec2,
  stops: Vec<Vec2>,
  skip_first: bool,
  color: Color,
  width: f32,
  join: LineJoin,
  cap: LineCap,
},
  • Image, using image, and Rect from Skia
Image {
  file_path: String,
  x: f32, y: f32, w: f32, h: f32,
  crop: Rect {
    x: f32, y: f32, w: f32, h: f32
  }
}
  • Touch Area, using touch-area

For handling events:

TouchArea {
  path: Calcit,
  action: Calcit,
  data: Calcit,
  position: Vec2,
  // children: Vec<Shape>, // TODO
  area: TouchAreaShape,
  line_style: Option<(Color, f32)>,
  fill_style: Option<Color>,
},
  • Key listener, using key-listener
KeyListener {
  key: String, // TODO modifier
  action: Calcit,
  path: Calcit,
  data: Calcit,
  // children: Vec<Shape>, // TODO
},
  • Rotate
Rotate {
  radius: f32,
}
  • Translate
Translate {
  x: f32,
  y: f32,
}
  • Scale
Scale {
  factor: f32,
}

License

MIT