Compare commits
No commits in common. "f238b038332fbc7ee226523fb528e132a78f6f12" and "e5882d01f8e512a59c45a77099a189814c32c16e" have entirely different histories.
f238b03833
...
e5882d01f8
@ -10,7 +10,7 @@ val dataforgeVersion by extra("0.8.0")
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "space.kscience"
|
group = "space.kscience"
|
||||||
version = "0.4.2-dev-1"
|
version = "0.4.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
@ -8,7 +8,6 @@ import org.w3c.dom.Element
|
|||||||
import space.kscience.dataforge.meta.Meta
|
import space.kscience.dataforge.meta.Meta
|
||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.visionforge.Vision
|
import space.kscience.visionforge.Vision
|
||||||
import kotlin.reflect.cast
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An [ElementVisionRenderer] that could be used directly in Compose-html as well as a stand-alone renderer
|
* An [ElementVisionRenderer] that could be used directly in Compose-html as well as a stand-alone renderer
|
||||||
@ -27,23 +26,3 @@ public interface ComposeHtmlVisionRenderer : ElementVisionRenderer {
|
|||||||
|
|
||||||
public companion object
|
public companion object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A compose-html renderer for a vision of given type
|
|
||||||
*/
|
|
||||||
public inline fun <reified T : Vision> ComposeHtmlVisionRenderer(
|
|
||||||
acceptRating: Int = ElementVisionRenderer.DEFAULT_RATING,
|
|
||||||
noinline renderFunction: @Composable DOMScope<Element>.(name: Name, vision: T, meta: Meta) -> Unit,
|
|
||||||
): ComposeHtmlVisionRenderer = object : ComposeHtmlVisionRenderer {
|
|
||||||
|
|
||||||
override fun rateVision(vision: Vision): Int =
|
|
||||||
if (vision::class == T::class) acceptRating else ElementVisionRenderer.ZERO_RATING
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
override fun DOMScope<Element>.render(name: Name, vision: Vision, meta: Meta) {
|
|
||||||
renderFunction(name, T::class.cast(vision), meta)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String = "ElementVisionRender(${T::class.simpleName})"
|
|
||||||
}
|
|
||||||
|
@ -9,6 +9,7 @@ import space.kscience.dataforge.meta.Meta
|
|||||||
import space.kscience.dataforge.misc.DfType
|
import space.kscience.dataforge.misc.DfType
|
||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.visionforge.Vision
|
import space.kscience.visionforge.Vision
|
||||||
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.cast
|
import kotlin.reflect.cast
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,15 +46,16 @@ public interface ElementVisionRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A browser renderer for a vision of given type
|
* A browser renderer for element of given type
|
||||||
*/
|
*/
|
||||||
public inline fun <reified T : Vision> ElementVisionRenderer(
|
public class SingleTypeVisionRenderer<T : Vision>(
|
||||||
acceptRating: Int = ElementVisionRenderer.DEFAULT_RATING,
|
public val kClass: KClass<T>,
|
||||||
noinline renderFunction: TagConsumer<HTMLElement>.(name: Name, vision: T, meta: Meta) -> Unit,
|
private val acceptRating: Int = ElementVisionRenderer.DEFAULT_RATING,
|
||||||
): ElementVisionRenderer = object : ElementVisionRenderer {
|
private val renderFunction: TagConsumer<HTMLElement>.(name: Name, vision: T, meta: Meta) -> Unit,
|
||||||
|
) : ElementVisionRenderer {
|
||||||
|
|
||||||
override fun rateVision(vision: Vision): Int =
|
override fun rateVision(vision: Vision): Int =
|
||||||
if (vision::class == T::class) acceptRating else ElementVisionRenderer.ZERO_RATING
|
if (vision::class == kClass) acceptRating else ElementVisionRenderer.ZERO_RATING
|
||||||
|
|
||||||
override fun render(
|
override fun render(
|
||||||
element: Element,
|
element: Element,
|
||||||
@ -63,9 +65,14 @@ public inline fun <reified T : Vision> ElementVisionRenderer(
|
|||||||
) {
|
) {
|
||||||
element.clear()
|
element.clear()
|
||||||
element.append {
|
element.append {
|
||||||
renderFunction(name, T::class.cast(vision), meta)
|
renderFunction(name, kClass.cast(vision), meta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String = "ElementVisionRender(${T::class.simpleName})"
|
override fun toString(): String = "ElementVisionRender(${kClass.simpleName})"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public inline fun <reified T : Vision> ElementVisionRenderer(
|
||||||
|
acceptRating: Int = ElementVisionRenderer.DEFAULT_RATING,
|
||||||
|
noinline renderFunction: TagConsumer<HTMLElement>.(name: Name, vision: T, meta: Meta) -> Unit,
|
||||||
|
): ElementVisionRenderer = SingleTypeVisionRenderer(T::class, acceptRating, renderFunction)
|
||||||
|
Loading…
Reference in New Issue
Block a user