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.

70 lines
1.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package nova.monadic_sfx.ui
  2. import javafx.{scene => jfxc}
  3. import monix.bio.Task
  4. import monix.execution.Cancelable
  5. import monix.execution.cancelables.CompositeCancelable
  6. import monix.reactive.subjects.ConcurrentSubject
  7. import nova.monadic_sfx.implicits._
  8. import scalafx.beans.property.ObjectProperty
  9. import scalafx.scene.Node
  10. import scalafx.scene.Parent
  11. import scalafx.scene.control.TextField
  12. import scalafx.scene.text.Font
  13. import cats.effect.Resource
  14. final class FXComponent private (
  15. val node: Parent,
  16. private val cancelable: Cancelable
  17. ) {
  18. // def toNode(implicit c: CompositeCancelable): Node = {
  19. // c += cancelable
  20. // rootNode
  21. // }
  22. }
  23. object FXComponent {
  24. private def acquire(f: CompositeCancelable => Task[Parent]) =
  25. for {
  26. c <- Task(CompositeCancelable())
  27. p <- f(c)
  28. } yield new FXComponent(p, c)
  29. def apply(f: CompositeCancelable => Task[Parent]) =
  30. Resource.make(acquire(f))(comp => Task(comp.cancelable.cancel()))
  31. }
  32. object TestFXComp {
  33. // val testComp =
  34. // FXComponent.resource { implicit c =>
  35. // Task.deferAction { implicit s =>
  36. // Task {
  37. // val sub = ConcurrentSubject.publish[jfxc.text.Font]
  38. // val f = ObjectProperty(Font("hmm"))
  39. // sub.onNext(f())
  40. // new TextField {
  41. // font <-- sub
  42. // font <== f
  43. // }
  44. // }
  45. // }
  46. // }
  47. // val x = for {
  48. // comp <- testComp
  49. // res <- FXComponent.make { implicit c =>
  50. // Task.deferAction { implicit s =>
  51. // Task {
  52. // new BorderPane {
  53. // val sub = ConcurrentSubject.publish[jfxc.text.Font]
  54. // center = FXComponent.fxComponent2Node(comp)
  55. // bottom = new TextField {
  56. // font <-- sub
  57. // }
  58. // }
  59. // }
  60. // }
  61. // }
  62. // } yield res
  63. }