Módulos

A API Ink é modularizada, então você pode usar apenas o que precisa.

Braçadas

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. InProgressStroke is used to render partial strokes with low latency and to build the final Stroke once input is complete, after which the object can be reused. InProgressStroke is used by the InProgressStrokes composable.
  • Stroke: An immutable representation of a finalized stroke with fixed geometry. Each Stroke has an ImmutableStrokeInputBatch (input points), a Brush (style), and a PartitionedMesh (geometric shape). You can store, manipulate, and render strokes within your application.

Geometria

O módulo Geometry oferece suporte a operações geométricas em formas primitivas (usando classes dedicadas como Box e Vec), além de formas arbitrárias (usando PartitionedMesh), incluindo detecção e transformação de interseção. O PartitionedMesh também pode conter dados extras para oferecer suporte à renderização.

Brush

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.

Criação

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.

Renderização

O módulo Rendering simplifica o desenho de traços de tinta em um Canvas do Android. Ele fornece CanvasStrokeRenderer para o Compose e ViewStrokeRenderer para layouts baseados em visualizações. Esses renderizadores otimizam o desempenho da renderização e ajudam a oferecer recursos visuais de alta qualidade, incluindo antialiasing.

Para renderizar traços, chame o método create() para receber uma instância de CanvasStrokeRenderer e, em seguida, chame o método draw() para renderizar traços concluídos (Stroke) ou em andamento (InProgressStroke) em um Canvas.

É possível transformar a tela ao desenhar um traço. Exemplos incluem panorâmica, zoom e rotação. Para renderizar o traço corretamente, também é necessário transmitir a transformação canvas para CanvasStrokeRenderer.draw.

Para evitar o rastreamento da transformação canvas separadamente, use ViewStrokeRenderer.

Armazenamento

O módulo storage fornece utilitários para serializar e desserializar dados de traços de maneira eficiente, principalmente com foco em StrokeInputBatch.

O módulo usa buffers de protocolo e técnicas otimizadas de compactação delta, resultando em uma economia significativa de armazenamento em comparação com métodos simples.

O módulo de armazenamento simplifica o salvamento, o carregamento e o compartilhamento de traços.