visionforge/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeViewWithControls.kt

80 lines
2.6 KiB
Kotlin
Raw Normal View History

2021-05-10 22:07:16 +03:00
package space.kscience.visionforge.ring
import kotlinx.css.*
2021-06-06 20:57:39 +03:00
import react.*
2021-05-10 22:07:16 +03:00
import ringui.grid.ringCol
import ringui.grid.ringGrid
import ringui.grid.ringRow
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.names.Name
import space.kscience.visionforge.react.ThreeCanvasComponent
import space.kscience.visionforge.solid.Solid
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
import styled.css
import styled.styledDiv
2021-06-08 18:45:03 +03:00
public external interface ThreeCanvasWithControlsProps : RProps {
2021-05-10 22:07:16 +03:00
public var context: Context
2021-06-08 18:45:03 +03:00
public var solid: Solid?
2021-05-10 22:07:16 +03:00
public var selected: Name?
}
@JsExport
2021-06-08 18:45:03 +03:00
public val ThreeCanvasWithControls: (props: ThreeCanvasWithControlsProps) -> dynamic =
2021-06-06 20:57:39 +03:00
functionalComponent("ThreeViewWithControls") { props ->
2021-05-10 22:07:16 +03:00
var selected by useState { props.selected }
val onSelect: (Name?) -> Unit = {
selected = it
}
2021-06-06 20:57:39 +03:00
val options = useMemo {
Canvas3DOptions.invoke {
this.onSelect = onSelect
}
}
2021-05-10 22:07:16 +03:00
styledDiv {
css {
height = 100.pct
2021-06-06 22:42:50 +03:00
maxHeight = 100.vh
maxWidth = 100.vw
2021-05-10 22:07:16 +03:00
}
ringGrid {
ringRow {
ringCol {
attrs {
xs = 12
sm = 12
md = 8
lg = 9
}
child(ThreeCanvasComponent) {
attrs {
this.context = props.context
2021-06-08 18:45:03 +03:00
this.solid = props.solid as? Solid
2021-05-10 22:07:16 +03:00
this.selected = selected
2021-06-06 20:57:39 +03:00
this.options = options
2021-05-10 22:07:16 +03:00
}
}
}
ringCol {
attrs {
xs = 12
sm = 12
md = 4
lg = 3
}
styledDiv {
css {
padding(top = 4.px)
//border(1.px, BorderStyle.solid, Color.lightGray)
height = 100.pct
overflowY = Overflow.auto
}
2021-06-08 18:45:03 +03:00
ringThreeControls(options, props.solid, selected, onSelect)
2021-05-10 22:07:16 +03:00
}
}
}
}
}
}