spxbhuhb / adaptive

Consolidated full-stack application development library for Kotlin
Apache License 2.0
0 stars 0 forks source link

Introduce the instruction concept #16

Closed toth-istvan-zoltan closed 1 month ago

toth-istvan-zoltan commented 1 month ago

Modifying the appearance of elements is done different ways on different platforms:

The instruction concept is an abstraction inspired by Tailwind and Compose modifiers.

fun main() {
    browser {
        hello(padding_10, border_1, border_color_black, /* the other parameters */)
    }
}

@Adaptive
fun hello(vararg instructions : AdaptiveInstruction, /* other parameters */) {
    /* whatever hello does */
}

The actual implementation of the instruction should be adapter dependent:

val padding_10 = AdaptiveInstruction("padding_10")
object CssInstructionFactory : Registry<AdaptiveInstruction> {
    init {
        + CssAdaptiveInstruction(padding_10, "padding: 10px"))
    }
}
AndroidAdaptiveInstruction({ it.setPadding(10) })

object AndroidInstructionFactory : Registry<AdaptiveInstruction> {
    init {
        + AndroidAdaptiveInstruction(padding_10) { it.setPadding(10) }
    }
}

Cons:

Pros:

toth-istvan-zoltan commented 1 month ago

Implemented the basic concept.