Geometry API

Geometry API ช่วยให้คุณสร้างเครื่องมือแบบอินเทอร์แอกทีฟ เช่น ยางลบและกลไกการเลือก

หากต้องการดูตัวอย่างการใช้งานจริงของ Geometry API โปรดดูตัวอย่างการใช้งาน Eraser ต่อไปนี้

ยางลบทั้งจังหวะ

fun eraseWholeStrokes(
    eraserBox: ImmutableBox,
    finishedStrokesState: MutableState<Set<Stroke>>,
) {
    val threshold = 0.1f

    val strokesToErase = finishedStrokesState.value.filter { stroke ->
        stroke.shape.computeCoverageIsGreaterThan(
            box = eraserBox,
            coverageThreshold = threshold,
        )
    }
    if (strokesToErase.isNotEmpty()) {
        Snapshot.withMutableSnapshot {
            finishedStrokesState.value -= strokesToErase
        }
    }
}

สำหรับการใช้งานการเขียน อย่าลืมทริกเกอร์การจัดองค์ประกอบใหม่เพื่อให้ เส้นโครงร่างถูกนำออกได้อย่างมีประสิทธิภาพ ตัวอย่างเช่น วิธีการคือใช้ rememberCoroutineScope ใน Composable และส่งขอบเขต Coroutine ไปยัง Listener แบบสัมผัส ซึ่งช่วยให้คุณสามารถแก้ไข finishedStrokesState ภายในขอบเขตได้ ของ Compose