Parts about clearing and selection

This commit is contained in:
Igor Dunaev 2023-12-09 22:34:43 +03:00
parent 80e7bbbad8
commit 0e620b25e2
2 changed files with 24 additions and 7 deletions

View File

@ -1,13 +1,10 @@
import web.cssom.* import web.cssom.*
import emotion.react.Global import emotion.react.Global
import react.FC
import react.Props
import emotion.react.css import emotion.react.css
import emotion.react.styles import emotion.react.styles
import react.*
import react.dom.html.ReactHTML.div import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.input import react.dom.html.ReactHTML.input
import react.useEffect
import react.useState
import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.Context
import space.kscience.dataforge.names.parseAsName import space.kscience.dataforge.names.parseAsName
import space.kscience.visionforge.Colors import space.kscience.visionforge.Colors
@ -71,11 +68,17 @@ val EventDisplay = FC<Props> {
eventData?.let { eventData?.let {
containedVision.setChild(EVENTS_NAME, generateEvents(it)) containedVision.setChild(EVENTS_NAME, generateEvents(it))
} }
if (eventData == null) {
containedVision.setChild(EVENTS_NAME, null)
}
} }
useEffect(geometryData) { useEffect(geometryData) {
geometryData?.let { geometryData?.let {
containedVision.setChild(GEOMETRY_NAME, generateGeometry(it)) containedVision.setChild(GEOMETRY_NAME, generateGeometry(it))
} }
if (geometryData == null) {
containedVision.setChild(GEOMETRY_NAME, null)
}
} }
div { div {
@ -117,6 +120,20 @@ val EventDisplay = FC<Props> {
geometryData = 4f + 2f * Random.nextFloat() geometryData = 4f + 2f * Random.nextFloat()
} }
} }
input {
css {
margin = 5.px
padding = 5.px
backgroundColor = NamedColor.lightcoral
color = NamedColor.white
}
type = InputType.button
value = "Clear Scene"
onClick = {
geometryData = null
eventData = null
}
}
} }
div { div {
css { css {

View File

@ -6,7 +6,7 @@ fun generateEvents(radius: Float): SolidGroup {
val count = Random.nextInt(10, 20) val count = Random.nextInt(10, 20)
return SolidGroup { return SolidGroup {
repeat(count) { repeat(count) {
sphere(radius) { sphere(radius, it.toString()) {
x = 5.0 * (Random.nextFloat() - 0.5) x = 5.0 * (Random.nextFloat() - 0.5)
y = 2.0 * (Random.nextFloat() - 0.5) y = 2.0 * (Random.nextFloat() - 0.5)
z = 2.0 * (Random.nextFloat() - 0.5) z = 2.0 * (Random.nextFloat() - 0.5)
@ -18,13 +18,13 @@ fun generateEvents(radius: Float): SolidGroup {
fun generateGeometry(distance: Float): SolidGroup { fun generateGeometry(distance: Float): SolidGroup {
return SolidGroup { return SolidGroup {
box(10, 3, 3) { box(10, 3, 3, "Magnet1") {
x = 0.0 x = 0.0
y = -distance y = -distance
z = 0.0 z = 0.0
color(Colors.gray) color(Colors.gray)
} }
box(10, 3, 3) { box(10, 3, 3, "Magnet2") {
x = 0.0 x = 0.0
y = distance y = distance
z = 0.0 z = 0.0