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.

95 lines
2.3 KiB

  1. package nova.monadic_sfx.ui.controller
  2. import animatefx.animation.AnimationFX
  3. import animatefx.animation.Bounce
  4. import animatefx.animation.FadeIn
  5. import animatefx.util.{SequentialAnimationFX => SeqFX}
  6. import cats.effect.Sync
  7. import monix.eval.Task
  8. import nova.monadic_sfx.implicits.FontIcon
  9. import nova.monadic_sfx.implicits.IconLiteral
  10. import nova.monadic_sfx.implicits.JFXButton
  11. import nova.monadic_sfx.implicits.JFXListView
  12. import nova.monadic_sfx.implicits.JFXTextArea
  13. import nova.monadic_sfx.implicits.JFXTextField
  14. import nova.monadic_sfx.ui.components.todo.TodoListComponentOld
  15. import scalafx.collections.ObservableBuffer
  16. import scalafx.scene.control.Label
  17. import scalafx.scene.layout.HBox
  18. import scalafx.scene.paint.Color
  19. class TodoController(todoListComponent: TodoListComponentOld) {
  20. import AnimFX._
  21. def root =
  22. new HBox {
  23. children = Seq(
  24. new Label {
  25. text = "Todo"
  26. },
  27. new JFXButton {
  28. text = " Click me"
  29. onAction = _ => {
  30. new FadeIn(new Label("hello")).play()
  31. val anim = new SeqFX(
  32. new Bounce(new Label("hello")),
  33. new FadeIn(new Label("hello"))
  34. ).toAnimFX[Task]
  35. for {
  36. _ <- Task.unit
  37. _ <- anim.playL
  38. } yield ()
  39. }
  40. },
  41. new JFXTextField {
  42. text = "hello"
  43. labelFloat = true
  44. },
  45. new JFXListView[String] {
  46. items = ObservableBuffer("hello")
  47. },
  48. new JFXTextArea {
  49. prefWidth = 400
  50. text = "blah"
  51. labelFloat = true
  52. },
  53. new FontIcon {
  54. iconSize = 50
  55. iconColor = Color.Black
  56. iconLiteral = IconLiteral.Gmi10k
  57. }
  58. )
  59. }
  60. // def test() = {
  61. // new TextField("hello").lookup()
  62. // }
  63. // def test2() = {
  64. // new Label().lookup()
  65. // }
  66. }
  67. abstract class AnimFX[F[_]: Sync] {
  68. def playL: F[Unit]
  69. }
  70. object AnimFX {
  71. implicit class AnimationFXExt(anim: AnimationFX) {
  72. def toAnimFX[F[_]](implicit
  73. F: Sync[F]
  74. ) =
  75. new AnimFX[F] {
  76. override def playL: F[Unit] =
  77. F.delay(anim.play())
  78. }
  79. }
  80. implicit class SeqAnimationFXExt(anim: SeqFX) {
  81. def toAnimFX[F[_]](implicit
  82. F: Sync[F]
  83. ) =
  84. new AnimFX[F] {
  85. override def playL: F[Unit] =
  86. F.delay(anim.play())
  87. }
  88. }
  89. }