JindongJindong
Core

JindongScope

DSL scope interface for defining haptic patterns

JindongScope

The scope interface that provides the DSL for defining haptic patterns.

Definition

@JindongScopeMarker
interface JindongScope

Description

JindongScope is the receiver for the Jindong content block. It serves two purposes:

  1. DSL Extension Point: All haptic DSL functions are defined as extensions on JindongScope
  2. Scope Control: The @JindongScopeMarker annotation prevents implicit nesting

Available Functions

Functions available within JindongScope:

FunctionDescription
HapticEmit a vibration event
DelayPause the pattern
SequenceGroup events sequentially
RepeatRepeat content N times
RepeatWithIndexRepeat with index access

Usage

The scope is automatically provided by Jindong:

Jindong(trigger) {
    // Inside JindongScope
    Haptic(100.ms)
    Delay(50.ms)
    Haptic(50.ms)
}

DSL Functions as Extensions

All haptic functions are extensions on JindongScope:

@Composable
fun JindongScope.Haptic(
    duration: Duration,
    intensity: HapticIntensity = HapticIntensity.MEDIUM
)

@Composable
fun JindongScope.Delay(duration: Duration)

@Composable
fun JindongScope.Repeat(
    count: Int,
    content: @Composable JindongScope.() -> Unit
)

Scope Marker

The @JindongScopeMarker annotation prevents confusing nested scopes:

@DslMarker
annotation class JindongScopeMarker

This means you cannot accidentally access outer scopes:

Jindong(trigger) {
    Repeat(3) {
        // Still in JindongScope - works fine
        Haptic(50.ms)
    }
}

Composable Support

The scope supports standard Compose patterns:

Conditionals

Jindong(trigger) {
    if (isSuccess) {
        Haptic(100.ms, HapticIntensity.MEDIUM)
    } else {
        Haptic(50.ms, HapticIntensity.HIGH)
    }
}

When Expressions

Jindong(trigger) {
    when (state) {
        State.SUCCESS -> Haptic(100.ms, HapticIntensity.LIGHT)
        State.ERROR -> Repeat(3) { Haptic(50.ms); Delay(50.ms) }
        State.WARNING -> Haptic(150.ms, HapticIntensity.MEDIUM)
    }
}

Loops

Jindong(trigger) {
    // Using RepeatWithIndex for index access
    RepeatWithIndex(5) { index ->
        val intensity = HapticIntensity.Custom(1.0f - index * 0.2f)
        Haptic(50.ms, intensity)
        Delay(30.ms)
    }
}

Internal Implementation

The default implementation is straightforward:

internal class JindongScopeImpl : JindongScope

The actual behavior comes from the DSL extension functions, not the scope interface itself.

See Also