Ink API はモジュール化されているため、必要なものだけを使用できます。
ストローク
strokes モジュールは Ink API の基盤として機能します。このモジュールの主なデータ型は次のとおりです。
StrokeInputBatch: ポインタ入力の一連の動作を表します。位置、タイムスタンプ、必要に応じて圧力、傾き、向きを含みます。InProgressStroke: 現在描画中のストロークを表します。InProgressStrokeは、低レイテンシで部分的なストロークをレンダリングし、入力が完了したら最終的なStrokeを構築するために使用されます。その後、オブジェクトを再利用できます。InProgressStrokeは、InProgressStrokesコンポーザブルで使用されます。Stroke: ジオメトリが固定された確定済みのストロークの不変表現。各Strokeには、ImmutableStrokeInputBatch(入力ポイント)、Brush(スタイル)、PartitionedMesh(幾何学模様)があります。アプリケーション内でストロークを保存、操作、レンダリングできます。
ジオメトリ
The Geometry module supports geometric operations on primitive shapes (using dedicated classes like Box and Vec), as well as arbitrary shapes (using PartitionedMesh), including intersection detection and transformation. PartitionedMesh can also hold additional data to support rendering.
ブラシ
The brush module defines the style of strokes. It
consists of two main parts:
Brush: Specifies the style of a stroke including base color, base size, andBrushFamily.BrushFamilyis analogous to a font family, it defines a stroke's style. For example, aBrushFamilycan represent a specific style of marker or highlighter, allowing strokes with different sizes and colors to share that style.StockBrushes: Provides factory functions for creating ready-to-useBrushFamilyinstances.
オーサリング
Compose のオーサリング モジュールを使用すると、ユーザーのタッチ入力をキャプチャして、画面上に低レイテンシのストロークとしてリアルタイムでレンダリングできます。これは、モーション イベントを処理し、ストロークが描画されると同時に表示するコンポーザブル InProgressStrokes によって実現されます。
ストロークが完了すると、コンポーザブルは InProgressStrokesFinishedListener コールバックを使用してクライアント アプリケーションに通知します。これにより、アプリケーションはレンダリングまたは保存のために完了したストロークを取得できます。
Compose では、InProgressStrokes は onStrokesFinished パラメータでこのコールバックを受け取ります。完成したストロークを別のコンポーザブルに渡し、レンダリング モジュールを使用して画面にコミットします。
レンダリング
レンダリング モジュールを使用すると、Android の Canvas にインク ストロークを簡単に描画できます。Compose 用の CanvasStrokeRenderer と、ビューベースのレイアウト用の ViewStrokeRenderer が用意されています。これらのレンダラは、レンダリング パフォーマンスを最適化し、アンチエイリアシングなどの高品質のビジュアルを提供します。
ストロークをレンダリングするには、create() メソッドを呼び出して CanvasStrokeRenderer インスタンスを取得し、draw() メソッドを呼び出して、完了した(Stroke)ストロークまたは進行中の(InProgressStroke)ストロークを Canvas にレンダリングします。
ストロークを描画するときに、キャンバスを変換できます。たとえば、パン、ズーム、回転などがあります。ストロークを正しくレンダリングするには、canvas 変換を CanvasStrokeRenderer.draw に渡す必要もあります。
canvas 変換を個別にトラッキングしないようにするには、代わりに ViewStrokeRenderer を使用します。
ストレージ
The storage module provides utilities for
efficiently serializing and deserializing stroke data, primarily focusing
on StrokeInputBatch.
The module uses protocol buffers and optimized delta compression techniques, resulting in significant storage savings compared to naive methods.
The storage module simplifies saving, loading, and sharing strokes.