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

93 lines
3.1 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-06-09 11:48:03 +03:00
import ringui.grid.RowPosition
2021-05-10 22:07:16 +03:00
import ringui.grid.ringCol
import ringui.grid.ringGrid
import ringui.grid.ringRow
2021-06-09 11:48:03 +03:00
import ringui.tabs.ringTab
2021-05-10 22:07:16 +03:00
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?
2021-06-09 11:48:03 +03:00
public var additionalTabs: Map<String, RBuilder.() -> Unit>?
}
public fun ThreeCanvasWithControlsProps.tab(title: String, block: RBuilder.()->Unit){
additionalTabs = (additionalTabs?: emptyMap()) + (title to block)
2021-05-10 22:07:16 +03:00
}
@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-09 11:48:03 +03:00
width = 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 {
2021-06-09 11:48:03 +03:00
attrs {
start = RowPosition.sm
}
2021-05-10 22:07:16 +03:00
ringCol {
attrs {
xs = 12
sm = 12
md = 8
lg = 9
}
child(ThreeCanvasComponent) {
attrs {
this.context = props.context
2021-06-09 11:48:03 +03:00
this.solid = props.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)
2021-06-09 11:48:03 +03:00
width = 100.pct
2021-05-10 22:07:16 +03:00
//border(1.px, BorderStyle.solid, Color.lightGray)
}
2021-06-09 11:48:03 +03:00
ringThreeControls(options, props.solid, selected, onSelect) {
props.additionalTabs?.forEach { (title, builder) ->
ringTab(title, title, builder)
}
}
2021-05-10 22:07:16 +03:00
}
}
}
}
}
}