La API de Ink está modularizada, por lo que puedes usar solo lo que necesitas.
Brazadas
El módulo trazos sirve como base de la API de Ink. Los tipos de datos clave de este módulo son los siguientes:
StrokeInputBatch: Representa una serie de entradas de puntero, incluidas su posición, marca de tiempo y, de manera opcional, presión, inclinación y orientación.InProgressStroke: Representa un trazo que se está dibujando de forma activa.InProgressStrokese usa para renderizar trazos parciales con baja latencia y para compilar el objetoStrokefinal una vez que se completa la entrada, después de lo cual se puede reutilizar el objeto. El elementoInProgressStrokese usa en el elementoInProgressStrokescomponible.Stroke: Es una representación inmutable de un trazo finalizado con geometría fija. CadaStroketiene unImmutableStrokeInputBatch(puntos de entrada), unBrush(estilo) y unaPartitionedMesh(forma geométrica). Puedes almacenar, manipular y renderizar trazos dentro de tu aplicación.
Geometría
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.
Pincel
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.
Autoría
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.
Renderización
El módulo Rendering simplifica el dibujo de trazos de tinta en un Canvas de Android.
Proporciona CanvasStrokeRenderer para Compose y ViewStrokeRenderer para diseños basados en vistas. Estos renderizadores optimizan el rendimiento de la renderización y ayudan a ofrecer elementos visuales de alta calidad, incluido el suavizado.
Para renderizar trazos, llama al método create() para obtener una instancia de CanvasStrokeRenderer y, luego, llama al método draw() para renderizar trazos terminados (Stroke) o en curso (InProgressStroke) en un Canvas.
Puedes transformar el lienzo cuando dibujas un trazo. Algunos ejemplos incluyen el desplazamiento horizontal, el zoom y la rotación. Para renderizar el trazo correctamente, también debes pasar la transformación canvas a CanvasStrokeRenderer.draw.
Para evitar hacer un seguimiento de la transformación canvas por separado, usa ViewStrokeRenderer.
Almacenamiento
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.