Skip to content

Commit

Permalink
Merge pull request #602 from baaahs/concrete-view
Browse files Browse the repository at this point in the history
Make View, Icon, and DialogHolder non-MP common interfaces
  • Loading branch information
xian authored Jul 26, 2024
2 parents 7d5fe89 + 624bfab commit 70e0f21
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 64 deletions.
6 changes: 3 additions & 3 deletions src/commonMain/kotlin/baaahs/ui/View.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package baaahs.ui

expect interface View
interface View

expect interface Icon
interface Icon

expect interface DialogHolder {
interface DialogHolder {
fun showDialog(view: View)
fun showMenuDialog(title: String, options: List<DialogMenuItem>)
fun closeDialog()
Expand Down
6 changes: 4 additions & 2 deletions src/jsMain/kotlin/baaahs/app/ui/CommonIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ actual fun getCommonIcons() = object : PlatformIcons {
fun jsIcon(materialIcon: SvgIconComponent): Icon = JsIcon(materialIcon)

private class JsIcon(private val icon: SvgIconComponent) : Icon {
override fun getReactIcon(): SvgIconComponent = icon
}
fun getReactIcon(): SvgIconComponent = icon
}

fun Icon.getReactIcon(): SvgIconComponent = (this as JsIcon).getReactIcon()
10 changes: 3 additions & 7 deletions src/jsMain/kotlin/baaahs/app/ui/controls/ControlWrapperView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package baaahs.app.ui.controls
import baaahs.app.ui.appContext
import baaahs.show.live.ControlProps
import baaahs.show.live.OpenControl
import baaahs.ui.className
import baaahs.ui.unaryMinus
import baaahs.ui.unaryPlus
import baaahs.ui.xComponent
import baaahs.ui.*
import js.objects.jso
import materialui.icon
import mui.material.Card
Expand All @@ -30,9 +27,8 @@ private val ControlWrapper = xComponent<ControlWrapperProps>("Control") { props

Card {
attrs.classes = jso { root = props.className?.className ?: -Styles.controlBox }
with (props.control.getView(props.controlProps)) {
render()
}
props.control.getView(props.controlProps)
.render(this)

problemBadge(control)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import baaahs.Gadget
import baaahs.app.ui.CommonIcons
import baaahs.app.ui.appContext
import baaahs.app.ui.document.fileUpload
import baaahs.app.ui.getReactIcon
import baaahs.doc.FileType
import baaahs.encodeBase64
import baaahs.gadgets.ImagePicker
Expand Down
2 changes: 1 addition & 1 deletion src/jsMain/kotlin/baaahs/app/ui/dialog/DialogPanelsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private val DialogPanelsView = xComponent<DialogPanelsProps>("DialogPanels") { p
ErrorBoundary {
attrs.FallbackComponent = ErrorDisplay

with (panelView) { render() }
panelView.render(this)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private val DocumentMenuView = xComponent<DocumentMenuProps>("DocumentMenu") { p
documentManager.onNew(object : DialogHolder {
override fun showDialog(view: View) {
renderDialog = {
with(view) { render() }
view.render(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private val EditableManagerUi = xComponent<EditableManagerUiProps>("EditableMana
val classes = +styles.singlePanel and
if (dialogPanel.noMargin) styles.singlePanelNoMargin else null
div(classes) {
with (dialogPanel.getView()) { render() }
dialogPanel.getView().render(this)
}
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/jsMain/kotlin/baaahs/app/ui/editor/EditorPanels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import baaahs.model.ModelUnit
import baaahs.scene.MutableScene
import baaahs.show.mutable.*
import baaahs.ui.View
import baaahs.ui.render
import baaahs.ui.renderWrapper
import baaahs.ui.unaryPlus
import mui.material.Divider
Expand All @@ -27,7 +28,7 @@ actual fun getEditorPanelViews(): EditorPanelViews = object : EditorPanelViews {
): View = renderWrapper {
val mutablePatch = mutablePatchHolder.patches[0]
val editorPanel = mutablePatch.getEditorPanel(editableManager)
with (editorPanel.getView()) { render() }
editorPanel.getView().render(this)
}

override fun forGenericPropertiesPanel(
Expand All @@ -41,9 +42,8 @@ actual fun getEditorPanelViews(): EditorPanelViews = object : EditorPanelViews {
}
}

with(editorPanelComponent.getView(editableManager)) {
render()
}
editorPanelComponent.getView(editableManager)
.render(this)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/jsMain/kotlin/baaahs/app/ui/layout/GridItemView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import baaahs.show.live.ControlProps
import baaahs.show.live.OpenControl
import baaahs.show.mutable.MutableShow
import baaahs.ui.and
import baaahs.ui.render
import baaahs.ui.unaryPlus
import baaahs.ui.xComponent
import materialui.icon
Expand Down Expand Up @@ -44,9 +45,8 @@ private val GridItemView = xComponent<GridItemProps>("GridItem") { props ->
event.preventDefault()
}

with (control.getView(props.controlProps)) {
render()
}
control.getView(props.controlProps)
.render(this)

problemBadge(control)

Expand Down
2 changes: 1 addition & 1 deletion src/jsMain/kotlin/baaahs/app/ui/model/ModelEditorView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private val ModelEditorView = xComponent<ModelEditorProps>("ModelEditor") { prop
attrs.margin = FormControlMargin.dense

editingEntity.getEditorPanelViews().forEach {
with(it) { render() }
it.render(this)
}

header { +"Actions" }
Expand Down
15 changes: 5 additions & 10 deletions src/jsMain/kotlin/baaahs/app/ui/patchmod/PatchModView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import baaahs.app.ui.controls.Styles
import baaahs.app.ui.shaderPreview
import baaahs.show.live.ControlProps
import baaahs.show.live.OpenPatchHolder
import baaahs.ui.asTextNode
import baaahs.ui.unaryMinus
import baaahs.ui.unaryPlus
import baaahs.ui.xComponent
import baaahs.ui.*
import js.objects.jso
import mui.material.*
import react.*
Expand Down Expand Up @@ -75,9 +72,8 @@ private val PatchModView = xComponent<PatchModProps>("PatchMod") { props ->
attrs.noSharedGlContext = true
}

selectedPatchMod?.let {
with(it.getView(selectedPatch)) { render() }
}
selectedPatchMod?.getView(selectedPatch)
?.render(this)
}

div(+styles.controls) {
Expand All @@ -87,9 +83,8 @@ private val PatchModView = xComponent<PatchModProps>("PatchMod") { props ->
if (incomingFeeds.intersect(control.controlledFeeds()).isNotEmpty()) {
Card {
attrs.classes = jso { root = -Styles.controlBox }
with(control.getView(ControlProps(null, null, null))) {
render()
}
control.getView(ControlProps(null, null, null))
.render(this)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import baaahs.scene.EditingController
import baaahs.scene.FixtureMappingData
import baaahs.scene.MutableFixtureMapping
import baaahs.scene.MutableScene
import baaahs.ui.render
import baaahs.ui.typographyH5
import baaahs.ui.unaryMinus
import baaahs.ui.xComponent
Expand Down Expand Up @@ -55,7 +56,7 @@ private val ControllerConfigEditorView = xComponent<ControllerConfigEditorProps>
}

editingController.getEditorPanelViews().forEach {
with(it) { render() }
it.render(this)
}

Card {
Expand Down
4 changes: 3 additions & 1 deletion src/jsMain/kotlin/baaahs/mapper/FixtureConfigPickerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import baaahs.device.FixtureType
import baaahs.scene.EditingController
import baaahs.scene.MutableFixtureOptions
import baaahs.ui.asTextNode
import baaahs.ui.render
import baaahs.ui.unaryMinus
import baaahs.ui.xComponent
import js.objects.jso
Expand Down Expand Up @@ -43,7 +44,8 @@ private val FixtureConfigPickerView = xComponent<FixtureConfigPickerProps>("Fixt
if (fixtureConfig != null) {
Card {
attrs.classes = jso { this.root = -styles.configCardInner }
with(fixtureConfig.getEditorView(props.editingController)) { render() }
fixtureConfig.getEditorView(props.editingController)
.render(this)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/jsMain/kotlin/baaahs/mapper/TransportConfigPickerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import baaahs.fixtures.TransportType
import baaahs.scene.EditingController
import baaahs.scene.MutableTransportConfig
import baaahs.ui.asTextNode
import baaahs.ui.render
import baaahs.ui.unaryMinus
import baaahs.ui.xComponent
import js.objects.jso
Expand Down Expand Up @@ -44,7 +45,8 @@ private val TransportConfigPickerView = xComponent<TransportConfigPickerProps>("
if (transportConfig != null) {
Card {
attrs.classes = jso { this.root = -styles.configCardInner }
with(transportConfig.getEditorView(props.editingController)) { render() }
transportConfig.getEditorView(props.editingController)
.render(this)
}
}
}
Expand Down
18 changes: 6 additions & 12 deletions src/jsMain/kotlin/baaahs/ui/DialogHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ package baaahs.ui

import react.RBuilder

actual interface DialogHolder {
actual fun showDialog(view: View)
actual fun showMenuDialog(title: String, options: List<DialogMenuItem>)
actual fun closeDialog()

fun showDialog(block: RBuilder.() -> Unit) {
showDialog(object : View {
override fun RBuilder.render() {
block()
}
})
}
fun DialogHolder.showDialog(block: RBuilder.() -> Unit) {
showDialog(object : JsView {
override fun RBuilder.render() {
block()
}
})
}
8 changes: 3 additions & 5 deletions src/jsMain/kotlin/baaahs/ui/View.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package baaahs.ui

import kotlinx.browser.window
import mui.icons.material.SvgIconComponent
import react.RBuilder

actual interface View {
interface JsView : View {
fun RBuilder.render()
}

actual interface Icon {
fun getReactIcon(): SvgIconComponent
fun View.render(rBuilder: RBuilder) = with (this as JsView) {
rBuilder.render()
}

actual fun confirm(message: String): Boolean =
Expand Down
2 changes: 1 addition & 1 deletion src/jsMain/kotlin/baaahs/ui/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fun LinearDimension.inPixels(): Int {
}

fun renderWrapper(block: RBuilder.() -> Unit): View {
return object : View {
return object : JsView {
override fun RBuilder.render() {
block()
}
Expand Down
1 change: 1 addition & 0 deletions src/jsMain/kotlin/materialui/types.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package materialui

import baaahs.app.ui.getReactIcon
import baaahs.ui.Icon
import mui.icons.material.SvgIconComponent
import mui.material.SvgIconProps
Expand Down
10 changes: 0 additions & 10 deletions src/jvmMain/kotlin/baaahs/ui/View.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
package baaahs.ui

actual interface View

actual interface Icon

actual interface DialogHolder {
actual fun showDialog(view: View)
actual fun showMenuDialog(title: String, options: List<DialogMenuItem>)
actual fun closeDialog()
}

actual fun confirm(message: String): Boolean = TODO("confirm not implemented")

0 comments on commit 70e0f21

Please sign in to comment.