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.

50 lines
1.3 KiB

  1. package nova.monadic_sfx
  2. import javafx.event.ActionEvent
  3. import monix.execution.Ack
  4. import monix.execution.Cancelable
  5. import monix.reactive.Observable
  6. import monix.reactive.OverflowStrategy
  7. import scalafx.scene.control._
  8. package object implicits {
  9. implicit class MyButtonExt(val button: Button) extends AnyVal {
  10. def observableAction(): Observable[ActionEvent] = {
  11. import monix.execution.cancelables.SingleAssignCancelable
  12. Observable.create(OverflowStrategy.Unbounded) { sub =>
  13. val c = SingleAssignCancelable()
  14. val l = new javafx.event.EventHandler[ActionEvent] {
  15. override def handle(event: ActionEvent): Unit = {
  16. if (sub.onNext(event) == Ack.Stop) c.cancel()
  17. }
  18. }
  19. button.onAction = l
  20. c := Cancelable(() =>
  21. button.removeEventHandler(
  22. ActionEvent.ACTION,
  23. l
  24. )
  25. )
  26. c
  27. }
  28. }
  29. }
  30. // implicit class NodeExt(val node: Node) {
  31. // def lookup2[T <: SFXDelegate[_]](
  32. // selector: String
  33. // )(implicit c: ClassTag[T]) = {
  34. // val t = c.runtimeClass
  35. // Option(node.delegate.lookup(selector)) match {
  36. // case Some(value) =>
  37. // if (value.getClass == t) Some(value) else None
  38. // case None => None
  39. // }
  40. // }
  41. // val x = node.lookup2("")
  42. // }
  43. }