L'API Ink è modulare, quindi puoi utilizzare solo ciò che ti serve.
Bracciate
The strokes module serves as the foundation of the Ink API. Key data types within this module are:
StrokeInputBatch: Represents a series of pointer inputs, including their position, timestamp, and optionally pressure, tilt, and orientation.InProgressStroke: Represents a stroke that is actively being drawn.InProgressStrokeis used to render partial strokes with low latency and to build the finalStrokeonce input is complete, after which the object can be reused.InProgressStrokeis used by theInProgressStrokescomposable.Stroke: An immutable representation of a finalized stroke with fixed geometry. EachStrokehas anImmutableStrokeInputBatch(input points), aBrush(style), and aPartitionedMesh(geometric shape). You can store, manipulate, and render strokes within your application.
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, 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.
Authoring
Il modulo Compose Authoring ti consente di acquisire l'input tocco dell'utente e di eseguirne il rendering
come tratti a bassa latenza sullo schermo in tempo reale. Ciò si ottiene tramite
il componente componibile InProgressStrokes, che elabora gli eventi di movimento e mostra
i tratti man mano che vengono disegnati.
Una volta completato un tratto, il componente composable invia una notifica all'applicazione client utilizzando
un callback InProgressStrokesFinishedListener. Ciò consente all'applicazione
di recuperare i tratti completati per il rendering o l'archiviazione.
In Compose, InProgressStrokes accetta questo callback nel parametro onStrokesFinished. Passa i tratti finiti a un altro componibile per visualizzarli sullo schermo utilizzando il modulo di rendering.
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
Il modulo storage fornisce utilità per
serializzare e deserializzare in modo efficiente i dati dei tratti, concentrandosi principalmente
su StrokeInputBatch.
Il modulo utilizza protocol buffers e tecniche di compressione delta ottimizzate, con un conseguente risparmio significativo dello spazio di archiviazione rispetto ai metodi semplici.
Il modulo di archiviazione semplifica il salvataggio, il caricamento e la condivisione dei tratti.