Moduli

L'API Ink è modulare, quindi puoi utilizzare solo ciò che ti serve.

Bracciate

Il modulo tratti funge da base dell'API Ink. I tipi di dati chiave all'interno di questo modulo sono:

  • StrokeInputBatch: rappresenta una serie di input del puntatore, inclusi posizione, timestamp e, facoltativamente, pressione, inclinazione e orientamento.
  • InProgressStroke: Rappresenta un tratto in fase di disegno. InProgressStroke viene utilizzato per eseguire il rendering di tratti parziali con bassa latenza e per creare il Stroke finale una volta completato l'input, dopodiché l'oggetto può essere riutilizzato. InProgressStroke è utilizzato dal componibile InProgressStrokes.
  • Stroke: una rappresentazione immutabile di un tratto finalizzato con geometria fissa. Ogni Stroke ha un ImmutableStrokeInputBatch (punti di input), uno Brush (stile) e una PartitionedMesh (forma geometrica). Puoi archiviare, manipolare e visualizzare i tratti all'interno dell'applicazione.

Geometria

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.

Pennello

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, and BrushFamily. BrushFamily is analogous to a font family, it defines a stroke's style. For example, a BrushFamily can 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-use BrushFamily instances.

Authoring

The Compose Authoring module lets you capture user touch input and render it as low-latency strokes on the screen in real time. This is achieved through the InProgressStrokes composable, which processes motion events and displays the strokes as they are drawn.

Once a stroke is completed, the composable notifies the client application using an InProgressStrokesFinishedListener callback. This allows the application to retrieve the finished strokes for rendering or storage.

In Compose, InProgressStrokes takes this callback in the onStrokesFinished parameter. Pass the finished strokes to another composable to commit them to the screen using the rendering module.

Rendering

Il modulo Rendering semplifica il disegno di tratti di inchiostro su un Canvas Android. Fornisce CanvasStrokeRenderer per Compose e ViewStrokeRenderer per i layout basati sulle visualizzazioni. Questi renderer ottimizzano le prestazioni di rendering e contribuiscono a fornire immagini di alta qualità, incluso l'antialiasing.

Per eseguire il rendering dei tratti, chiama il metodo create() per ottenere un'istanza CanvasStrokeRenderer, quindi chiama il metodo draw() per eseguire il rendering dei tratti finiti (Stroke) o in corso (InProgressStroke) su un Canvas.

Puoi trasformare il canvas quando disegni un tratto. Alcuni esempi includono panoramica, zoom e rotazione. Per eseguire il rendering del tratto correttamente, devi anche passare la trasformazione canvas a CanvasStrokeRenderer.draw.

Per evitare di monitorare separatamente la trasformazione canvas, utilizza ViewStrokeRenderer.

Spazio di archiviazione

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.