โมดูล

Ink API เป็นแบบแยกส่วน คุณจึงใช้ได้เฉพาะสิ่งที่ต้องการ

สโตรก

โมดูลเส้นเป็นรากฐานของ 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, 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.

การเขียน

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.

การแสดงภาพ

โมดูลการแสดงผลช่วยให้การวาดเส้นหมึกลงใน Android Canvas ง่ายขึ้น โดยมี CanvasStrokeRenderer สำหรับ Compose และ ViewStrokeRenderer สำหรับเลย์เอาต์ที่อิงตาม View โดย โปรแกรมแสดงผลเหล่านี้จะเพิ่มประสิทธิภาพการแสดงผลและช่วยแสดงภาพคุณภาพสูง รวมถึงการป้องกันรอยหยัก

หากต้องการแสดงผลลายเส้น ให้เรียกใช้เมธอด create() เพื่อรับอินสแตนซ์ CanvasStrokeRenderer จากนั้นเรียกใช้เมธอด draw() เพื่อ แสดงผลลายเส้นที่เสร็จแล้ว (Stroke) หรือลายเส้นที่กำลังดำเนินการ (InProgressStroke) บน Canvas

คุณสามารถเปลี่ยนรูปผืนผ้าใบได้เมื่อวาดเส้น ตัวอย่างเช่น การแพน การซูม และการหมุน หากต้องการแสดงผลเส้นขีดอย่างถูกต้อง คุณต้องส่งcanvas transform ไปยัง 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.