You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.8 KiB
71 lines
1.8 KiB
package nova.monadic_sfx.ui
|
|
|
|
import javafx.{scene => jfxc}
|
|
import monix.bio.Task
|
|
import monix.execution.Cancelable
|
|
import monix.execution.cancelables.CompositeCancelable
|
|
import monix.reactive.subjects.ConcurrentSubject
|
|
import nova.monadic_sfx.implicits._
|
|
import scalafx.beans.property.ObjectProperty
|
|
import scalafx.scene.Node
|
|
import scalafx.scene.Parent
|
|
import scalafx.scene.control.TextField
|
|
import scalafx.scene.text.Font
|
|
import cats.effect.Resource
|
|
|
|
final class FXComponent private (
|
|
val rootNode: Parent,
|
|
val cancelable: Cancelable
|
|
)
|
|
|
|
object FXComponent {
|
|
def acquire(f: CompositeCancelable => Task[Parent]) =
|
|
for {
|
|
c <- Task(CompositeCancelable())
|
|
p <- f(c)
|
|
} yield new FXComponent(p, c)
|
|
|
|
def fxComponent2Node(
|
|
component: FXComponent
|
|
)(implicit c: CompositeCancelable): Node = {
|
|
c += component.cancelable
|
|
component.rootNode
|
|
}
|
|
|
|
def resource(f: CompositeCancelable => Task[Parent]) =
|
|
Resource.make(acquire(f))(comp => Task(comp.cancelable.cancel()))
|
|
}
|
|
|
|
object TestFXComp {
|
|
val testComp =
|
|
FXComponent.resource { implicit c =>
|
|
Task.deferAction { implicit s =>
|
|
Task {
|
|
val sub = ConcurrentSubject.publish[jfxc.text.Font]
|
|
val f = ObjectProperty(Font("hmm"))
|
|
sub.onNext(f())
|
|
new TextField {
|
|
font <-- sub
|
|
font <== f
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// val x = for {
|
|
// comp <- testComp
|
|
// res <- FXComponent.make { implicit c =>
|
|
// Task.deferAction { implicit s =>
|
|
// Task {
|
|
// new BorderPane {
|
|
// val sub = ConcurrentSubject.publish[jfxc.text.Font]
|
|
// center = FXComponent.fxComponent2Node(comp)
|
|
// bottom = new TextField {
|
|
// font <-- sub
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// } yield res
|
|
}
|